diff --git a/AdaptiveBrightness/main_window.cpp b/AdaptiveBrightness/main_window.cpp index 1c773d1..d6f3fff 100644 --- a/AdaptiveBrightness/main_window.cpp +++ b/AdaptiveBrightness/main_window.cpp @@ -64,13 +64,14 @@ void MainWindow::enumMonitors() m_mtx.lock(); m_ui.monitorDropdown->clear(); + m_monitors.clear(); auto monitors = enumerateMonitors(); for(auto& monitor: monitors) { 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_ui.monitorDropdown->addItem(m_monitors.back().driver.getName()); } m_mtx.unlock(); @@ -114,6 +115,7 @@ void MainWindow::loadIcons() void MainWindow::setupMonitorsTab() { connect(m_ui.monitorDropdown, QOverload::of(&QComboBox::currentIndexChanged), this, &MainWindow::updateCurrentMonitorGUI); + connect(m_ui.monitorEnumerateButton, &QAbstractButton::clicked, [this](bool) { enumMonitors(); }); setupLimitsSlider(); setupOverallLimitsSlider(); @@ -265,6 +267,10 @@ void MainWindow::setupCallbackTimer() 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.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));