From d3d7430ec9afb94abaf78fa2c9edd9d9f946881c Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 18 12月 2023 01:29:07 +0800
Subject: [PATCH] Add QtContext WinIdChange workaround

---
 src/core/contexts/qtwindowcontext.cpp |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp
index 78b0de1..35fc2d1 100644
--- a/src/core/contexts/qtwindowcontext.cpp
+++ b/src/core/contexts/qtwindowcontext.cpp
@@ -103,7 +103,8 @@
 
     QtWindowEventFilter::~QtWindowEventFilter() = default;
 
-    bool QtWindowEventFilter::eventFilter(QObject *object, QEvent *event) {
+    bool QtWindowEventFilter::eventFilter(QObject *obj, QEvent *event) {
+        Q_UNUSED(obj)
         auto type = event->type();
         if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) {
             return false;
@@ -114,8 +115,8 @@
         bool fixedSize = delegate->isHostSizeFixed(host);
         auto me = static_cast<const QMouseEvent *>(event);
 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
-        QPoint scenePos = mouseEvent->scenePosition().toPoint();
-        QPoint globalPos = mouseEvent->globalPosition().toPoint();
+        QPoint scenePos = me->scenePosition().toPoint();
+        QPoint globalPos = me->globalPosition().toPoint();
 #else
         QPoint scenePos = me->windowPos().toPoint();
         QPoint globalPos = me->screenPos().toPoint();
@@ -252,10 +253,11 @@
         AbstractWindowContext::virtual_hook(id, data);
     }
 
-    bool QtWindowContext::setupHost() {
-        m_delegate->setWindowFlags(m_host, Qt::FramelessWindowHint);
-        std::ignore = new QtWindowEventFilter(this, this);
-        return true;
+    void QtWindowContext::winIdChanged(QWindow *oldWindow) {
+        Q_UNUSED(oldWindow)
+        m_delegate->setWindowFlags(m_host,
+                                   m_delegate->getWindowFlags(m_host) | Qt::FramelessWindowHint);
+        qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this);
     }
 
-}
\ No newline at end of file
+}

--
Gitblit v1.9.1