From 4f9f75cb4b70f3b76cee57d0f98b59f8475bba3b Mon Sep 17 00:00:00 2001 From: SineStriker <trueful@163.com> Date: 周三, 27 12月 2023 05:56:28 +0800 Subject: [PATCH] Add mac theme notifications --- src/core/style/styleagent_win.cpp | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/core/style/styleagent_win.cpp b/src/core/style/styleagent_win.cpp index 9d6072e..e118713 100644 --- a/src/core/style/styleagent_win.cpp +++ b/src/core/style/styleagent_win.cpp @@ -12,6 +12,23 @@ using StyleAgentSet = QSet<StyleAgentPrivate *>; Q_GLOBAL_STATIC(StyleAgentSet, g_styleAgentSet) + static StyleAgent::SystemTheme getSystemTheme() { + if (isHighContrastModeEnabled()) { + return StyleAgent::HighContrast; + } else if (isDarkThemeActive()) { + return StyleAgent::Dark; + } else { + return StyleAgent::Light; + } + } + + static void notifyAllStyleAgents() { + auto theme = getSystemTheme(); + for (auto &&ap : std::as_const(*g_styleAgentSet())) { + ap->notifyThemeChanged(theme); + } + } + class SystemSettingEventFilter : public AppNativeEventFilter { public: bool nativeEventFilter(const QByteArray &eventType, void *message, @@ -26,15 +43,13 @@ case WM_THEMECHANGED: case WM_SYSCOLORCHANGE: case WM_DWMCOLORIZATIONCOLORCHANGED: { - // TODO: walk through `g_styleAgentSet` + notifyAllStyleAgents(); break; } case WM_SETTINGCHANGE: { - if (!msg->wParam && msg->lParam && - std::wcscmp(reinterpret_cast<LPCWSTR>(msg->lParam), L"ImmersiveColorSet") == - 0) { - // TODO: walk through `g_styleAgentSet` + if (isImmersiveColorSetChange(msg->wParam, msg->lParam)) { + notifyAllStyleAgents(); } break; } @@ -66,10 +81,10 @@ SystemSettingEventFilter *SystemSettingEventFilter::instance = nullptr; void StyleAgentPrivate::setupSystemThemeHook() { + systemTheme = getSystemTheme(); + g_styleAgentSet->insert(this); SystemSettingEventFilter::install(); - - // Initialize `systemTheme` variable } void StyleAgentPrivate::removeSystemThemeHook() { -- Gitblit v1.9.1