Add mutex to protect update thread
This commit is contained in:
parent
c930e316c4
commit
45116d8857
@ -61,6 +61,8 @@ void MainWindow::enumSensors()
|
|||||||
|
|
||||||
void MainWindow::enumMonitors()
|
void MainWindow::enumMonitors()
|
||||||
{
|
{
|
||||||
|
m_mtx.lock();
|
||||||
|
|
||||||
m_ui.monitorDropdown->clear();
|
m_ui.monitorDropdown->clear();
|
||||||
|
|
||||||
auto monitors = enumerateMonitors();
|
auto monitors = enumerateMonitors();
|
||||||
@ -70,6 +72,8 @@ void MainWindow::enumMonitors()
|
|||||||
m_ui.monitorDropdown->addItem(monitor.getName());
|
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_mtx.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadIcons()
|
void MainWindow::loadIcons()
|
||||||
@ -269,6 +273,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 +328,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)
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user