Skip to content

Commit

Permalink
Hide Shortcut Guide when screenshots are taken (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzoz authored and chrdavis committed Nov 1, 2019
1 parent fd06336 commit e182f29
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/modules/shortcut_guide/overlay_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/shortcut_guide/overlay_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class D2DOverlayWindow : public D2DWindow {
~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);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/shortcut_guide/shortcut_guide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/shortcut_guide/shortcut_guide.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class OverlayWindow : public PowertoyModuleIface {

void on_held();
void on_held_press(DWORD vkCode);
void quick_hide();
void was_hidden();

virtual void destroy() override;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/shortcut_guide/target_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit e182f29

Please sign in to comment.