From 41a4103ffcce0efb6d532a15d307ab98177c997e Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 04 12月 2023 16:57:47 +0800
Subject: [PATCH] Update delegate

---
 src/core/contexts/abstractwindowcontext.cpp |   41 +++++++++++++++++++++++++++++++++++++++++
 qmsetup                                     |    2 +-
 src/core/contexts/abstractwindowcontext_p.h |    1 +
 src/core/contexts/win32windowcontext.cpp    |   10 +++++-----
 4 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/qmsetup b/qmsetup
index d5d9a3e..65369fc 160000
--- a/qmsetup
+++ b/qmsetup
@@ -1 +1 @@
-Subproject commit d5d9a3efa97633cd275a133d924ea998ea708f7a
+Subproject commit 65369fcf7def72a0aeec59724cdb63e9c5f0475d
diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp
index 5c75d28..a3d2bba 100644
--- a/src/core/contexts/abstractwindowcontext.cpp
+++ b/src/core/contexts/abstractwindowcontext.cpp
@@ -101,4 +101,45 @@
         return false;
     }
 
+    bool AbstractWindowContext::isInTitleBarDraggableArea(const QPoint &pos) const {
+        if (!m_titleBar) {
+            // There's no title bar at all, the mouse will always be in the client area.
+            return false;
+        }
+        if (!m_delegate->isVisible(m_titleBar) || !m_delegate->isEnabled(m_titleBar)) {
+            // The title bar is hidden or disabled for some reason, treat it as there's
+            // no title bar.
+            return false;
+        }
+        QRect windowRect = {QPoint(0, 0), m_windowHandle->size()};
+        QRect titleBarRect = m_delegate->mapGeometryToScene(m_titleBar);
+        if (!titleBarRect.intersects(windowRect)) {
+            // The title bar is totally outside the window for some reason,
+            // also treat it as there's no title bar.
+            return false;
+        }
+
+        for (int i = CoreWindowAgent::WindowIcon; i <= CoreWindowAgent::Close; ++i) {
+            auto currentButton = m_systemButtons[i];
+            if (currentButton && m_delegate->isVisible(currentButton) &&
+                m_delegate->isEnabled(currentButton) &&
+                m_delegate->mapGeometryToScene(currentButton).contains(pos)) {
+                return true;
+            }
+        }
+
+        for (auto widget : m_hitTestVisibleItems) {
+            if (widget && m_delegate->isVisible(widget) && m_delegate->isEnabled(widget) &&
+                m_delegate->mapGeometryToScene(widget).contains(pos)) {
+                return true;
+            }
+        }
+
+        if (hitTestShape().contains(pos)) {
+            return true;
+        }
+
+        return false;
+    }
+
 }
\ No newline at end of file
diff --git a/src/core/contexts/abstractwindowcontext_p.h b/src/core/contexts/abstractwindowcontext_p.h
index 83ad768..54471fe 100644
--- a/src/core/contexts/abstractwindowcontext_p.h
+++ b/src/core/contexts/abstractwindowcontext_p.h
@@ -41,6 +41,7 @@
 
         QRegion hitTestShape() const;
         bool isInSystemButtons(const QPoint &pos, CoreWindowAgent::SystemButton *button) const;
+        bool isInTitleBarDraggableArea(const QPoint &pos) const;
 
     protected:
         QWindow *m_windowHandle;
diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index 02f3cd1..d88418e 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -158,13 +158,13 @@
         if (apis.pGetDpiForWindow) {         // Win10
             return apis.pGetDpiForWindow(hwnd);
         } else if (apis.pGetDpiForMonitor) { // Win8.1
-             HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
+            HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
             UINT dpiX{USER_DEFAULT_SCREEN_DPI};
             UINT dpiY{USER_DEFAULT_SCREEN_DPI};
             apis.pGetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
             return dpiX;
         } else { // Win2K
-             HDC hdc = ::GetDC(nullptr);
+            HDC hdc = ::GetDC(nullptr);
             const int dpiX = ::GetDeviceCaps(hdc, LOGPIXELSX);
             const int dpiY = ::GetDeviceCaps(hdc, LOGPIXELSY);
             ::ReleaseDC(nullptr, hdc);
@@ -194,7 +194,7 @@
         }
         // Use "MONITOR_DEFAULTTONEAREST" here so that we can still get the correct
         // monitor even if the window is minimized.
-         HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
+        HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
         MONITORINFOEXW monitorInfo{};
         monitorInfo.cbSize = sizeof(monitorInfo);
         ::GetMonitorInfoW(monitor, &monitorInfo);
@@ -945,9 +945,9 @@
                             APPBARDATA abd2{};
                             abd2.cbSize = sizeof(abd2);
                             abd2.hWnd = ::FindWindowW(L"Shell_TrayWnd", nullptr);
-                             HMONITOR windowMonitor =
+                            HMONITOR windowMonitor =
                                 ::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
-                             HMONITOR taskbarMonitor =
+                            HMONITOR taskbarMonitor =
                                 ::MonitorFromWindow(abd2.hWnd, MONITOR_DEFAULTTOPRIMARY);
                             if (taskbarMonitor == windowMonitor) {
                                 ::SHAppBarMessage(ABM_GETTASKBARPOS, &abd2);

--
Gitblit v1.9.1