From 09287f3d9e9e88271de2bfd5388dae5a53e8c6f5 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 摹曛, 07 12月 2023 15:03:24 +0800
Subject: [PATCH] Add host event filter

---
 src/core/corewindowagent.cpp |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/src/core/corewindowagent.cpp b/src/core/corewindowagent.cpp
index 5d1f74e..d5dff5a 100644
--- a/src/core/corewindowagent.cpp
+++ b/src/core/corewindowagent.cpp
@@ -16,30 +16,28 @@
     CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), context(nullptr) {
     }
 
-    CoreWindowAgentPrivate::~CoreWindowAgentPrivate() {
-        if (context) {
-            delete context;
-            context = nullptr;
-        }
-    }
+    CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default;
 
     void CoreWindowAgentPrivate::init() {
     }
 
-    bool CoreWindowAgentPrivate::setup(const QObject *host, const WindowItemDelegate *delegate) {
-        auto ctx =
+    AbstractWindowContext *CoreWindowAgentPrivate::createContext() const {
+        return
 #ifdef Q_OS_WINDOWS
-            new Win32WindowContext(host, delegate)
+            new Win32WindowContext()
 #else
-            new QtWindowContext(host, window, delegate)
+            new QtWindowContext()
 #endif
-            ;
-        if (!ctx->setup()) {
-            delete ctx;
-            ctx = nullptr;
+                ;
+    }
+
+
+    bool CoreWindowAgentPrivate::setup(QObject *host, WindowItemDelegate *delegate) {
+        std::unique_ptr<AbstractWindowContext> ctx(createContext());
+        if (!ctx->setup(host, delegate)) {
             return false;
         }
-        context = ctx;
+        context = std::move(ctx);
         return true;
     }
 

--
Gitblit v1.9.1