From e6afd336212561bb89125e61eeaccfc4b90a926d Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Thu, 31 Oct 2019 10:26:24 +0100 Subject: [PATCH] Hide Shortcut Guide when screenshots are taken (#605) --- src/modules/shortcut_guide/overlay_window.cpp | 10 ++++++++++ src/modules/shortcut_guide/overlay_window.h | 1 + src/modules/shortcut_guide/shortcut_guide.cpp | 4 ++++ src/modules/shortcut_guide/shortcut_guide.h | 1 + src/modules/shortcut_guide/target_state.cpp | 6 ++++++ 5 files changed, 22 insertions(+) diff --git a/src/modules/shortcut_guide/overlay_window.cpp b/src/modules/shortcut_guide/overlay_window.cpp index 0b21982239..b374edaeba 100644 --- a/src/modules/shortcut_guide/overlay_window.cpp +++ b/src/modules/shortcut_guide/overlay_window.cpp @@ -385,6 +385,16 @@ void D2DOverlayWindow::set_theme(const std::wstring& theme) { } } +/* Hide the window but do not call on_hide(). Use this to quickly hide the window when needed. + Note, that a proper hide should be made after this before showing the window again. +*/ +void D2DOverlayWindow::quick_hide() { + ShowWindow(hwnd, SW_HIDE); + if (thumbnail) { + DwmUnregisterThumbnail(thumbnail); + } +} + float D2DOverlayWindow::get_overlay_opacity() { return overlay_opacity; } diff --git a/src/modules/shortcut_guide/overlay_window.h b/src/modules/shortcut_guide/overlay_window.h index c2f438c675..0421d69df1 100644 --- a/src/modules/shortcut_guide/overlay_window.h +++ b/src/modules/shortcut_guide/overlay_window.h @@ -47,6 +47,7 @@ public: ~D2DOverlayWindow(); void apply_overlay_opacity(float opacity); void set_theme(const std::wstring& theme); + void quick_hide(); private: void animate(int vk_code, int offset); bool show_thumbnail(const RECT& rect, double alpha); diff --git a/src/modules/shortcut_guide/shortcut_guide.cpp b/src/modules/shortcut_guide/shortcut_guide.cpp index 7866863489..6005c719e6 100644 --- a/src/modules/shortcut_guide/shortcut_guide.cpp +++ b/src/modules/shortcut_guide/shortcut_guide.cpp @@ -146,6 +146,10 @@ void OverlayWindow::on_held_press(DWORD vkCode) { winkey_popup->animate(vkCode); } +void OverlayWindow::quick_hide() { + winkey_popup->quick_hide(); +} + void OverlayWindow::was_hidden() { target_state->was_hiden(); } diff --git a/src/modules/shortcut_guide/shortcut_guide.h b/src/modules/shortcut_guide/shortcut_guide.h index 6e535e0006..f2d805cd38 100644 --- a/src/modules/shortcut_guide/shortcut_guide.h +++ b/src/modules/shortcut_guide/shortcut_guide.h @@ -23,6 +23,7 @@ public: void on_held(); void on_held_press(DWORD vkCode); + void quick_hide(); void was_hidden(); virtual void destroy() override; diff --git a/src/modules/shortcut_guide/target_state.cpp b/src/modules/shortcut_guide/target_state.cpp index c8e8f844b2..5ad00cf926 100644 --- a/src/modules/shortcut_guide/target_state.cpp +++ b/src/modules/shortcut_guide/target_state.cpp @@ -11,6 +11,12 @@ bool TargetState::signal_event(unsigned vk_code, bool key_down) { if (!events.empty() && events.back().key_down == key_down && events.back().vk_code == vk_code) { return false; } + // Hide the overlay when WinKey + Shift + S is pressed. 0x53 is the VK code of the S key + if (key_down && state == Shown && vk_code == 0x53 && (GetKeyState(VK_LSHIFT) || GetKeyState(VK_RSHIFT))) { + // We cannot use normal hide() here, there is stuff that needs deinitialization. + // It can be safely done when the user releases the WinKey. + instance->quick_hide(); + } bool supress = false; if (!key_down && (vk_code == VK_LWIN || vk_code == VK_RWIN) && state == Shown &&