sola.lu
2025-06-06 9dcea027f16c4ce5852da3dfc8aca284c582bd7d
src/core/style/styleagent_win.cpp
@@ -1,3 +1,7 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
#include "styleagent_p.h"
#include <QtCore/QSet>
@@ -11,6 +15,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:
@@ -26,15 +47,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;
                }
@@ -45,7 +64,7 @@
            return false;
        }
        static SystemSettingEventFilter *instance;
        static inline SystemSettingEventFilter *instance = nullptr;
        static inline void install() {
            if (instance) {
@@ -63,13 +82,11 @@
        }
    };
    SystemSettingEventFilter *SystemSettingEventFilter::instance = nullptr;
    void StyleAgentPrivate::setupSystemThemeHook() {
        systemTheme = getSystemTheme();
        g_styleAgentSet->insert(this);
        SystemSettingEventFilter::install();
        // Initialize `systemTheme` variable
    }
    void StyleAgentPrivate::removeSystemThemeHook() {