Set tray icon to average brightness value
This commit is contained in:
parent
1e3836cb9f
commit
c930e316c4
@ -301,14 +301,14 @@ void MainWindow::updateState()
|
|||||||
sensorError = true;
|
sensorError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto iconBrightness = utils::map(brightness, 0.f, 1.f, size_t{0}, size_t{8});
|
|
||||||
|
|
||||||
if(!setMonitorBrightness(brightness)) {
|
if(!setMonitorBrightness(brightness)) {
|
||||||
enumMonitors();
|
enumMonitors();
|
||||||
qInfo(ltr("At least one monitor became invalid, re-enumerating monitors found %1 valid monitor(s)").arg(m_monitors.size()));
|
qInfo(ltr("At least one monitor became invalid, re-enumerating monitors found %1 valid monitor(s)").arg(m_monitors.size()));
|
||||||
monitorError = true;
|
monitorError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto iconBrightness = utils::map(brightness, 0.f, 1.f, size_t{0}, size_t{8});
|
||||||
|
|
||||||
if(!sensorError && !monitorError && m_trayIcon) {
|
if(!sensorError && !monitorError && m_trayIcon) {
|
||||||
m_trayIcon->setIcon(*m_sensorStateIcons[iconBrightness]);
|
m_trayIcon->setIcon(*m_sensorStateIcons[iconBrightness]);
|
||||||
}
|
}
|
||||||
@ -324,7 +324,7 @@ void MainWindow::updateState()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::setMonitorBrightness(float brightness)
|
bool MainWindow::setMonitorBrightness(float& brightness)
|
||||||
{
|
{
|
||||||
if(m_monitors.empty()) {
|
if(m_monitors.empty()) {
|
||||||
return false;
|
return false;
|
||||||
@ -352,8 +352,15 @@ bool MainWindow::setMonitorBrightness(float brightness)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!errorOccurred) {
|
||||||
|
auto avgBrightness = 0.f;
|
||||||
|
std::for_each(m_monitors.begin(), m_monitors.end(), [&avgBrightness](const auto& mon) { avgBrightness += mon.brightness; });
|
||||||
|
avgBrightness /= m_monitors.size();
|
||||||
|
brightness = avgBrightness;
|
||||||
|
}
|
||||||
|
|
||||||
if(allMonitorsSameBrightness) {
|
if(allMonitorsSameBrightness) {
|
||||||
m_ui.monitorOverallBrightnessSlider->setValue(utils::map(m_monitors.front().brightness, 0.f, 1.f, 0, 100));
|
m_ui.monitorOverallBrightnessSlider->setValue(utils::map(brightness, 0.f, 1.f, 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
return !errorOccurred;
|
return !errorOccurred;
|
||||||
|
@ -46,7 +46,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
void updateState();
|
void updateState();
|
||||||
|
|
||||||
bool setMonitorBrightness(float brightness);
|
bool setMonitorBrightness(float& brightness);
|
||||||
|
|
||||||
void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
|
void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user