From 320cc56b7e9143b6de57e11015369a67c2835ccb Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Wed, 22 Feb 2023 16:23:49 +0100 Subject: [PATCH] [Shotcut Guide]Dismiss with mouse click (#23991) * dismiss with mouse * fix spellcheck --- .github/actions/spell-check/expect.txt | 1 + .../ShortcutGuide/shortcut_guide.cpp | 37 +++++++++++++++++++ .../ShortcutGuide/shortcut_guide.h | 5 ++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index e854c87522..9eeb1fa1ca 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -176,6 +176,7 @@ buildtask buildtransitive Burkina Buryatia +BUTTONUP BValue BYPOSITION bytearray diff --git a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp index 2843017ac6..f1c843d615 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp +++ b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.cpp @@ -160,6 +160,30 @@ namespace return CallNextHookEx(NULL, nCode, wParam, lParam); } + LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) + { + if (nCode >= 0) + { + switch (wParam) + { + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + case WM_XBUTTONUP: + // Don't close with mouse click if activation is windows key and the key is pressed + if (!overlay_window_instance->win_key_activation() || !isWinPressed()) + { + overlay_window_instance->CloseWindow(HideWindowType::MOUSE_BUTTONUP); + } + break; + default: + break; + } + } + + return CallNextHookEx(0, nCode, wParam, lParam); + } + std::wstring ToWstring(HideWindowType type) { switch (type) @@ -172,6 +196,8 @@ namespace return L"WIN_SHORTCUT_PRESSED"; case HideWindowType::THE_SHORTCUT_PRESSED: return L"THE_SHORTCUT_PRESSED"; + case HideWindowType::MOUSE_BUTTONUP: + return L"MOUSE_BUTTONUP"; } return L""; @@ -191,6 +217,12 @@ OverlayWindow::OverlayWindow(HWND activeWindow) { Logger::warn(L"Failed to create low level keyboard hook. {}", get_last_error_or_default(GetLastError())); } + + mouseHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, GetModuleHandle(NULL), NULL); + if (!mouseHook) + { + Logger::warn(L"Failed to create low level mouse hook. {}", get_last_error_or_default(GetLastError())); + } } void OverlayWindow::ShowWindow() @@ -316,6 +348,11 @@ bool OverlayWindow::overlay_visible() const return target_state->active(); } +bool OverlayWindow::win_key_activation() const +{ + return shouldReactToPressedWinKey.value; +} + void OverlayWindow::init_settings() { auto settings = GetSettings(); diff --git a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h index 418ddd1862..57f9bf3267 100644 --- a/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h +++ b/src/modules/ShortcutGuide/ShortcutGuide/shortcut_guide.h @@ -18,7 +18,8 @@ enum class HideWindowType ESC_PRESSED, WIN_RELEASED, WIN_SHORTCUT_PRESSED, - THE_SHORTCUT_PRESSED + THE_SHORTCUT_PRESSED, + MOUSE_BUTTONUP }; class OverlayWindow @@ -34,6 +35,7 @@ public: void was_hidden(); bool overlay_visible() const; + bool win_key_activation() const; bool is_disabled_app(wchar_t* exePath); @@ -52,6 +54,7 @@ private: void update_disabled_apps(); HWND activeWindow; HHOOK keyboardHook; + HHOOK mouseHook; struct OverlayOpacity {