Implement getting monitor brightness
This commit is contained in:
parent
b9170388b6
commit
058ba0846b
@ -38,6 +38,12 @@ class Monitor {
|
|||||||
|
|
||||||
bool hasBrightnessCapability() const;
|
bool hasBrightnessCapability() const;
|
||||||
|
|
||||||
|
template<typename InType, typename OutType>
|
||||||
|
auto map(InType value, InType inMin, InType inMax, OutType outMin, OutType outMax)
|
||||||
|
{
|
||||||
|
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
||||||
|
}
|
||||||
|
|
||||||
const HMONITOR m_hMonitor;
|
const HMONITOR m_hMonitor;
|
||||||
const PhysicalMonitor m_physicalMonitor;
|
const PhysicalMonitor m_physicalMonitor;
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
@ -37,7 +39,25 @@ bool Monitor::setBrightness(float percentage)
|
|||||||
|
|
||||||
float Monitor::getBrightness()
|
float Monitor::getBrightness()
|
||||||
{
|
{
|
||||||
return NAN;
|
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)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16));
|
||||||
|
|
||||||
|
DWORD minBrightness = 0;
|
||||||
|
DWORD brightness = 0;
|
||||||
|
DWORD maxBrightness = 0;
|
||||||
|
|
||||||
|
if(!GetMonitorBrightness(m_physicalMonitor.handle, &minBrightness, &brightness, &maxBrightness)) {
|
||||||
|
qCritical(ltr("Failed to get brightness of monitor '%1' with handle '0x%2' and physical handle '0x%3', error: %4")
|
||||||
|
.arg(m_physicalMonitor.name)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_hMonitor), 0, 16)
|
||||||
|
.arg(reinterpret_cast<qulonglong>(m_physicalMonitor.handle), 0, 16)
|
||||||
|
.arg(getLastErrorString()));
|
||||||
|
return NAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::clamp(map(brightness, minBrightness, maxBrightness, 0.f, 1.f), 0.f, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Monitor::operator bool() const
|
Monitor::operator bool() const
|
||||||
|
Loading…
Reference in New Issue
Block a user