diff --git a/src/modules/fancyzones/dll/dllmain.cpp b/src/modules/fancyzones/dll/dllmain.cpp index c2c023884f..a5c5ea4f90 100644 --- a/src/modules/fancyzones/dll/dllmain.cpp +++ b/src/modules/fancyzones/dll/dllmain.cpp @@ -75,7 +75,7 @@ public: { if (!m_app) { - initialize_winhook_event_ids(); + InitializeWinhookEventIds(); Trace::FancyZones::EnableFancyZones(true); m_app = MakeFancyZones(reinterpret_cast(&__ImageBase), m_settings); @@ -202,7 +202,7 @@ private: static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { LowlevelKeyboardEvent event; - if (nCode == HC_ACTION) + if (nCode == HC_ACTION && wParam == WM_KEYDOWN) { event.lParam = reinterpret_cast(lParam); event.wParam = wParam; @@ -232,11 +232,7 @@ private: intptr_t FancyZonesModule::HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept { - if (data->wParam == WM_KEYDOWN) - { - return m_app.as()->OnKeyDown(data->lParam) ? 1 : 0; - } - return 0; + return m_app.as()->OnKeyDown(data->lParam); } void FancyZonesModule::HandleWinHookEvent(WinHookEvent* data) noexcept diff --git a/src/modules/fancyzones/lib/FancyZones.cpp b/src/modules/fancyzones/lib/FancyZones.cpp index ba55ea0bc2..f041958280 100644 --- a/src/modules/fancyzones/lib/FancyZones.cpp +++ b/src/modules/fancyzones/lib/FancyZones.cpp @@ -63,20 +63,20 @@ public: std::shared_lock readLock(m_lock); return m_windowMoveHandler.InMoveSize(); } - IFACEMETHODIMP_(void) - MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen) noexcept + + void MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen) noexcept { std::unique_lock writeLock(m_lock); m_windowMoveHandler.MoveSizeStart(window, monitor, ptScreen, m_zoneWindowMap); } - IFACEMETHODIMP_(void) - MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen) noexcept + + void MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen) noexcept { std::unique_lock writeLock(m_lock); m_windowMoveHandler.MoveSizeUpdate(monitor, ptScreen, m_zoneWindowMap); } - IFACEMETHODIMP_(void) - MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept + + void MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept { std::unique_lock writeLock(m_lock); m_windowMoveHandler.MoveSizeEnd(window, ptScreen, m_zoneWindowMap); @@ -117,14 +117,14 @@ public: VirtualDesktopChanged() noexcept; IFACEMETHODIMP_(void) VirtualDesktopInitialize() noexcept; - IFACEMETHODIMP_(void) - WindowCreated(HWND window) noexcept; IFACEMETHODIMP_(bool) OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept; IFACEMETHODIMP_(void) ToggleEditor() noexcept; IFACEMETHODIMP_(void) SettingsChanged() noexcept; + + void WindowCreated(HWND window) noexcept; // IZoneWindowHost IFACEMETHODIMP_(void) @@ -248,10 +248,12 @@ private: OnThreadExecutor m_dpiUnawareThread; OnThreadExecutor m_virtualDesktopTrackerThread; - static UINT WM_PRIV_VD_INIT; // Message to get back to the UI thread when FancyZones is initialized - static UINT WM_PRIV_VD_SWITCH; // Message to get back to the UI thread when virtual desktop switch occurs - static UINT WM_PRIV_VD_UPDATE; // Message to get back to the UI thread on virtual desktops update (creation/deletion) - static UINT WM_PRIV_EDITOR; // Message to get back to the UI thread when the editor exits + static UINT WM_PRIV_VD_INIT; // Scheduled when FancyZones is initialized + static UINT WM_PRIV_VD_SWITCH; // Scheduled when virtual desktop switch occurs + static UINT WM_PRIV_VD_UPDATE; // Scheduled on virtual desktops update (creation/deletion) + static UINT WM_PRIV_EDITOR; // Scheduled when the editor exits + + static UINT WM_PRIV_LOWLEVELKB; // Scheduled when we receive a key down press // Did we terminate the editor or was it closed cleanly? enum class EditorExitKind : byte @@ -265,6 +267,7 @@ UINT FancyZones::WM_PRIV_VD_INIT = RegisterWindowMessage(L"{469818a8-00fa-4069-b UINT FancyZones::WM_PRIV_VD_SWITCH = RegisterWindowMessage(L"{128c2cb0-6bdf-493e-abbe-f8705e04aa95}"); UINT FancyZones::WM_PRIV_VD_UPDATE = RegisterWindowMessage(L"{b8b72b46-f42f-4c26-9e20-29336cf2f22e}"); UINT FancyZones::WM_PRIV_EDITOR = RegisterWindowMessage(L"{87543824-7080-4e91-9d9c-0404642fc7b6}"); +UINT FancyZones::WM_PRIV_LOWLEVELKB = RegisterWindowMessage(L"{763c03a3-03d9-4cde-8d71-f0358b0b4b52}"); // IFancyZones IFACEMETHODIMP_(void) @@ -398,9 +401,10 @@ FancyZones::OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept { if (m_settings->GetSettings()->overrideSnapHotkeys) { - // Win+Left, Win+Right will cycle through Zones in the active ZoneSet Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /*inMoveSize*/); - return OnSnapHotkey(info->vkCode); + // Win+Left, Win+Right will cycle through Zones in the active ZoneSet when WM_PRIV_LOWLEVELKB's handled + PostMessageW(m_window, WM_PRIV_LOWLEVELKB, 0, info->vkCode); + return true; } } } @@ -592,7 +596,11 @@ LRESULT FancyZones::WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lpa POINT ptScreen; GetPhysicalCursorPos(&ptScreen); - if (message == WM_PRIV_VD_INIT) + if (message == WM_PRIV_LOWLEVELKB) + { + OnSnapHotkey(static_cast(lparam)); + } + else if (message == WM_PRIV_VD_INIT) { OnDisplayChange(DisplayChangeType::Initialization); } diff --git a/src/modules/fancyzones/lib/FancyZones.h b/src/modules/fancyzones/lib/FancyZones.h index ce30d3f65b..698cd2af8c 100644 --- a/src/modules/fancyzones/lib/FancyZones.h +++ b/src/modules/fancyzones/lib/FancyZones.h @@ -23,35 +23,6 @@ interface __declspec(uuid("{50D3F0F5-736E-4186-BDF4-3D6BEE150C3A}")) IFancyZones */ interface __declspec(uuid("{2CB37E8F-87E6-4AEC-B4B2-E0FDC873343F}")) IFancyZonesCallback : public IUnknown { - /** - * @returns Boolean indicating whether a move/size operation is currently active. - */ - IFACEMETHOD_(bool, InMoveSize)() = 0; - /** - * A window is being moved or resized. Track down window position and give zone layout - * hints if dragging functionality is enabled. - * - * @param window Handle of window being moved or resized. - * @param monitor Handle of monitor on which windows is moving / resizing. - * @param ptScreen Cursor coordinates. - */ - IFACEMETHOD_(void, MoveSizeStart)(HWND window, HMONITOR monitor, POINT const& ptScreen) = 0; - /** - * A window has changed location, shape, or size. Track down window position and give zone layout - * hints if dragging functionality is enabled. - * - * @param monitor Handle of monitor on which windows is moving / resizing. - * @param ptScreen Cursor coordinates. - */ - IFACEMETHOD_(void, MoveSizeUpdate)(HMONITOR monitor, POINT const& ptScreen) = 0; - /** - * The movement or resizing of a window has finished. Assign window to the zone if it - * is dropped within zone borders. - * - * @param window Handle of window being moved or resized. - * @param ptScreen Cursor coordinates where window is droped. - */ - IFACEMETHOD_(void, MoveSizeEnd)(HWND window, POINT const& ptScreen) = 0; /** * Inform FancyZones that user has switched between virtual desktops. */ @@ -61,15 +32,7 @@ interface __declspec(uuid("{2CB37E8F-87E6-4AEC-B4B2-E0FDC873343F}")) IFancyZones * * @param data Handle of window being moved or resized. */ - IFACEMETHOD_(void, HandleWinHookEvent)(const WinHookEvent* data){}; - /** - * Inform FancyZones that new window is created. FancyZones will try to assign it to the - * zone insde active zone layout (if information about last zone, in which window was located - * before being closed, is available). - * - * @param window Handle of newly created window. - */ - IFACEMETHOD_(void, WindowCreated)(HWND window) = 0; + IFACEMETHOD_(void, HandleWinHookEvent)(const WinHookEvent* data) = 0; /** * Process keyboard event. * diff --git a/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.cpp b/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.cpp index 631f80f43c..d3e59b4b4a 100644 --- a/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.cpp +++ b/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.cpp @@ -12,7 +12,7 @@ UINT WM_PRIV_WINDOWCREATED; std::once_flag init_flag; -void initialize_winhook_event_ids() +void InitializeWinhookEventIds() { std::call_once(init_flag, [&] { WM_PRIV_MOVESIZESTART = RegisterWindowMessage(L"{f48def23-df42-4c0f-a13d-3eb4a9e204d4}"); diff --git a/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.h b/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.h index 51dd46363e..3f7212fb17 100644 --- a/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.h +++ b/src/modules/fancyzones/lib/FancyZonesWinHookEventIDs.h @@ -6,4 +6,4 @@ extern UINT WM_PRIV_LOCATIONCHANGE; extern UINT WM_PRIV_NAMECHANGE; extern UINT WM_PRIV_WINDOWCREATED; -void initialize_winhook_event_ids(); +void InitializeWinhookEventIds(); diff --git a/src/modules/fancyzones/tests/UnitTests/FancyZonesSettings.Spec.cpp b/src/modules/fancyzones/tests/UnitTests/FancyZonesSettings.Spec.cpp index 3fe1835132..1e4edd9950 100644 --- a/src/modules/fancyzones/tests/UnitTests/FancyZonesSettings.Spec.cpp +++ b/src/modules/fancyzones/tests/UnitTests/FancyZonesSettings.Spec.cpp @@ -387,6 +387,8 @@ namespace FancyZonesUnitTests IFACEMETHODIMP_(void) MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept {} IFACEMETHODIMP_(void) + HandleWinHookEvent(const WinHookEvent * data) noexcept {} + IFACEMETHODIMP_(void) VirtualDesktopChanged() noexcept {} IFACEMETHODIMP_(void) VirtualDesktopInitialize() noexcept {}