/ src / modules / ShortcutGuide / ShortcutGuide / shortcut_guide.h
shortcut_guide.h
  1  #pragma once
  2  #include "../interface/powertoy_module_interface.h"
  3  //#include <interface/powertoy_module_interface.h>
  4  #include "overlay_window.h"
  5  #include "native_event_waiter.h"
  6  #include "ShortcutGuideSettings.h"
  7  #include "ShortcutGuideConstants.h"
  8  
  9  #include "Generated Files/resource.h"
 10  
 11  // We support only one instance of the overlay
 12  extern class OverlayWindow* overlay_window_instance;
 13  
 14  class TargetState;
 15  
 16  enum class HideWindowType
 17  {
 18      ESC_PRESSED,
 19      WIN_RELEASED,
 20      WIN_SHORTCUT_PRESSED,
 21      THE_SHORTCUT_PRESSED,
 22      MOUSE_BUTTONUP
 23  };
 24  
 25  class OverlayWindow
 26  {
 27  public:
 28      OverlayWindow(HWND activeWindow);
 29      void ShowWindow();
 30      void CloseWindow(HideWindowType type, int mainThreadId = 0);
 31      bool IsDisabled();
 32  
 33      void on_held();
 34      void quick_hide();
 35      void was_hidden();
 36  
 37      bool overlay_visible() const;
 38      bool win_key_activation() const;
 39  
 40      bool is_disabled_app(wchar_t* exePath);
 41  
 42      void get_exe_path(HWND window, wchar_t* exePath);
 43      ~OverlayWindow();
 44      static ShortcutGuideSettings GetSettings() noexcept;
 45  private:
 46      std::wstring app_name;
 47      //contains the non localized key of the powertoy
 48      static inline std::wstring app_key = ShortcutGuideConstants::ModuleKey;
 49      std::unique_ptr<TargetState> target_state;
 50      std::unique_ptr<D2DOverlayWindow> winkey_popup;
 51      std::unique_ptr<NativeEventWaiter> event_waiter;
 52      std::vector<std::wstring> disabled_apps_array;
 53      void init_settings();
 54      void update_disabled_apps();
 55      HWND activeWindow;
 56      HHOOK keyboardHook;
 57      HHOOK mouseHook;
 58  
 59      struct OverlayOpacity
 60      {
 61          static inline PCWSTR name = L"overlay_opacity";
 62          int value;
 63          int resourceId = IDS_SETTING_DESCRIPTION_OVERLAY_OPACITY;
 64      } overlayOpacity{};
 65  
 66      struct Theme
 67      {
 68          static inline PCWSTR name = L"theme";
 69          std::wstring value;
 70          int resourceId = IDS_SETTING_DESCRIPTION_THEME;
 71          std::vector<std::pair<std::wstring, UINT>> keys_and_texts = {
 72              { L"system", IDS_SETTING_DESCRIPTION_THEME_SYSTEM },
 73              { L"light", IDS_SETTING_DESCRIPTION_THEME_LIGHT },
 74              { L"dark", IDS_SETTING_DESCRIPTION_THEME_DARK }
 75          };
 76      } theme;
 77  
 78      struct DisabledApps
 79      {
 80          static inline PCWSTR name = L"disabled_apps";
 81          std::wstring value;
 82      } disabledApps;
 83  
 84      struct ShouldReactToPressedWinKey
 85      {
 86          static inline PCWSTR name = L"use_legacy_press_win_key_behavior";
 87          bool value;
 88      } shouldReactToPressedWinKey;
 89  
 90      struct WindowsKeyPressTimeForGlobalWindowsShortcuts
 91      {
 92          static inline PCWSTR name = L"press_time";
 93          int value;
 94      } windowsKeyPressTimeForGlobalWindowsShortcuts;
 95  
 96      struct WindowsKeyPressTimeForTaskbarIconShortcuts
 97      {
 98          static inline PCWSTR name = L"press_time_for_taskbar_icon_shortcuts";
 99          int value;
100      } windowsKeyPressTimeForTaskbarIconShortcuts;
101  
102      struct OpenShortcut
103      {
104          static inline PCWSTR name = L"open_shortcutguide";
105      } openShortcut;
106  };