From 3871bfc5d3aff45e498fa2944c27e6eb5d146c8e Mon Sep 17 00:00:00 2001
From: SineStriker <trueful@163.com>
Date: 周三, 20 12月 2023 19:56:32 +0800
Subject: [PATCH] Add mac hot-switch implementations

---
 src/widgets/widgetwindowagent.cpp |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/widgets/widgetwindowagent.cpp b/src/widgets/widgetwindowagent.cpp
index 8b6988e..a15a7ed 100644
--- a/src/widgets/widgetwindowagent.cpp
+++ b/src/widgets/widgetwindowagent.cpp
@@ -9,6 +9,27 @@
 
 namespace QWK {
 
+    class WidgetWinIdChangeEventFilter : public QObject {
+    public:
+        explicit WidgetWinIdChangeEventFilter(QWidget *widget, AbstractWindowContext *ctx)
+            : QObject(ctx), widget(widget), ctx(ctx) {
+            widget->installEventFilter(this);
+        }
+
+    protected:
+        bool eventFilter(QObject *obj, QEvent *event) override {
+            Q_UNUSED(obj)
+            if (event->type() == QEvent::WinIdChange) {
+                ctx->notifyWinIdChange();
+            }
+            return false;
+        }
+
+    protected:
+        QWidget *widget;
+        AbstractWindowContext *ctx;
+    };
+
     WidgetWindowAgentPrivate::WidgetWindowAgentPrivate() = default;
 
     WidgetWindowAgentPrivate::~WidgetWindowAgentPrivate() = default;
@@ -36,14 +57,14 @@
         w->setAttribute(Qt::WA_DontCreateNativeAncestors);
         w->setAttribute(Qt::WA_NativeWindow);
 
-        if (!d->setup(w, new WidgetItemDelegate())) {
-            return false;
-        }
+        d->setup(w, new WidgetItemDelegate());
         d->hostWidget = w;
 
 #ifdef Q_OS_WINDOWS
         d->setupWindows10BorderWorkaround();
 #endif
+        std::ignore = new WidgetWinIdChangeEventFilter(w, d->context.get());
+
         return true;
     }
 

--
Gitblit v1.9.1