From c837319767bb609c6ec806336e49a347c77b11d3 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周五, 22 12月 2023 21:30:53 +0800
Subject: [PATCH] Add non-system-border option on Windows

---
 src/core/style/styleagent_win.cpp |   62 ++++++++++++++++++++++---------
 1 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/src/core/style/styleagent_win.cpp b/src/core/style/styleagent_win.cpp
index 9d6072e..bee647a 100644
--- a/src/core/style/styleagent_win.cpp
+++ b/src/core/style/styleagent_win.cpp
@@ -21,27 +21,47 @@
                 return false;
             }
 
-            const auto msg = static_cast<const MSG *>(message);
-            switch (msg->message) {
-                case WM_THEMECHANGED:
-                case WM_SYSCOLORCHANGE:
-                case WM_DWMCOLORIZATIONCOLORCHANGED: {
-                    // TODO: walk through `g_styleAgentSet`
-                    break;
-                }
+            auto themeChanged = [message]() -> bool {
+                const auto msg = static_cast<const MSG *>(message);
+                switch (msg->message) {
+                    case WM_THEMECHANGED:
+                    case WM_SYSCOLORCHANGE:
+                    case WM_DWMCOLORIZATIONCOLORCHANGED:
+                        return true;
 
-                case WM_SETTINGCHANGE: {
-                    if (!msg->wParam && msg->lParam &&
-                        std::wcscmp(reinterpret_cast<LPCWSTR>(msg->lParam), L"ImmersiveColorSet") ==
+                    case WM_SETTINGCHANGE: {
+                        if (!msg->wParam && msg->lParam &&
+                            std::wcscmp(reinterpret_cast<LPCWSTR>(msg->lParam), L"ImmersiveColorSet") ==
                             0) {
-                        // TODO: walk through `g_styleAgentSet`
+                            return true;
+                        }
+                        break;
                     }
-                    break;
-                }
 
-                default:
-                    break;
+                    default:
+                        break;
+                }
+                return false;
+            }();
+
+            if (themeChanged) {
+                auto theme = []() -> StyleAgent::SystemTheme {
+                    if (isHighContrastModeEnabled()) {
+                        return StyleAgent::HighContrast;
+                    } else if (isDarkThemeActive()) {
+                        return StyleAgent::Dark;
+                    } else {
+                        return StyleAgent::Light;
+                    }
+                }();
+                for (auto &&ap : std::as_const(*g_styleAgentSet())) {
+                    if (ap->systemTheme != theme) {
+                        ap->systemTheme = theme;
+                        ap->notifyThemeChanged(theme);
+                    }
+                }
             }
+
             return false;
         }
 
@@ -66,10 +86,16 @@
     SystemSettingEventFilter *SystemSettingEventFilter::instance = nullptr;
 
     void StyleAgentPrivate::setupSystemThemeHook() {
+        if (isHighContrastModeEnabled()) {
+            systemTheme = StyleAgent::HighContrast;
+        } else if (isDarkThemeActive()) {
+            systemTheme = StyleAgent::Dark;
+        } else {
+            systemTheme = StyleAgent::Light;
+        }
+
         g_styleAgentSet->insert(this);
         SystemSettingEventFilter::install();
-
-        // Initialize `systemTheme` variable
     }
 
     void StyleAgentPrivate::removeSystemThemeHook() {

--
Gitblit v1.9.1