From 994e08bebc76617241f3fd13dcb621983e666d18 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 12 Jul 2020 21:02:51 +0200 Subject: [PATCH] Add function to get monitor name --- AdaptiveBrightness/monitor.hpp | 4 ++++ AdaptiveBrightness/monitor_win.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/AdaptiveBrightness/monitor.hpp b/AdaptiveBrightness/monitor.hpp index 34112cc..f3faebb 100644 --- a/AdaptiveBrightness/monitor.hpp +++ b/AdaptiveBrightness/monitor.hpp @@ -10,6 +10,8 @@ #include #include + #include + namespace detail { extern BOOL enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM); @@ -26,6 +28,8 @@ class Monitor { bool setBrightness(float percentage); float getBrightness(); + QString getName() const; + operator bool() const; private: diff --git a/AdaptiveBrightness/monitor_win.cpp b/AdaptiveBrightness/monitor_win.cpp index 2fee52c..fd1e6c8 100644 --- a/AdaptiveBrightness/monitor_win.cpp +++ b/AdaptiveBrightness/monitor_win.cpp @@ -113,6 +113,14 @@ float Monitor::getBrightness() return std::clamp(utils::map(brightness, minBrightness, maxBrightness, 0.f, 1.f), 0.f, 1.f); } +QString Monitor::getName() const +{ + return QString("%1 (0x%2:0x%3)") + .arg(m_physicalMonitor.name) + .arg(reinterpret_cast(m_hMonitor), 0, 16) + .arg(reinterpret_cast(m_physicalMonitor.handle), 0, 16); +} + Monitor::operator bool() const { return !m_errorOccurred;