From dd961a654f29fe6a59a093f8b4b0fff726efbd4a Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周三, 08 5月 2024 11:55:57 +0800
Subject: [PATCH] Fix a mistake

---
 src/core/contexts/win32windowcontext.cpp |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index 93a186c..a448ed6 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -35,6 +35,12 @@
 
 namespace QWK {
 
+    enum IconButtonClickLevelFlag {
+        IconButtonClicked = 1,
+        IconButtonDoubleClicked = 2,
+        IconButtonTriggersClose = 4,
+    };
+
     // The thickness of an auto-hide taskbar in pixels.
     static constexpr const quint8 kAutoHideTaskBarThickness = 2;
 
@@ -1384,11 +1390,15 @@
                                     iconButtonClickTime = ::GetTickCount64();
                                     *result =
                                         ::DefWindowProcW(hWnd, WM_NCLBUTTONDOWN, wParam, lParam);
-                                    if (iconButtonClickLevel == 2) {
+                                    if (iconButtonClickLevel & IconButtonTriggersClose) {
                                         ::PostMessageW(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
                                     }
-                                    // No need to reset `iconButtonClickLevel`, if it has value,
-                                    // there must be another incoming WM_NCLBUTTONDOWN
+                                    if (iconButtonClickLevel & IconButtonDoubleClicked) {
+                                        iconButtonClickLevel = 0;
+                                    }
+                                    // Otherwise, no need to reset `iconButtonClickLevel` if not to
+                                    // close, if it has value, there must be another incoming
+                                    // WM_NCLBUTTONDOWN
                                 } else {
                                     iconButtonClickLevel = 0;
                                 }
@@ -2146,6 +2156,7 @@
         if (shouldShowSystemMenu) {
             static HHOOK mouseHook = nullptr;
             static std::optional<POINT> mouseClickPos;
+            static bool mouseDoubleClicked = false;
             bool mouseHookedLocal = false;
 
             // The menu is triggered by a click on icon button
@@ -2166,6 +2177,9 @@
                         [](int nCode, WPARAM wParam, LPARAM lParam) {
                             if (nCode >= 0) {
                                 if (wParam == WM_LBUTTONDOWN || wParam == WM_LBUTTONDBLCLK) {
+                                    if (wParam == WM_LBUTTONDBLCLK) {
+                                        mouseDoubleClicked = true;
+                                    }
                                     auto pMouseStruct = reinterpret_cast<MOUSEHOOKSTRUCT *>(lParam);
                                     if (pMouseStruct) {
                                         mouseClickPos = pMouseStruct->pt;
@@ -2196,15 +2210,20 @@
                     WindowAgentBase::SystemButton sysButtonType = WindowAgentBase::Unknown;
                     if (isInSystemButtons(qtScenePos, &sysButtonType) &&
                         sysButtonType == WindowAgentBase::WindowIcon) {
-                        iconButtonClickLevel = 1;
+                        iconButtonClickLevel |= IconButtonClicked;
                         if (::GetTickCount64() - iconButtonClickTime <= doubleClickTime) {
-                            iconButtonClickLevel = 2;
+                            iconButtonClickLevel |= IconButtonTriggersClose;
                         }
                     }
                 }
 
+                if (mouseDoubleClicked) {
+                    iconButtonClickLevel |= IconButtonDoubleClicked;
+                }
+
                 mouseHook = nullptr;
                 mouseClickPos.reset();
+                mouseDoubleClicked = false;
             }
 
             // QPA's internal code will handle system menu events separately, and its

--
Gitblit v1.9.1