From 02d1cd1ec0f544335ca1b31546737868a675439f Mon Sep 17 00:00:00 2001
From: Zhao Yuhang <2546789017@qq.com>
Date: 周六, 23 12月 2023 22:36:06 +0800
Subject: [PATCH] fix theme notify

---
 src/quick/quickwindowagent_win.cpp |   43 ++++++++++++++++++++++++++++++-------------
 1 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/quick/quickwindowagent_win.cpp b/src/quick/quickwindowagent_win.cpp
index 2049d29..8b2ea86 100644
--- a/src/quick/quickwindowagent_win.cpp
+++ b/src/quick/quickwindowagent_win.cpp
@@ -3,12 +3,14 @@
 #include <QtQuick/QQuickPaintedItem>
 #include <QtQuick/private/qquickitem_p.h>
 
-#include <QWKCore/private/eventobserver_p.h>
+#include <QWKCore/qwindowkit_windows.h>
+#include <QWKCore/qwkconfig.h>
+#include <QWKCore/private/nativeeventfilter_p.h>
 
 namespace QWK {
 
-    class BorderItem : public QQuickPaintedItem, public EventObserver {
-        Q_OBJECT
+#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER)
+    class BorderItem : public QQuickPaintedItem, public NativeEventFilter {
     public:
         explicit BorderItem(QQuickItem *parent, AbstractWindowContext *context);
         ~BorderItem() override;
@@ -20,7 +22,8 @@
         void itemChange(ItemChange change, const ItemChangeData &data) override;
 
     protected:
-        bool observe(QEvent *event) override;
+        bool nativeEventFilter(const QByteArray &eventType, void *message,
+                               QT_NATIVE_EVENT_RESULT_TYPE *result) override;
 
         AbstractWindowContext *context;
 
@@ -30,8 +33,7 @@
 
     BorderItem::BorderItem(QQuickItem *parent, AbstractWindowContext *context)
         : QQuickPaintedItem(parent), context(context) {
-        setAntialiasing(true);   // ### FIXME: do we need to enable or disable this?
-        setMipmap(true);         // ### FIXME: do we need to enable or disable this?
+        setAntialiasing(true);   // We needs anti-aliasing to give us better result.
         setFillColor({});        // Will improve the performance a little bit.
         setOpaquePainting(true); // Will also improve the performance, we don't draw
                                  // semi-transparent borders of course.
@@ -42,9 +44,9 @@
         anchors->setLeft(parentPri->left());
         anchors->setRight(parentPri->right());
 
-        setZ(10);
+        setZ(9999); // Make sure our fake border always above everything in the window.
 
-        context->addObserver(this);
+        context->installNativeEventFilter(this);
         connect(window(), &QQuickWindow::activeChanged, this,
                 &BorderItem::_q_windowActivityChanged);
         updateGeometry();
@@ -80,10 +82,24 @@
         }
     }
 
-    bool BorderItem::observe(QEvent *event) {
-        switch (event->type()) {
-            case QEvent::UpdateLater: {
+    bool BorderItem::nativeEventFilter(const QByteArray &eventType, void *message,
+                                       QT_NATIVE_EVENT_RESULT_TYPE *result) {
+        Q_UNUSED(eventType)
+        const auto msg = static_cast<const MSG *>(message);
+        switch (msg->message) {
+            case WM_THEMECHANGED:
+            case WM_SYSCOLORCHANGE:
+            case WM_DWMCOLORIZATIONCOLORCHANGED: {
                 update();
+                break;
+            }
+
+            case WM_SETTINGCHANGE: {
+                if (!msg->wParam && msg->lParam &&
+                    std::wcscmp(reinterpret_cast<LPCWSTR>(msg->lParam), L"ImmersiveColorSet") ==
+                        0) {
+                    update();
+                }
                 break;
             }
 
@@ -96,15 +112,16 @@
     void BorderItem::_q_windowActivityChanged() {
         update();
     }
+#endif
 
     void QuickWindowAgentPrivate::setupWindows10BorderWorkaround() {
+#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER)
         // Install painting hook
         auto ctx = context.get();
         if (ctx->property("needBorderPainter").toBool()) {
             std::ignore = new BorderItem(hostWindow->contentItem(), ctx);
         }
+#endif
     }
 
 }
-
-#include "quickwindowagent_win.moc"
\ No newline at end of file

--
Gitblit v1.9.1