From f3721da17996168489778327459084dd227690d6 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周六, 23 12月 2023 23:29:39 +0800
Subject: [PATCH] Adjust paint event handler

---
 src/widgets/widgetwindowagent_win.cpp |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/widgets/widgetwindowagent_win.cpp b/src/widgets/widgetwindowagent_win.cpp
index 3eb9f1e..7901bac 100644
--- a/src/widgets/widgetwindowagent_win.cpp
+++ b/src/widgets/widgetwindowagent_win.cpp
@@ -3,9 +3,14 @@
 #include <QtGui/QPainter>
 
 #include <QWKCore/qwindowkit_windows.h>
+#include <QWKCore/qwkconfig.h>
 #include <QWKCore/private/nativeeventfilter_p.h>
 
 namespace QWK {
+
+#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER)
+
+    class WidgetBorderHandler;
 
     class WidgetBorderHandler : public QObject, public NativeEventFilter {
     public:
@@ -64,11 +69,23 @@
         }
 
         bool eventFilter(QObject *obj, QEvent *event) override {
+            Q_UNUSED(obj)
             switch (event->type()) {
                 case QEvent::Paint: {
-                    if (widget->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen))
+                    if (widget->windowState() &
+                        (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen))
                         break;
 
+                    // Friend class helping to call `event`
+                    class HackedWidget : public QWidget {
+                    public:
+                        friend class WidgetBorderHandler;
+                    };
+
+                    // Let the widget paint first
+                    static_cast<HackedWidget *>(widget)->event(event);
+
+                    // Draw border
                     auto paintEvent = static_cast<QPaintEvent *>(event);
                     auto rect = paintEvent->rect();
                     auto region = paintEvent->region();
@@ -80,7 +97,7 @@
                         &region,
                     };
                     ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook, args);
-                    break;
+                    return true;
                 }
 
                 case QEvent::WindowStateChange: {
@@ -103,13 +120,16 @@
         QWidget *widget;
         AbstractWindowContext *ctx;
     };
+#endif
 
     void WidgetWindowAgentPrivate::setupWindows10BorderWorkaround() {
+#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER)
         // Install painting hook
         auto ctx = context.get();
         if (ctx->property("needBorderPainter").toBool()) {
             std::ignore = new WidgetBorderHandler(hostWidget, ctx);
         }
+#endif
     }
 
 }

--
Gitblit v1.9.1