|
|
|
|
@@ -19,7 +19,7 @@
|
|
|
|
|
#include "sensor_driver.hpp"
|
|
|
|
|
#include "utils.hpp"
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|
|
|
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_mtx(QMutex::RecursionMode::Recursive)
|
|
|
|
|
{
|
|
|
|
|
qDebug(ltr("Creating main window"));
|
|
|
|
|
|
|
|
|
|
@@ -54,6 +54,8 @@ void MainWindow::closeEvent(QCloseEvent* event)
|
|
|
|
|
|
|
|
|
|
void MainWindow::enumSensors()
|
|
|
|
|
{
|
|
|
|
|
m_sensors.clear();
|
|
|
|
|
|
|
|
|
|
auto sensors = enumerateSensors();
|
|
|
|
|
|
|
|
|
|
for(auto& sensor: sensors) {
|
|
|
|
|
@@ -357,6 +359,12 @@ void MainWindow::updateState()
|
|
|
|
|
|
|
|
|
|
bool MainWindow::setMonitorBrightness(float& brightness)
|
|
|
|
|
{
|
|
|
|
|
constexpr auto hysteresis = [](const auto& lowThreshold, const auto& highThreshold, const auto& currentValue, const auto& newValue) {
|
|
|
|
|
if(newValue > highThreshold || newValue < lowThreshold)
|
|
|
|
|
return newValue;
|
|
|
|
|
return currentValue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(m_monitors.empty()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
@@ -365,6 +373,28 @@ bool MainWindow::setMonitorBrightness(float& brightness)
|
|
|
|
|
bool allMonitorsSameBrightness = true;
|
|
|
|
|
|
|
|
|
|
for(size_t i = 0; i < m_monitors.size(); ++i) {
|
|
|
|
|
const auto updateMonitorBrightness = [&] {
|
|
|
|
|
const auto brightnessRange = m_monitors[i].maxBrightness - m_monitors[i].minBrightness;
|
|
|
|
|
const auto hysteresisDelta = m_monitors[i].manualOverride ? 0.f : m_monitors[i].HYSTERESIS_THRESHOLD * brightnessRange;
|
|
|
|
|
const auto lowThreshold = std::clamp(m_monitors[i].prevBrightness - hysteresisDelta, m_monitors[i].minBrightness, m_monitors[i].maxBrightness);
|
|
|
|
|
const auto highThreshold = std::clamp(m_monitors[i].prevBrightness + hysteresisDelta, m_monitors[i].minBrightness, m_monitors[i].maxBrightness);
|
|
|
|
|
if(hysteresis(lowThreshold, highThreshold, m_monitors[i].prevBrightness, m_monitors[i].brightness) != m_monitors[i].prevBrightness) {
|
|
|
|
|
qDebug(ltr("Setting monitor %1 brightness from %2 to %3")
|
|
|
|
|
.arg(i)
|
|
|
|
|
.arg(m_monitors[i].prevBrightness, 0, 'f', 2)
|
|
|
|
|
.arg(m_monitors[i].brightness, 0, 'f', 2));
|
|
|
|
|
m_monitors[i].prevBrightness = m_monitors[i].brightness;
|
|
|
|
|
return m_monitors[i].driver.setBrightness(m_monitors[i].brightness);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
qDebug(ltr("Hysteresis prevented setting monitor %1 brightness from %2 to %3")
|
|
|
|
|
.arg(i)
|
|
|
|
|
.arg(m_monitors[i].prevBrightness, 0, 'f', 2)
|
|
|
|
|
.arg(m_monitors[i].brightness, 0, 'f', 2));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(!std::isnan(brightness) && !m_monitors[i].manualOverride) {
|
|
|
|
|
m_monitors[i].brightness = brightness;
|
|
|
|
|
}
|
|
|
|
|
@@ -375,7 +405,7 @@ bool MainWindow::setMonitorBrightness(float& brightness)
|
|
|
|
|
allMonitorsSameBrightness = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!m_monitors[i].driver.setBrightness(m_monitors[i].brightness)) {
|
|
|
|
|
if(!updateMonitorBrightness()) {
|
|
|
|
|
errorOccurred = true;
|
|
|
|
|
}
|
|
|
|
|
else if(m_ui.monitorDropdown->currentIndex() == static_cast<int>(i)) {
|
|
|
|
|
|