From 8c1228a7aaf50b98ade67d2f37066f991da16cd3 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 24 Jun 2024 13:25:16 +1000 Subject: [PATCH] Qt: Tidy up theme change workaround --- src/duckstation-qt/logwindow.cpp | 5 +---- src/duckstation-qt/mainwindow.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/duckstation-qt/logwindow.cpp b/src/duckstation-qt/logwindow.cpp index e4f946f8a..67dafb862 100644 --- a/src/duckstation-qt/logwindow.cpp +++ b/src/duckstation-qt/logwindow.cpp @@ -27,10 +27,7 @@ LogWindow::LogWindow(bool attach_to_main) Log::RegisterCallback(&LogWindow::logCallback, this); } -LogWindow::~LogWindow() -{ - Log::UnregisterCallback(&LogWindow::logCallback, this); -} +LogWindow::~LogWindow() = default; void LogWindow::updateSettings() { diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 0f9c49767..e5e8925cf 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -134,7 +133,6 @@ MainWindow::~MainWindow() Assert(!m_display_widget); Assert(!m_debugger_window); cancelGameListRefresh(); - destroySubWindows(); // we compare here, since recreate destroys the window later if (g_main_window == this) @@ -596,6 +594,7 @@ void MainWindow::onSystemDestroyed() // If we're closing or in batch mode, quit the whole application now. if (m_is_closing || QtHost::InBatchMode()) { + destroySubWindows(); quit(); return; } @@ -744,6 +743,11 @@ void MainWindow::recreate() new_main_window->show(); deleteLater(); + // Recreate log window as well. Then make sure we're still on top. + LogWindow::updateSettings(); + new_main_window->raise(); + new_main_window->activateWindow(); + // Reload the sources we just closed. g_emu_thread->reloadInputSources(); @@ -2204,21 +2208,17 @@ void MainWindow::connectSignals() void MainWindow::setTheme(const QString& theme) { - [[maybe_unused]] const QString old_theme = - QString::fromStdString(Host::GetStringSettingValue("UI", "Theme", InterfaceSettingsWidget::DEFAULT_THEME_NAME)); + [[maybe_unused]] const QString old_style_name = qApp->style()->name(); Host::SetBaseStringSettingValue("UI", "Theme", theme.toUtf8().constData()); Host::CommitBaseSettingChanges(); updateTheme(); #ifdef _WIN32 - if (((old_theme.isEmpty() && QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) || - old_theme == QStringLiteral("windowsvista")) != - ((old_theme.isEmpty() && QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) || - theme == QStringLiteral("windowsvista"))) - { + // Work around a bug where the background colour of menus is broken when changing to/from the windowsvista theme. + const QString new_style_name = qApp->style()->name(); + if ((old_style_name == QStringLiteral("windowsvista")) != (new_style_name == QStringLiteral("windowsvista"))) recreate(); - } #endif }