From 8b72eabae325c34d8eab1544203993015cc91741 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 18 12月 2023 00:54:51 +0800
Subject: [PATCH] Add win32 winIdChange workaround

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

diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp
index 3b2340f..d69ab75 100644
--- a/src/core/contexts/abstractwindowcontext.cpp
+++ b/src/core/contexts/abstractwindowcontext.cpp
@@ -11,27 +11,17 @@
 
     AbstractWindowContext::~AbstractWindowContext() = default;
 
-    bool AbstractWindowContext::setup(QObject *host, WindowItemDelegate *delegate) {
-        if (!host || !delegate) {
-            return false;
+    void AbstractWindowContext::setup(QObject *host, WindowItemDelegate *delegate) {
+        if (m_host || !host || !delegate) {
+            return;
         }
-
-        auto windowHandle = delegate->hostWindow(host);
-        if (!windowHandle) {
-            return false;
-        }
-
         m_host = host;
         m_delegate.reset(delegate);
-        m_windowHandle = windowHandle;
-
-        if (!setupHost()) {
-            m_host = nullptr;
-            m_delegate.reset();
-            m_windowHandle = nullptr;
-            return false;
+        m_windowHandle = m_delegate->hostWindow(m_host);
+        if (m_windowHandle) {
+            m_windowHandleGuard = m_windowHandle;
+            winIdChanged(nullptr, false);
         }
-        return true;
     }
 
     bool AbstractWindowContext::setHitTestVisible(const QObject *obj, bool visible) {
@@ -45,21 +35,6 @@
         } else {
             m_hitTestVisibleItems.remove(obj);
         }
-        return true;
-    }
-
-    bool AbstractWindowContext::setHitTestVisible(const QRect &rect, bool visible) {
-        Q_ASSERT(rect.isValid());
-        if (!rect.isValid()) {
-            return false;
-        }
-
-        if (visible) {
-            m_hitTestVisibleRects.append(rect);
-        } else {
-            m_hitTestVisibleRects.removeAll(rect);
-        }
-        hitTestVisibleShapeDirty = true;
         return true;
     }
 
@@ -91,16 +66,12 @@
         return true;
     }
 
-    QRegion AbstractWindowContext::hitTestShape() const {
-        if (hitTestVisibleShapeDirty) {
-            hitTestVisibleShape = {};
-            for (const auto &rect : m_hitTestVisibleRects) {
-                hitTestVisibleShape += rect;
-            }
-            hitTestVisibleShapeDirty = false;
-        }
-        return hitTestVisibleShape;
+#ifdef Q_OS_MAC
+    void AbstractWindowContext::setSystemButtonArea(const QRect &rect) {
+        m_systemButtonArea = rect;
+        virtual_hook(SystemButtonAreaChangedHook, nullptr);
     }
+#endif
 
     bool AbstractWindowContext::isInSystemButtons(const QPoint &pos,
                                                   WindowAgentBase::SystemButton *button) const {
@@ -157,9 +128,6 @@
             }
         }
 
-        if (!m_hitTestVisibleRects.isEmpty() && hitTestShape().contains(pos)) {
-            return false;
-        }
         return true;
     }
 
@@ -205,4 +173,10 @@
         virtual_hook(ShowSystemMenuHook, &const_cast<QPoint &>(pos));
     }
 
+    void AbstractWindowContext::notifyWinIdChange() {
+        auto oldWindow = m_windowHandle;
+        m_windowHandle = m_delegate->window(m_host);
+        winIdChanged(oldWindow, oldWindow && m_windowHandleGuard.isNull());
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.1