From 1ed449e168af133184633d174fd7339a13d1d595 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Thu, 31 Mar 2022 10:26:16 +0800 Subject: [PATCH] Windows QPA: Only refresh the window theme if it really changes WM_SETTINGCHANGE may be triggered in many different reasons, we don't have to verify whether the system changes the global theme or not in all cases. Although not officially documented, there's a widely known and used technique to detect whether the user actually changes the personalize settings or not, that is when wParam is 0 and lParam is "ImmersiveColorSet", this combination indicates system's personalize settings has been changed. We can get rid of most unneeded verify of system theme by only execute the logic in this specific case. Change-Id: Iaf934c29975b3b2090fd692776f80b1125d3ddb3 Reviewed-by: Oliver Wolff --- .../platforms/windows/qwindowscontext.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index f32b82bb112..721e6a4929e 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1154,17 +1154,20 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, return false; case QtWindows::SettingChangedEvent: { QWindowsWindow::settingsChanged(); - const bool darkMode = QWindowsTheme::queryDarkMode(); - if (darkMode != QWindowsContextPrivate::m_darkMode) { - QWindowsContextPrivate::m_darkMode = darkMode; - auto integration = QWindowsIntegration::instance(); - if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) { - for (QWindowsWindow *w : d->m_windows) - w->setDarkBorder(QWindowsContextPrivate::m_darkMode); - } - if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) { - QWindowsTheme::instance()->refresh(); - QWindowSystemInterface::handleThemeChange(); + // Only refresh the window theme if the user changes the personalize settings. + if (wParam == 0 && wcscmp(reinterpret_cast(lParam), L"ImmersiveColorSet") == 0) { + const bool darkMode = QWindowsTheme::queryDarkMode(); + if (darkMode != QWindowsContextPrivate::m_darkMode) { + QWindowsContextPrivate::m_darkMode = darkMode; + auto integration = QWindowsIntegration::instance(); + if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeWindowFrames)) { + for (QWindowsWindow *w : d->m_windows) + w->setDarkBorder(QWindowsContextPrivate::m_darkMode); + } + if (integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) { + QWindowsTheme::instance()->refresh(); + QWindowSystemInterface::handleThemeChange(); + } } } return d->m_screenManager.handleScreenChanges();