From ea8d13724433cab8ccf53e76f9b8b553d76141ff Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周三, 08 5月 2024 13:38:24 +0800 Subject: [PATCH] minor tweaks --- src/core/contexts/win32windowcontext.cpp | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index 93a186c..e32142e 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; @@ -1382,13 +1388,16 @@ // menu while Windows will create and execute a new event loop // until the menu returns iconButtonClickTime = ::GetTickCount64(); - *result = - ::DefWindowProcW(hWnd, WM_NCLBUTTONDOWN, wParam, lParam); - if (iconButtonClickLevel == 2) { + *result = ::DefWindowProcW(hWnd, message, wParam, lParam); + 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 +2155,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 @@ -2165,11 +2175,23 @@ WH_MOUSE, [](int nCode, WPARAM wParam, LPARAM lParam) { if (nCode >= 0) { - if (wParam == WM_LBUTTONDOWN || wParam == WM_LBUTTONDBLCLK) { - auto pMouseStruct = reinterpret_cast<MOUSEHOOKSTRUCT *>(lParam); - if (pMouseStruct) { - mouseClickPos = pMouseStruct->pt; + switch (wParam) { + case WM_LBUTTONDBLCLK: + mouseDoubleClicked = true; + Q_FALLTHROUGH(); + + // case WM_POINTERDOWN: + + case WM_LBUTTONDOWN: { + auto pMouseStruct = + reinterpret_cast<MOUSEHOOKSTRUCT *>(lParam); + if (pMouseStruct) { + mouseClickPos = pMouseStruct->pt; + } + break; } + default: + break; } } return ::CallNextHookEx(nullptr, nCode, wParam, lParam); @@ -2196,15 +2218,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