Compare commits

...

2 Commits

Author SHA1 Message Date
42043bcd55 Implement re-enumerate button 2020-07-17 18:35:56 +02:00
45116d8857 Add mutex to protect update thread 2020-07-17 18:35:38 +02:00
2 changed files with 17 additions and 1 deletions

View File

@ -61,15 +61,20 @@ void MainWindow::enumSensors()
void MainWindow::enumMonitors() void MainWindow::enumMonitors()
{ {
m_mtx.lock();
m_ui.monitorDropdown->clear(); m_ui.monitorDropdown->clear();
m_monitors.clear();
auto monitors = enumerateMonitors(); auto monitors = enumerateMonitors();
for(auto& monitor: monitors) { for(auto& monitor: monitors) {
const auto currentBrightness = monitor.getBrightness(); const auto currentBrightness = monitor.getBrightness();
m_ui.monitorDropdown->addItem(monitor.getName());
m_monitors.push_back({std::move(monitor), 0.f, 1.f, currentBrightness, false}); m_monitors.push_back({std::move(monitor), 0.f, 1.f, currentBrightness, false});
m_ui.monitorDropdown->addItem(m_monitors.back().driver.getName());
} }
m_mtx.unlock();
} }
void MainWindow::loadIcons() void MainWindow::loadIcons()
@ -110,6 +115,7 @@ void MainWindow::loadIcons()
void MainWindow::setupMonitorsTab() void MainWindow::setupMonitorsTab()
{ {
connect(m_ui.monitorDropdown, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::updateCurrentMonitorGUI); connect(m_ui.monitorDropdown, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::updateCurrentMonitorGUI);
connect(m_ui.monitorEnumerateButton, &QAbstractButton::clicked, [this](bool) { enumMonitors(); });
setupLimitsSlider(); setupLimitsSlider();
setupOverallLimitsSlider(); setupOverallLimitsSlider();
@ -261,6 +267,10 @@ void MainWindow::setupCallbackTimer()
void MainWindow::updateCurrentMonitorGUI(int index) void MainWindow::updateCurrentMonitorGUI(int index)
{ {
if(index == -1) {
return;
}
m_ui.monitorMinBrightnessSlider->setValue(utils::map(m_monitors[index].minBrightness, 0.f, 1.f, 0, 100)); m_ui.monitorMinBrightnessSlider->setValue(utils::map(m_monitors[index].minBrightness, 0.f, 1.f, 0, 100));
m_ui.monitorMaxBrightnessSlider->setValue(utils::map(m_monitors[index].maxBrightness, 0.f, 1.f, 0, 100)); m_ui.monitorMaxBrightnessSlider->setValue(utils::map(m_monitors[index].maxBrightness, 0.f, 1.f, 0, 100));
m_ui.monitorBrightnessSlider->setValue(utils::map(m_monitors[index].brightness, 0.f, 1.f, 0, 100)); m_ui.monitorBrightnessSlider->setValue(utils::map(m_monitors[index].brightness, 0.f, 1.f, 0, 100));
@ -269,6 +279,8 @@ void MainWindow::updateCurrentMonitorGUI(int index)
void MainWindow::updateState() void MainWindow::updateState()
{ {
m_mtx.lock();
qDebug(ltr("Updating state")); qDebug(ltr("Updating state"));
bool sensorError = false; bool sensorError = false;
@ -322,6 +334,8 @@ void MainWindow::updateState()
if(m_trayIcon) { if(m_trayIcon) {
m_trayIcon->setToolTip(tr("AdaptiveBrightness - %1%").arg(brightness * 100, 0, 'f', 0)); m_trayIcon->setToolTip(tr("AdaptiveBrightness - %1%").arg(brightness * 100, 0, 'f', 0));
} }
m_mtx.unlock();
} }
bool MainWindow::setMonitorBrightness(float& brightness) bool MainWindow::setMonitorBrightness(float& brightness)

View File

@ -8,6 +8,7 @@
#include <QIcon> #include <QIcon>
#include <QMainWindow> #include <QMainWindow>
#include <QMenu> #include <QMenu>
#include <QMutex>
#include <QSlider> #include <QSlider>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QThread> #include <QThread>
@ -63,6 +64,7 @@ class MainWindow : public QMainWindow {
QThread* m_timerThread = nullptr; QThread* m_timerThread = nullptr;
QTimer* m_timer = nullptr; QTimer* m_timer = nullptr;
QMutex m_mtx;
struct SensorData { struct SensorData {
Sensor driver; Sensor driver;