[Shotcut Guide]Dismiss with mouse click (#23991)

* dismiss with mouse

* fix spellcheck
This commit is contained in:
Davide Giacometti 2023-02-22 16:23:49 +01:00 committed by GitHub
parent 0b281677df
commit 320cc56b7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View File

@ -176,6 +176,7 @@ buildtask
buildtransitive
Burkina
Buryatia
BUTTONUP
BValue
BYPOSITION
bytearray

View File

@ -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();

View File

@ -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
{