Implement checking brightness support

This commit is contained in:
BlackMark 2020-07-05 19:02:06 +02:00
parent 07c189d399
commit 978420e4a0
3 changed files with 26 additions and 5 deletions

View File

@ -31,6 +31,8 @@ class Monitor {
Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR physicalMonitor);
bool hasBrightnessCapability() const;
const HMONITOR m_hMonitor;
const PhysicalMonitor m_physicalMonitor;
};

View File

@ -71,7 +71,11 @@ static BOOL enumMonitorsCallback(HMONITOR hMonitor, [[maybe_unused]] HDC hDC, [[
}
for(const auto& physicalMonitor: physicalMonitors) {
monitors.push_back(Monitor(hMonitor, physicalMonitor));
const auto monitor = Monitor(hMonitor, physicalMonitor);
if(monitor.hasBrightnessCapability()) {
monitors.push_back(monitor);
}
}
return true;

View File

@ -5,16 +5,18 @@
#include <QtDebug>
#include <QtGlobal>
#include <highlevelmonitorconfigurationapi.h>
#include "log_tr.hpp"
Monitor::Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR physicalMonitor)
: m_hMonitor(hMonitor)
, m_physicalMonitor(physicalMonitor.hPhysicalMonitor, physicalMonitor.szPhysicalMonitorDescription)
{
qInfo(ltr("Creating monitor '%1' with handle '0x%2' and physical handle '0x%3'")
.arg(m_physicalMonitor.name)
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
qDebug(ltr("Creating monitor '%1' with handle '0x%2' and physical handle '0x%3'")
.arg(m_physicalMonitor.name)
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
}
Monitor::~Monitor()
@ -25,4 +27,17 @@ Monitor::~Monitor()
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
}
bool Monitor::hasBrightnessCapability() const
{
DWORD monitorCapabilities = 0;
DWORD colorTemperatures = 0;
if(!GetMonitorCapabilities(m_physicalMonitor.handle, &monitorCapabilities, &colorTemperatures)) {
// TODO: Log error
return false;
}
return monitorCapabilities & MC_CAPS_BRIGHTNESS;
}
#endif