diff --git a/AdaptiveBrightness/monitor.hpp b/AdaptiveBrightness/monitor.hpp index 2ef8938..f887557 100644 --- a/AdaptiveBrightness/monitor.hpp +++ b/AdaptiveBrightness/monitor.hpp @@ -40,6 +40,7 @@ class Monitor { const PhysicalMonitor m_physicalMonitor; std::optional> m_brightnessRange; + bool m_errorOccurred = false; Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR physicalMonitor); diff --git a/AdaptiveBrightness/monitor_win.cpp b/AdaptiveBrightness/monitor_win.cpp index d0e469d..57400b4 100644 --- a/AdaptiveBrightness/monitor_win.cpp +++ b/AdaptiveBrightness/monitor_win.cpp @@ -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(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(m_hMonitor), 0, 16) @@ -82,17 +88,19 @@ float Monitor::getBrightness() .arg(reinterpret_cast(m_hMonitor), 0, 16) .arg(reinterpret_cast(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