From 7870a66790ea7eea03d04c09335892590c794fe3 Mon Sep 17 00:00:00 2001 From: vldmr11080 <57061786+vldmr11080@users.noreply.github.com> Date: Mon, 25 May 2020 10:15:42 +0200 Subject: [PATCH] [FancyZones] Snap out of maximized window into zones with win + left/right arrow (#3097) * Snap out of maximized window into zones with win + left/right arrow. * Determine if there is anything to process before swallowing keypress. --- src/modules/fancyzones/lib/FancyZones.cpp | 21 ++++++++++++++++++++- src/modules/fancyzones/lib/util.cpp | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/modules/fancyzones/lib/FancyZones.cpp b/src/modules/fancyzones/lib/FancyZones.cpp index d1445bee58..5e15f3065e 100644 --- a/src/modules/fancyzones/lib/FancyZones.cpp +++ b/src/modules/fancyzones/lib/FancyZones.cpp @@ -226,6 +226,7 @@ private: bool IsNewWorkArea(GUID virtualDesktopId, HMONITOR monitor) noexcept; void OnEditorExitEvent() noexcept; + bool ProcessSnapHotkey() noexcept; std::vector> GetRawMonitorData() noexcept; std::vector GetMonitorsSorted() noexcept; @@ -397,7 +398,7 @@ FancyZones::OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept } else if ((info->vkCode == VK_RIGHT) || (info->vkCode == VK_LEFT)) { - if (m_settings->GetSettings()->overrideSnapHotkeys) + if (ProcessSnapHotkey()) { Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /*inMoveSize*/); // Win+Left, Win+Right will cycle through Zones in the active ZoneSet when WM_PRIV_LOWLEVELKB's handled @@ -948,6 +949,24 @@ void FancyZones::OnEditorExitEvent() noexcept } } +bool FancyZones::ProcessSnapHotkey() noexcept +{ + if (m_settings->GetSettings()->overrideSnapHotkeys) + { + const HMONITOR monitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTONULL); + if (monitor) + { + auto zoneWindow = m_zoneWindowMap.find(monitor); + if (zoneWindow != m_zoneWindowMap.end() && + zoneWindow->second->ActiveZoneSet()) + { + return true; + } + } + } + return false; +} + std::vector FancyZones::GetMonitorsSorted() noexcept { std::shared_lock readLock(m_lock); diff --git a/src/modules/fancyzones/lib/util.cpp b/src/modules/fancyzones/lib/util.cpp index 86371d9a54..6be3eeb20f 100644 --- a/src/modules/fancyzones/lib/util.cpp +++ b/src/modules/fancyzones/lib/util.cpp @@ -128,6 +128,13 @@ void SizeWindowToRect(HWND window, RECT rect) noexcept placement.showCmd = SW_RESTORE | SW_SHOWNA; } + // Remove maximized show command to make sure window is moved to the correct zone. + if (placement.showCmd & SW_SHOWMAXIMIZED) + { + placement.showCmd = SW_RESTORE; + placement.flags &= ~WPF_RESTORETOMAXIMIZED; + } + placement.rcNormalPosition = rect; placement.flags |= WPF_ASYNCWINDOWPLACEMENT;