diff options
author | Yuhang Zhao <2546789017@qq.com> | 2022-03-31 10:26:16 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-04-26 13:44:49 +0800 |
commit | 1ed449e168af133184633d174fd7339a13d1d595 (patch) | |
tree | 2914db98378a46d70f13a3805fa82b05e200652a /src/plugins/platforms/windows/qwindowscontext.cpp | |
parent | 9f9be33180f6a9522705045c57a268df2b27b540 (diff) |
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 <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index f32b82bb11..721e6a4929 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<LPCWSTR>(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(); |