From a0bede6ff6a700a6eea9702c49d378f07de22f63 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周三, 06 12月 2023 12:11:37 +0800
Subject: [PATCH] Fix title bar hover bug

---
 src/core/contexts/abstractwindowcontext_p.h |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/core/contexts/abstractwindowcontext_p.h b/src/core/contexts/abstractwindowcontext_p.h
index fd3a445..996a0e3 100644
--- a/src/core/contexts/abstractwindowcontext_p.h
+++ b/src/core/contexts/abstractwindowcontext_p.h
@@ -1,6 +1,9 @@
 #ifndef ABSTRACTWINDOWCONTEXT_P_H
 #define ABSTRACTWINDOWCONTEXT_P_H
 
+#include <array>
+#include <memory>
+
 #include <QtCore/QSet>
 #include <QtGui/QWindow>
 #include <QtGui/QPolygon>
@@ -13,16 +16,14 @@
     class QWK_CORE_EXPORT AbstractWindowContext : public QObject {
         Q_OBJECT
     public:
-        inline AbstractWindowContext(QWindow *window, WindowItemDelegate *delegate)
-            : m_windowHandle(window), m_delegate(delegate) {
-        }
-        ~AbstractWindowContext();
+        AbstractWindowContext(QObject *host, WindowItemDelegate *delegate);
+        ~AbstractWindowContext() override;
 
     public:
         virtual bool setup() = 0;
 
+        inline QObject *host() const;
         inline QWindow *window() const;
-        void setupWindow(QWindow *window);
 
         inline bool isHitTestVisible(QObject *obj) const;
         bool setHitTestVisible(QObject *obj, bool visible);
@@ -36,20 +37,30 @@
 
         void showSystemMenu(const QPoint &pos);
 
+        QRegion hitTestShape() const;
+        bool isInSystemButtons(const QPoint &pos, CoreWindowAgent::SystemButton *button) const;
+        bool isInTitleBarDraggableArea(const QPoint &pos) const;
+
     protected:
+        QObject *m_host;
+        std::unique_ptr<WindowItemDelegate> m_delegate;
         QWindow *m_windowHandle;
-        WindowItemDelegate *m_delegate;
 
         QSet<QObject *> m_hitTestVisibleItems;
         QList<QRect> m_hitTestVisibleRects;
 
         QObject *m_titleBar{};
-        QObject *m_systemButtons[CoreWindowAgent::NumSystemButton]{};
+        std::array<QObject *, CoreWindowAgent::NumSystemButton> m_systemButtons{};
 
+        // Cached shape
         mutable bool hitTestVisibleShapeDirty{};
-        mutable QPolygon hitTestVisibleShape;
+        mutable QRegion hitTestVisibleShape;
     };
 
+    inline QObject *AbstractWindowContext::host() const {
+        return m_host;
+    }
+
     inline QWindow *AbstractWindowContext::window() const {
         return m_windowHandle;
     }

--
Gitblit v1.9.1