Implement monitor validity check
This commit is contained in:
parent
259c62b01b
commit
c4f56a964d
@ -40,6 +40,7 @@ class Monitor {
|
||||
const PhysicalMonitor m_physicalMonitor;
|
||||
|
||||
std::optional<std::pair<DWORD, DWORD>> m_brightnessRange;
|
||||
bool m_errorOccurred = false;
|
||||
|
||||
Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR physicalMonitor);
|
||||
|
||||
|
@ -34,6 +34,8 @@ Monitor::~Monitor()
|
||||
|
||||
bool Monitor::setBrightness(float percentage)
|
||||
{
|
||||
m_errorOccurred = true;
|
||||
|
||||
if(!m_brightnessRange) {
|
||||
qDebug(ltr("No brightness range known for monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
||||
.arg(m_physicalMonitor.name)
|
||||
@ -62,11 +64,15 @@ bool Monitor::setBrightness(float percentage)
|
||||
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16)
|
||||
.arg(newBrightness));
|
||||
|
||||
m_errorOccurred = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float Monitor::getBrightness()
|
||||
{
|
||||
m_errorOccurred = true;
|
||||
|
||||
qDebug(ltr("Getting brightness of monitor '%1' with handle '0x%2' and physical handle '0x%3'")
|
||||
.arg(m_physicalMonitor.name)
|
||||
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
||||
@ -82,17 +88,19 @@ float Monitor::getBrightness()
|
||||
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
||||
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16)
|
||||
.arg(getLastErrorString()));
|
||||
|
||||
return NAN;
|
||||
}
|
||||
|
||||
m_brightnessRange = std::pair{minBrightness, maxBrightness};
|
||||
m_errorOccurred = false;
|
||||
|
||||
return std::clamp(map(brightness, minBrightness, maxBrightness, 0.f, 1.f), 0.f, 1.f);
|
||||
}
|
||||
|
||||
Monitor::operator bool() const
|
||||
{
|
||||
return false;
|
||||
return !m_errorOccurred;
|
||||
}
|
||||
|
||||
bool Monitor::hasBrightnessCapability() const
|
||||
|
Loading…
Reference in New Issue
Block a user