From f5f8861eac976384273523be335572315a54566c Mon Sep 17 00:00:00 2001 From: Seraphima Zykova Date: Tue, 14 Jun 2022 16:45:45 +0200 Subject: [PATCH] [FancyZones] Update windows positions after changing the layout fix (#18805) * removed IWorkArea interface * split work area initialization * changed rect type in zoneset * tests upd work area tests removed obsolete, update others updated work area tests * get current vd windows * update windows positions * removed unused flag * moved update window positions to work area * check monitor * refactoring --- .../fancyzones/FancyZonesLib/FancyZones.cpp | 46 ++-- .../fancyzones/FancyZonesLib/FancyZones.h | 4 - .../FancyZonesLib/MonitorWorkAreaHandler.cpp | 19 +- .../FancyZonesLib/MonitorWorkAreaHandler.h | 16 +- .../FancyZonesLib/VirtualDesktop.cpp | 25 ++ .../fancyzones/FancyZonesLib/VirtualDesktop.h | 1 + .../FancyZonesLib/WindowMoveHandler.cpp | 43 +++- .../FancyZonesLib/WindowMoveHandler.h | 20 +- .../fancyzones/FancyZonesLib/WorkArea.cpp | 176 +++---------- .../fancyzones/FancyZonesLib/WorkArea.h | 238 ++++++++---------- .../fancyzones/FancyZonesLib/ZoneSet.cpp | 25 +- .../fancyzones/FancyZonesLib/ZoneSet.h | 6 +- .../UnitTests/WorkArea.Spec.cpp | 209 +++++---------- 13 files changed, 319 insertions(+), 509 deletions(-) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp index bc843756f0..7a0e37af58 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp @@ -152,19 +152,18 @@ protected: private: void UpdateWorkAreas() noexcept; - void UpdateWindowsPositions(bool suppressMove = false) noexcept; void CycleTabs(bool reverse) noexcept; bool OnSnapHotkeyBasedOnZoneNumber(HWND window, DWORD vkCode) noexcept; bool OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept; bool OnSnapHotkey(DWORD vkCode) noexcept; - bool ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr workArea) noexcept; + bool ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle, std::shared_ptr workArea) noexcept; void RegisterVirtualDesktopUpdates() noexcept; void UpdateHotkey(int hotkeyId, const PowerToysSettings::HotkeyObject& hotkeyObject, bool enable) noexcept; - std::pair, ZoneIndexSet> GetAppZoneHistoryInfo(HWND window, HMONITOR monitor, const std::unordered_map>& workAreaMap) noexcept; - void MoveWindowIntoZone(HWND window, winrt::com_ptr workArea, const ZoneIndexSet& zoneIndexSet) noexcept; + std::pair, ZoneIndexSet> GetAppZoneHistoryInfo(HWND window, HMONITOR monitor, const std::unordered_map>& workAreaMap) noexcept; + void MoveWindowIntoZone(HWND window, std::shared_ptr workArea, const ZoneIndexSet& zoneIndexSet) noexcept; bool MoveToAppLastZone(HWND window, HMONITOR active, HMONITOR primary) noexcept; void OnEditorExitEvent() noexcept; @@ -289,14 +288,14 @@ FancyZones::VirtualDesktopChanged() noexcept PostMessage(m_window, WM_PRIV_VD_SWITCH, 0, 0); } -std::pair, ZoneIndexSet> FancyZones::GetAppZoneHistoryInfo(HWND window, HMONITOR monitor, const std::unordered_map>& workAreaMap) noexcept +std::pair, ZoneIndexSet> FancyZones::GetAppZoneHistoryInfo(HWND window, HMONITOR monitor, const std::unordered_map>& workAreaMap) noexcept { if (monitor) { if (workAreaMap.contains(monitor)) { auto workArea = workAreaMap.at(monitor); - return std::pair, ZoneIndexSet>{ workArea, workArea->GetWindowZoneIndexes(window) }; + return std::pair, ZoneIndexSet>{ workArea, workArea->GetWindowZoneIndexes(window) }; } else { @@ -310,15 +309,15 @@ std::pair, ZoneIndexSet> FancyZones::GetAppZoneHistory auto zoneIndexSet = workArea->GetWindowZoneIndexes(window); if (!zoneIndexSet.empty()) { - return std::pair, ZoneIndexSet>{ workArea, zoneIndexSet }; + return std::pair, ZoneIndexSet>{ workArea, zoneIndexSet }; } } } - return std::pair, ZoneIndexSet>{ nullptr, {} }; + return std::pair, ZoneIndexSet>{ nullptr, {} }; } -void FancyZones::MoveWindowIntoZone(HWND window, winrt::com_ptr workArea, const ZoneIndexSet& zoneIndexSet) noexcept +void FancyZones::MoveWindowIntoZone(HWND window, std::shared_ptr workArea, const ZoneIndexSet& zoneIndexSet) noexcept { if (workArea) { @@ -338,7 +337,7 @@ bool FancyZones::MoveToAppLastZone(HWND window, HMONITOR active, HMONITOR primar } // Search application history on currently active monitor. - std::pair, ZoneIndexSet> appZoneHistoryInfo = GetAppZoneHistoryInfo(window, active, workAreaMap); + std::pair, ZoneIndexSet> appZoneHistoryInfo = GetAppZoneHistoryInfo(window, active, workAreaMap); // No application history on currently active monitor if (appZoneHistoryInfo.second.empty()) @@ -791,7 +790,8 @@ void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept { if (FancyZonesSettings::settings().displayChange_moveWindows) { - UpdateWindowsPositions(); + auto activeWorkAreas = m_workAreaHandler.GetWorkAreasByDesktopId(VirtualDesktop::instance().GetCurrentVirtualDesktopId()); + m_windowMoveHandler.UpdateWindowsPositions(activeWorkAreas); } } } @@ -883,19 +883,6 @@ void FancyZones::UpdateWorkAreas() noexcept } } -void FancyZones::UpdateWindowsPositions(bool suppressMove) noexcept -{ - for (const auto [window, desktopId] : VirtualDesktop::instance().GetWindowsRelatedToDesktops()) - { - auto zoneIndexSet = FancyZonesWindowProperties::RetrieveZoneIndexProperty(window); - auto workArea = m_workAreaHandler.GetWorkArea(window, desktopId); - if (workArea) - { - m_windowMoveHandler.MoveWindowIntoZoneByIndexSet(window, zoneIndexSet, workArea, suppressMove); - } - } -} - void FancyZones::CycleTabs(bool reverse) noexcept { auto window = GetForegroundWindow(); @@ -994,7 +981,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept // If that didn't work, extract zones from all other monitors and target one of them std::vector zoneRects; - std::vector>> zoneRectsInfo; + std::vector>> zoneRectsInfo; RECT currentMonitorRect{ .top = 0, .bottom = -1 }; for (const auto& [monitor, monitorRect] : allMonitors) @@ -1119,7 +1106,7 @@ bool FancyZones::OnSnapHotkey(DWORD vkCode) noexcept return false; } -bool FancyZones::ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr workArea) noexcept +bool FancyZones::ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle, std::shared_ptr workArea) noexcept { // Check whether Alt is used in the shortcut key combination if (GetAsyncKeyState(VK_MENU) & 0x8000) @@ -1223,8 +1210,11 @@ void FancyZones::UpdateZoneSets() noexcept workArea->UpdateActiveZoneSet(); } - auto moveWindows = FancyZonesSettings::settings().zoneSetChange_moveWindows; - UpdateWindowsPositions(!moveWindows); + if (FancyZonesSettings::settings().zoneSetChange_moveWindows) + { + auto activeWorkAreas = m_workAreaHandler.GetWorkAreasByDesktopId(VirtualDesktop::instance().GetCurrentVirtualDesktopId()); + m_windowMoveHandler.UpdateWindowsPositions(activeWorkAreas); + } } bool FancyZones::ShouldProcessSnapHotkey(DWORD vkCode) noexcept diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.h b/src/modules/fancyzones/FancyZonesLib/FancyZones.h index 6f78116315..5cbcfd4df6 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.h +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.h @@ -4,10 +4,6 @@ #include -interface IWorkArea; -interface IFancyZonesSettings; -interface IZoneSet; - struct WinHookEvent; interface __declspec(uuid("{50D3F0F5-736E-4186-BDF4-3D6BEE150C3A}")) IFancyZones : public IUnknown diff --git a/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp b/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp index 465c2d788e..ec97221794 100644 --- a/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp +++ b/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp @@ -6,10 +6,10 @@ #include -winrt::com_ptr MonitorWorkAreaHandler::GetWorkArea(const GUID& desktopId, HMONITOR monitor) +std::shared_ptr MonitorWorkAreaHandler::GetWorkArea(const GUID& desktopId, HMONITOR monitor) { auto desktopIt = workAreaMap.find(desktopId); - if (desktopIt != std::end(workAreaMap)) + if (desktopIt != workAreaMap.end()) { auto& perDesktopData = desktopIt->second; auto monitorIt = perDesktopData.find(monitor); @@ -21,7 +21,7 @@ winrt::com_ptr MonitorWorkAreaHandler::GetWorkArea(const GUID& deskto return nullptr; } -winrt::com_ptr MonitorWorkAreaHandler::GetWorkAreaFromCursor(const GUID& desktopId) +std::shared_ptr MonitorWorkAreaHandler::GetWorkAreaFromCursor(const GUID& desktopId) { auto allMonitorsWorkArea = GetWorkArea(desktopId, NULL); if (allMonitorsWorkArea) @@ -42,7 +42,7 @@ winrt::com_ptr MonitorWorkAreaHandler::GetWorkAreaFromCursor(const GU } } -winrt::com_ptr MonitorWorkAreaHandler::GetWorkArea(HWND window, const GUID& desktopId) +std::shared_ptr MonitorWorkAreaHandler::GetWorkArea(HWND window, const GUID& desktopId) { auto allMonitorsWorkArea = GetWorkArea(desktopId, NULL); if (allMonitorsWorkArea) @@ -58,19 +58,20 @@ winrt::com_ptr MonitorWorkAreaHandler::GetWorkArea(HWND window, const } } -const std::unordered_map>& MonitorWorkAreaHandler::GetWorkAreasByDesktopId(const GUID& desktopId) +const std::unordered_map>& MonitorWorkAreaHandler::GetWorkAreasByDesktopId(const GUID& desktopId) { if (workAreaMap.contains(desktopId)) { return workAreaMap[desktopId]; } - static const std::unordered_map> empty; + + static const std::unordered_map> empty{}; return empty; } -std::vector> MonitorWorkAreaHandler::GetAllWorkAreas() +std::vector> MonitorWorkAreaHandler::GetAllWorkAreas() { - std::vector> workAreas{}; + std::vector> workAreas{}; for (const auto& [desktopId, perDesktopData] : workAreaMap) { std::transform(std::begin(perDesktopData), @@ -81,7 +82,7 @@ std::vector> MonitorWorkAreaHandler::GetAllWorkAreas() return workAreas; } -void MonitorWorkAreaHandler::AddWorkArea(const GUID& desktopId, HMONITOR monitor, winrt::com_ptr& workArea) +void MonitorWorkAreaHandler::AddWorkArea(const GUID& desktopId, HMONITOR monitor, std::shared_ptr& workArea) { if (!workAreaMap.contains(desktopId)) { diff --git a/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.h b/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.h index 1a0b1029dd..191b82d7b3 100644 --- a/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.h +++ b/src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.h @@ -2,7 +2,7 @@ #include "GuidUtils.h" -interface IWorkArea; +class WorkArea; struct ZoneColors; enum struct OverlappingZonesAlgorithm; @@ -18,7 +18,7 @@ public: * @returns Object representing single work area, interface to all actions available on work area * (e.g. moving windows through zone layout specified for that work area). */ - winrt::com_ptr GetWorkArea(const GUID& desktopId, HMONITOR monitor); + std::shared_ptr GetWorkArea(const GUID& desktopId, HMONITOR monitor); /** * Get work area based on virtual desktop id and the current cursor position. @@ -28,7 +28,7 @@ public: * @returns Object representing single work area, interface to all actions available on work area * (e.g. moving windows through zone layout specified for that work area). */ - winrt::com_ptr GetWorkAreaFromCursor(const GUID& desktopId); + std::shared_ptr GetWorkAreaFromCursor(const GUID& desktopId); /** * Get work area on which specified window is located. @@ -39,7 +39,7 @@ public: * @returns Object representing single work area, interface to all actions available on work area * (e.g. moving windows through zone layout specified for that work area). */ - winrt::com_ptr GetWorkArea(HWND window, const GUID& desktopId); + std::shared_ptr GetWorkArea(HWND window, const GUID& desktopId); /** * Get map of all work areas on single virtual desktop. Key in the map is monitor handle, while value @@ -49,12 +49,12 @@ public: * * @returns Map containing pairs of monitor and work area for that monitor (within same virtual desktop). */ - const std::unordered_map>& GetWorkAreasByDesktopId(const GUID& desktopId); + const std::unordered_map>& GetWorkAreasByDesktopId(const GUID& desktopId); /** * @returns All registered work areas. */ - std::vector> GetAllWorkAreas(); + std::vector> GetAllWorkAreas(); /** * Register new work area. @@ -63,7 +63,7 @@ public: * @param[in] monitor Monitor handle. * @param[in] workAra Object representing single work area. */ - void AddWorkArea(const GUID& desktopId, HMONITOR monitor, winrt::com_ptr& workArea); + void AddWorkArea(const GUID& desktopId, HMONITOR monitor, std::shared_ptr& workArea); /** * Check if work area is already registered. @@ -89,5 +89,5 @@ public: private: // Work area is uniquely defined by monitor and virtual desktop id. - std::unordered_map>> workAreaMap; + std::unordered_map>> workAreaMap; }; diff --git a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp index 7c224a5044..67bf726d2b 100644 --- a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp +++ b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.cpp @@ -240,6 +240,31 @@ std::vector> VirtualDesktop::GetWindowsRelatedToDesktops() return result; } +std::vector VirtualDesktop::GetWindowsFromCurrentDesktop() const +{ + using result_t = std::vector; + result_t windows; + + auto callback = [](HWND window, LPARAM data) -> BOOL { + result_t& result = *reinterpret_cast(data); + result.push_back(window); + return TRUE; + }; + EnumWindows(callback, reinterpret_cast(&windows)); + + std::vector result; + for (auto window : windows) + { + BOOL isOnCurrentVD{}; + if (m_vdManager->IsWindowOnCurrentVirtualDesktop(window, &isOnCurrentVD) == S_OK && isOnCurrentVD) + { + result.push_back(window); + } + } + + return result; +} + GUID VirtualDesktop::GetCurrentVirtualDesktopId() const noexcept { return m_currentVirtualDesktopId; diff --git a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h index f7f483ead5..069e1883ea 100644 --- a/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h +++ b/src/modules/fancyzones/FancyZonesLib/VirtualDesktop.h @@ -15,6 +15,7 @@ public: std::optional GetDesktopId(HWND window) const; std::optional GetDesktopIdByTopLevelWindows() const; std::vector> GetWindowsRelatedToDesktops() const; + std::vector GetWindowsFromCurrentDesktop() const; // registry std::optional GetCurrentVirtualDesktopIdFromRegistry() const; diff --git a/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp b/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp index 862baeeb60..a2bf160a2b 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.cpp @@ -59,7 +59,7 @@ WindowMoveHandler::WindowMoveHandler(const std::function& keyUpdateCallb { } -void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept +void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept { if (!FancyZonesWindowProcessing::IsProcessable(window)) { @@ -104,7 +104,7 @@ void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const m_draggedWindowWorkArea->MoveSizeEnter(m_draggedWindow); if (FancyZonesSettings::settings().showZonesOnAllMonitors) { - for (auto [keyMonitor, workArea] : workAreaMap) + for (const auto& [keyMonitor, workArea] : workAreaMap) { // Skip calling ShowZonesOverlay for iter->second (m_draggedWindowWorkArea) since it // was already called in MoveSizeEnter @@ -120,7 +120,7 @@ void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const { ResetWindowTransparency(); m_draggedWindowWorkArea = nullptr; - for (auto [keyMonitor, workArea] : workAreaMap) + for (const auto& [keyMonitor, workArea] : workAreaMap) { if (workArea) { @@ -132,8 +132,7 @@ void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const auto workArea = workAreaMap.find(monitor); if (workArea != workAreaMap.end()) { - const auto workAreaPtr = workArea->second; - const auto zoneSet = workAreaPtr->ZoneSet(); + const auto zoneSet = workArea->second->ZoneSet(); if (zoneSet) { zoneSet->DismissWindow(window); @@ -141,7 +140,7 @@ void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const } } -void WindowMoveHandler::MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept +void WindowMoveHandler::MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept { if (!m_inDragging) { @@ -208,7 +207,7 @@ void WindowMoveHandler::MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen, } } -void WindowMoveHandler::MoveSizeEnd(HWND window, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept +void WindowMoveHandler::MoveSizeEnd(HWND window, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept { if (window != m_draggedWindow) { @@ -292,29 +291,49 @@ void WindowMoveHandler::MoveSizeEnd(HWND window, POINT const& ptScreen, const st } } -void WindowMoveHandler::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, winrt::com_ptr workArea, bool suppressMove) noexcept +void WindowMoveHandler::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, std::shared_ptr workArea) noexcept { if (window != m_draggedWindow) { - workArea->MoveWindowIntoZoneByIndexSet(window, indexSet, suppressMove); + workArea->MoveWindowIntoZoneByIndexSet(window, indexSet); } } -bool WindowMoveHandler::MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr workArea) noexcept +bool WindowMoveHandler::MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle, std::shared_ptr workArea) noexcept { return workArea && workArea->MoveWindowIntoZoneByDirectionAndIndex(window, vkCode, cycle); } -bool WindowMoveHandler::MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr workArea) noexcept +bool WindowMoveHandler::MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle, std::shared_ptr workArea) noexcept { return workArea && workArea->MoveWindowIntoZoneByDirectionAndPosition(window, vkCode, cycle); } -bool WindowMoveHandler::ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode, winrt::com_ptr workArea) noexcept +bool WindowMoveHandler::ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode, std::shared_ptr workArea) noexcept { return workArea && workArea->ExtendWindowByDirectionAndPosition(window, vkCode); } +void WindowMoveHandler::UpdateWindowsPositions(const std::unordered_map>& activeWorkAreas) noexcept +{ + for (const auto& window : VirtualDesktop::instance().GetWindowsFromCurrentDesktop()) + { + auto zoneIndexSet = FancyZonesWindowProperties::RetrieveZoneIndexProperty(window); + if (zoneIndexSet.size() == 0) + { + continue; + } + + for (const auto& [monitor, workArea] : activeWorkAreas) + { + if (MonitorFromWindow(window, MONITOR_DEFAULTTONULL) == monitor) + { + workArea->MoveWindowIntoZoneByIndexSet(window, zoneIndexSet); + } + } + } +} + void WindowMoveHandler::WarnIfElevationIsRequired(HWND window) noexcept { using namespace notifications; diff --git a/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.h b/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.h index c3b182578f..67c4f9c41c 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.h +++ b/src/modules/fancyzones/FancyZonesLib/WindowMoveHandler.h @@ -7,22 +7,24 @@ #include interface IFancyZonesSettings; -interface IWorkArea; +class WorkArea; class WindowMoveHandler { public: WindowMoveHandler(const std::function& keyUpdateCallback); - void MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept; - void MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept; - void MoveSizeEnd(HWND window, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept; + void MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept; + void MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept; + void MoveSizeEnd(HWND window, POINT const& ptScreen, const std::unordered_map>& workAreaMap) noexcept; - void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, winrt::com_ptr workArea, bool suppressMove = false) noexcept; - bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr workArea) noexcept; - bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr workArea) noexcept; - bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode, winrt::com_ptr workArea) noexcept; + void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, std::shared_ptr workArea) noexcept; + bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle, std::shared_ptr workArea) noexcept; + bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle, std::shared_ptr workArea) noexcept; + bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode, std::shared_ptr workArea) noexcept; + void UpdateWindowsPositions(const std::unordered_map>& activeWorkAreas) noexcept; + inline void OnMouseDown() noexcept { m_mouseState = !m_mouseState; @@ -67,7 +69,7 @@ private: bool m_inDragging{}; // Whether or not a move/size operation is currently active HWND m_draggedWindow{}; // The window that is being moved/sized MoveSizeWindowInfo m_draggedWindowInfo; // MoveSizeWindowInfo of the window at the moment when dragging started - winrt::com_ptr m_draggedWindowWorkArea; // "Active" WorkArea, where the move/size is happening. Will update as drag moves between monitors. + std::shared_ptr m_draggedWindowWorkArea; // "Active" WorkArea, where the move/size is happening. Will update as drag moves between monitors. bool m_dragEnabled{}; // True if we should be showing zone hints while dragging WindowTransparencyProperties m_windowTransparencyProperties; diff --git a/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp b/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp index ce500b5ec4..a6c87a392d 100644 --- a/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WorkArea.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "FancyZonesData/AppliedLayouts.h" #include "FancyZonesData/AppZoneHistory.h" @@ -12,6 +13,8 @@ #include "trace.h" #include "on_thread_executor.h" #include "Settings.h" +#include +#include #include #include @@ -28,8 +31,6 @@ namespace NonLocalizable using namespace FancyZonesUtils; -struct WorkArea; - namespace { // The reason for using this class is the need to call ShowWindow(window, SW_SHOWNORMAL); on each @@ -103,71 +104,6 @@ namespace WindowPool windowPool; } -struct WorkArea : public winrt::implements -{ -public: - WorkArea(HINSTANCE hinstance); - ~WorkArea(); - - bool Init(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId); - - IFACEMETHODIMP MoveSizeEnter(HWND window) noexcept; - IFACEMETHODIMP MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) noexcept; - IFACEMETHODIMP MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept; - IFACEMETHODIMP_(void) - MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept; - IFACEMETHODIMP_(void) - MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool suppressMove = false) noexcept; - IFACEMETHODIMP_(bool) - MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept; - IFACEMETHODIMP_(bool) - MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept; - IFACEMETHODIMP_(bool) - ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept; - IFACEMETHODIMP_(FancyZonesDataTypes::DeviceIdData) - UniqueId() const noexcept { return { m_uniqueId }; } - IFACEMETHODIMP_(void) - SaveWindowProcessToZoneIndex(HWND window) noexcept; - IFACEMETHODIMP_(IZoneSet*) - ZoneSet() const noexcept { return m_zoneSet.get(); } - IFACEMETHODIMP_(ZoneIndexSet) - GetWindowZoneIndexes(HWND window) const noexcept; - IFACEMETHODIMP_(void) - ShowZonesOverlay() noexcept; - IFACEMETHODIMP_(void) - HideZonesOverlay() noexcept; - IFACEMETHODIMP_(void) - UpdateActiveZoneSet() noexcept; - IFACEMETHODIMP_(void) - CycleTabs(HWND window, bool reverse) noexcept; - IFACEMETHODIMP_(void) - ClearSelectedZones() noexcept; - IFACEMETHODIMP_(void) - FlashZones() noexcept; - -protected: - static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept; - -private: - void InitializeZoneSets(const FancyZonesDataTypes::DeviceIdData& parentUniqueId) noexcept; - void CalculateZoneSet(OverlappingZonesAlgorithm overlappingAlgorithm) noexcept; - void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept; - LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept; - ZoneIndexSet ZonesFromPoint(POINT pt) noexcept; - void SetAsTopmostWindow() noexcept; - - HMONITOR m_monitor{}; - FancyZonesDataTypes::DeviceIdData m_uniqueId; - HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area. - HWND m_windowMoveSize{}; - winrt::com_ptr m_zoneSet; - ZoneIndexSet m_initialHighlightZone; - ZoneIndexSet m_highlightZone; - WPARAM m_keyLast{}; - size_t m_keyCycle{}; - std::unique_ptr m_zonesOverlay; -}; - WorkArea::WorkArea(HINSTANCE hinstance) { WNDCLASSEXW wcex{}; @@ -184,30 +120,12 @@ WorkArea::~WorkArea() windowPool.FreeZonesOverlayWindow(m_window); } -bool WorkArea::Init(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId) +bool WorkArea::Init(HINSTANCE hinstance, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId) { - Rect workAreaRect; - m_monitor = monitor; - if (monitor) - { - MONITORINFO mi{}; - mi.cbSize = sizeof(mi); - if (!GetMonitorInfoW(monitor, &mi)) - { - Logger::error(L"GetMonitorInfo failed on work area initialization"); - return false; - } - workAreaRect = Rect(mi.rcWork); - } - else - { - workAreaRect = GetAllMonitorsCombinedRect<&MONITORINFO::rcWork>(); - } - m_uniqueId = uniqueId; InitializeZoneSets(parentUniqueId); - m_window = windowPool.NewZonesOverlayWindow(workAreaRect, hinstance, this); + m_window = windowPool.NewZonesOverlayWindow(m_workAreaRect, hinstance, this); if (!m_window) { @@ -220,7 +138,7 @@ bool WorkArea::Init(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataT return true; } -IFACEMETHODIMP WorkArea::MoveSizeEnter(HWND window) noexcept +HRESULT WorkArea::MoveSizeEnter(HWND window) noexcept { m_windowMoveSize = window; m_highlightZone = {}; @@ -230,7 +148,7 @@ IFACEMETHODIMP WorkArea::MoveSizeEnter(HWND window) noexcept return S_OK; } -IFACEMETHODIMP WorkArea::MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) noexcept +HRESULT WorkArea::MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) noexcept { bool redraw = false; POINT ptClient = ptScreen; @@ -274,7 +192,7 @@ IFACEMETHODIMP WorkArea::MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, return S_OK; } -IFACEMETHODIMP WorkArea::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept +HRESULT WorkArea::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept { if (m_windowMoveSize != window) { @@ -299,23 +217,20 @@ IFACEMETHODIMP WorkArea::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcep return S_OK; } -IFACEMETHODIMP_(void) -WorkArea::MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept +void WorkArea::MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept { MoveWindowIntoZoneByIndexSet(window, { index }); } -IFACEMETHODIMP_(void) -WorkArea::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool suppressMove) noexcept +void WorkArea::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet) noexcept { if (m_zoneSet) { - m_zoneSet->MoveWindowIntoZoneByIndexSet(window, m_window, indexSet, suppressMove); + m_zoneSet->MoveWindowIntoZoneByIndexSet(window, m_window, indexSet); } } -IFACEMETHODIMP_(bool) -WorkArea::MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept +bool WorkArea::MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept { if (m_zoneSet) { @@ -331,8 +246,7 @@ WorkArea::MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool return false; } -IFACEMETHODIMP_(bool) -WorkArea::MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept +bool WorkArea::MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept { if (m_zoneSet) { @@ -345,8 +259,7 @@ WorkArea::MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bo return false; } -IFACEMETHODIMP_(bool) -WorkArea::ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept +bool WorkArea::ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept { if (m_zoneSet) { @@ -359,8 +272,7 @@ WorkArea::ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept return false; } -IFACEMETHODIMP_(void) -WorkArea::SaveWindowProcessToZoneIndex(HWND window) noexcept +void WorkArea::SaveWindowProcessToZoneIndex(HWND window) noexcept { if (m_zoneSet) { @@ -378,8 +290,7 @@ WorkArea::SaveWindowProcessToZoneIndex(HWND window) noexcept } } -IFACEMETHODIMP_(ZoneIndexSet) -WorkArea::GetWindowZoneIndexes(HWND window) const noexcept +ZoneIndexSet WorkArea::GetWindowZoneIndexes(HWND window) const noexcept { if (m_zoneSet) { @@ -401,8 +312,7 @@ WorkArea::GetWindowZoneIndexes(HWND window) const noexcept return {}; } -IFACEMETHODIMP_(void) -WorkArea::ShowZonesOverlay() noexcept +void WorkArea::ShowZonesOverlay() noexcept { if (m_window) { @@ -412,8 +322,7 @@ WorkArea::ShowZonesOverlay() noexcept } } -IFACEMETHODIMP_(void) -WorkArea::HideZonesOverlay() noexcept +void WorkArea::HideZonesOverlay() noexcept { if (m_window) { @@ -424,8 +333,7 @@ WorkArea::HideZonesOverlay() noexcept } } -IFACEMETHODIMP_(void) -WorkArea::UpdateActiveZoneSet() noexcept +void WorkArea::UpdateActiveZoneSet() noexcept { bool isLayoutAlreadyApplied = AppliedLayouts::instance().IsLayoutApplied(m_uniqueId); if (!isLayoutAlreadyApplied) @@ -441,8 +349,7 @@ WorkArea::UpdateActiveZoneSet() noexcept } } -IFACEMETHODIMP_(void) -WorkArea::CycleTabs(HWND window, bool reverse) noexcept +void WorkArea::CycleTabs(HWND window, bool reverse) noexcept { if (m_zoneSet) { @@ -450,8 +357,7 @@ WorkArea::CycleTabs(HWND window, bool reverse) noexcept } } -IFACEMETHODIMP_(void) -WorkArea::ClearSelectedZones() noexcept +void WorkArea::ClearSelectedZones() noexcept { if (m_highlightZone.size()) { @@ -460,8 +366,7 @@ WorkArea::ClearSelectedZones() noexcept } } -IFACEMETHODIMP_(void) -WorkArea::FlashZones() noexcept +void WorkArea::FlashZones() noexcept { if (m_window) { @@ -513,31 +418,11 @@ void WorkArea::CalculateZoneSet(OverlappingZonesAlgorithm overlappingAlgorithm) appliedLayout->sensitivityRadius, overlappingAlgorithm)); - RECT workArea; - if (m_monitor) - { - MONITORINFO monitorInfo{}; - monitorInfo.cbSize = sizeof(monitorInfo); - if (GetMonitorInfoW(m_monitor, &monitorInfo)) - { - workArea = monitorInfo.rcWork; - } - else - { - Logger::error(L"CalculateZoneSet: GetMonitorInfo failed"); - return; - } - } - else - { - workArea = GetAllMonitorsCombinedRect<&MONITORINFO::rcWork>(); - } - bool showSpacing = appliedLayout->showSpacing; int spacing = showSpacing ? appliedLayout->spacing : 0; int zoneCount = appliedLayout->zoneCount; - zoneSet->CalculateZones(workArea, zoneCount, spacing); + zoneSet->CalculateZones(m_workAreaRect, zoneCount, spacing); UpdateActiveZoneSet(zoneSet.get()); } @@ -595,6 +480,11 @@ void WorkArea::SetAsTopmostWindow() noexcept SetWindowPos(m_window, windowInsertAfter, 0, 0, 0, 0, flags); } +void WorkArea::LogInitializationError() +{ + Logger::error(L"Unable to get monitor info, {}", get_last_error_or_default(GetLastError())); +} + #pragma endregion LRESULT CALLBACK WorkArea::s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept @@ -611,13 +501,3 @@ LRESULT CALLBACK WorkArea::s_WndProc(HWND window, UINT message, WPARAM wparam, L DefWindowProc(window, message, wparam, lparam); } -winrt::com_ptr MakeWorkArea(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId) noexcept -{ - auto self = winrt::make_self(hinstance); - if (self->Init(hinstance, monitor, uniqueId, parentUniqueId)) - { - return self; - } - - return nullptr; -} diff --git a/src/modules/fancyzones/FancyZonesLib/WorkArea.h b/src/modules/fancyzones/FancyZonesLib/WorkArea.h index 1ecc9fc30c..f52d6182d7 100644 --- a/src/modules/fancyzones/FancyZonesLib/WorkArea.h +++ b/src/modules/fancyzones/FancyZonesLib/WorkArea.h @@ -1,139 +1,111 @@ #pragma once -#include "FancyZones.h" -#include "FancyZonesLib/ZoneSet.h" -#include "FancyZonesLib/FancyZonesDataTypes.h" -/** - * Class representing single work area, which is defined by monitor and virtual desktop. - */ -interface __declspec(uuid("{7F017528-8110-4FB3-BE41-F472969C2560}")) IWorkArea : public IUnknown +#include +#include +#include + +class ZonesOverlay; + +class WorkArea { - /** - * 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. - */ - IFACEMETHOD(MoveSizeEnter)(HWND window) = 0; +public: + WorkArea(HINSTANCE hinstance); + ~WorkArea(); - /** - * A window has changed location, shape, or size. Track down window position and give zone layout - * hints if dragging functionality is enabled. - * - * @param ptScreen Cursor coordinates. - * @param dragEnabled Boolean indicating is giving hints about active zone layout enabled. - * Hints are given while dragging window while holding SHIFT key. - * @param selectManyZones When this parameter is true, the set of highlighted zones is computed - * by finding the minimum bounding rectangle of the zone(s) from which the - * user started dragging and the zone(s) above which the user is hovering - * at the moment this function is called. Otherwise, highlight only the zone(s) - * above which the user is currently hovering. - */ - IFACEMETHOD(MoveSizeUpdate)(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) = 0; - /** - * The movement or resizing of a window has finished. Assign window to the zone of it - * is dropped within zone borders. - * - * @param window Handle of window being moved or resized. - * @param ptScreen Cursor coordinates where window is dropped. - */ - IFACEMETHOD(MoveSizeEnd)(HWND window, POINT const& ptScreen) = 0; - /** - * Assign window to the zone based on zone index inside zone layout. - * - * @param window Handle of window which should be assigned to zone. - * @param index Zone index within zone layout. - */ - IFACEMETHOD_(void, MoveWindowIntoZoneByIndex)(HWND window, ZoneIndex index) = 0; - /** - * Assign window to the zones based on the set of zone indices inside zone layout. - * - * @param window Handle of window which should be assigned to zone. - * @param indexSet The set of zone indices within zone layout. - * @param suppressMove Whether we should just update the records or move window to the zone. - */ - IFACEMETHOD_(void, MoveWindowIntoZoneByIndexSet)(HWND window, const ZoneIndexSet& indexSet, bool suppressMove = false) = 0; - /** - * Assign window to the zone based on direction (using WIN + LEFT/RIGHT arrow), based on zone index numbers, - * not their on-screen position. - * - * @param window Handle of window which should be assigned to zone. - * @param vkCode Pressed arrow key. - * @param cycle Whether we should move window to the first zone if we reached last zone in layout. - * - * @returns Boolean which is always true if cycle argument is set, otherwise indicating if there is more - * zones left in the zone layout in which window can move. - */ - IFACEMETHOD_(bool, MoveWindowIntoZoneByDirectionAndIndex)(HWND window, DWORD vkCode, bool cycle) = 0; - /** - * Assign window to the zone based on direction (using WIN + LEFT/RIGHT/UP/DOWN arrow), based on - * their on-screen position. - * - * @param window Handle of window which should be assigned to zone. - * @param vkCode Pressed arrow key. - * @param cycle Whether we should move window to the first zone if we reached last zone in layout. - * - * @returns Boolean which is always true if cycle argument is set, otherwise indicating if there is more - * zones left in the zone layout in which window can move. - */ - IFACEMETHOD_(bool, MoveWindowIntoZoneByDirectionAndPosition)(HWND window, DWORD vkCode, bool cycle) = 0; - /** - * Extend or shrink the window to an adjacent zone based on direction (using CTRL+WIN+ALT + LEFT/RIGHT/UP/DOWN arrow), based on - * their on-screen position. - * - * @param window Handle of window which should be assigned to zone. - * @param vkCode Pressed arrow key. - * - * @returns Boolean indicating whether the window was rezoned. False could be returned when there are no more - * zones available in the given direction. - */ - IFACEMETHOD_(bool, ExtendWindowByDirectionAndPosition)(HWND window, DWORD vkCode) = 0; - /** - * Save information about zone in which window was assigned, when closing the window. - * Used once we open same window again to assign it to its previous zone. - * - * @param window Window handle. - */ - IFACEMETHOD_(void, SaveWindowProcessToZoneIndex)(HWND window) = 0; - /** - * @returns Unique work area identifier. Format: __ - */ - IFACEMETHOD_(FancyZonesDataTypes::DeviceIdData, UniqueId)() const = 0; - /** - * @returns Active zone layout for this work area. - */ - IFACEMETHOD_(IZoneSet*, ZoneSet)() const = 0; - /* - * @returns Zone index of the window - */ - IFACEMETHOD_(ZoneIndexSet, GetWindowZoneIndexes)(HWND window) const = 0; - /** - * Show a drawing of the zones in the work area. - */ - IFACEMETHOD_(void, ShowZonesOverlay)() = 0; - /** - * Hide the drawing of the zones in the work area. - */ - IFACEMETHOD_(void, HideZonesOverlay)() = 0; - /** - * Update currently active zone layout for this work area. - */ - IFACEMETHOD_(void, UpdateActiveZoneSet)() = 0; - /** - * Cycle through tabs in the zone that the window is in. - * - * @param window Handle of window which is cycled from (the current tab). - * @param reverse Whether to cycle in reverse order (to the previous tab) or to move to the next tab. - */ - IFACEMETHOD_(void, CycleTabs)(HWND window, bool reverse) = 0; - /** - * Clear the selected zones when this WorkArea loses focus. - */ - IFACEMETHOD_(void, ClearSelectedZones)() = 0; - /* - * Display the layout on the screen and then hide it. - */ - IFACEMETHOD_(void, FlashZones)() = 0; +public: + bool Init(HINSTANCE hinstance, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId); + inline bool InitWorkAreaRect(HMONITOR monitor) + { + m_monitor = monitor; + +#if defined(UNIT_TESTS) + m_workAreaRect = FancyZonesUtils::Rect({ 0, 0, 1920, 1080 }); + return true; +#endif + + if (monitor) + { + MONITORINFO mi{}; + mi.cbSize = sizeof(mi); + if (!GetMonitorInfoW(monitor, &mi)) + { + return false; + } + + m_workAreaRect = FancyZonesUtils::Rect(mi.rcWork); + } + else + { + m_workAreaRect = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFO::rcWork>(); + } + + return true; + } + + FancyZonesDataTypes::DeviceIdData UniqueId() const noexcept { return { m_uniqueId }; } + IZoneSet* ZoneSet() const noexcept { return m_zoneSet.get(); } + + ZoneIndexSet GetWindowZoneIndexes(HWND window) const noexcept; + + HRESULT MoveSizeEnter(HWND window) noexcept; + HRESULT MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) noexcept; + HRESULT MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept; + void MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept; + void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet) noexcept; + bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept; + bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept; + bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept; + void SaveWindowProcessToZoneIndex(HWND window) noexcept; + + void UpdateActiveZoneSet() noexcept; + + void ShowZonesOverlay() noexcept; + void HideZonesOverlay() noexcept; + void FlashZones() noexcept; + void ClearSelectedZones() noexcept; + + void CycleTabs(HWND window, bool reverse) noexcept; + + void LogInitializationError(); + +protected: + static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept; + +private: + void InitializeZoneSets(const FancyZonesDataTypes::DeviceIdData& parentUniqueId) noexcept; + void CalculateZoneSet(OverlappingZonesAlgorithm overlappingAlgorithm) noexcept; + void UpdateActiveZoneSet(_In_opt_ IZoneSet* zoneSet) noexcept; + LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept; + ZoneIndexSet ZonesFromPoint(POINT pt) noexcept; + void SetAsTopmostWindow() noexcept; + + HMONITOR m_monitor{}; + FancyZonesUtils::Rect m_workAreaRect{}; + + FancyZonesDataTypes::DeviceIdData m_uniqueId; + HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area. + HWND m_windowMoveSize{}; + winrt::com_ptr m_zoneSet; + ZoneIndexSet m_initialHighlightZone; + ZoneIndexSet m_highlightZone; + WPARAM m_keyLast{}; + size_t m_keyCycle{}; + std::unique_ptr m_zonesOverlay; }; -winrt::com_ptr MakeWorkArea(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId) noexcept; +inline std::shared_ptr MakeWorkArea(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::DeviceIdData& uniqueId, const FancyZonesDataTypes::DeviceIdData& parentUniqueId) noexcept +{ + auto self = std::make_shared(hinstance); + if (!self->InitWorkAreaRect(monitor)) + { + self->LogInitializationError(); + return nullptr; + } + + if (!self->Init(hinstance, uniqueId, parentUniqueId)) + { + return nullptr; + } + + return self; +} diff --git a/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp b/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp index 071b42a755..0f8c2ab040 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp +++ b/src/modules/fancyzones/FancyZonesLib/ZoneSet.cpp @@ -40,7 +40,7 @@ public: IFACEMETHODIMP_(void) MoveWindowIntoZoneByIndex(HWND window, HWND workAreaWindow, ZoneIndex index) noexcept; IFACEMETHODIMP_(void) - MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const ZoneIndexSet& indexSet, bool suppressMove = false) noexcept; + MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const ZoneIndexSet& indexSet) noexcept; IFACEMETHODIMP_(bool) MoveWindowIntoZoneByDirectionAndIndex(HWND window, HWND workAreaWindow, DWORD vkCode, bool cycle) noexcept; IFACEMETHODIMP_(bool) @@ -54,7 +54,7 @@ public: IFACEMETHODIMP_(void) CycleTabs(HWND window, bool reverse) noexcept; IFACEMETHODIMP_(bool) - CalculateZones(RECT workArea, int zoneCount, int spacing) noexcept; + CalculateZones(FancyZonesUtils::Rect workArea, int zoneCount, int spacing) noexcept; IFACEMETHODIMP_(bool) IsZoneEmpty(ZoneIndex zoneIndex) const noexcept; IFACEMETHODIMP_(ZoneIndexSet) GetCombinedZoneRange(const ZoneIndexSet& initialZones, const ZoneIndexSet& finalZones) const noexcept; @@ -188,7 +188,7 @@ ZoneSet::MoveWindowIntoZoneByIndex(HWND window, HWND workAreaWindow, ZoneIndex i } IFACEMETHODIMP_(void) -ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const ZoneIndexSet& zoneIds, bool suppressMove) noexcept +ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const ZoneIndexSet& zoneIds) noexcept { if (m_zones.empty()) { @@ -239,17 +239,14 @@ ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const Zo if (!sizeEmpty) { - if (!suppressMove) + FancyZonesWindowUtils::SaveWindowSizeAndOrigin(window); + + auto rect = FancyZonesWindowUtils::AdjustRectForSizeWindowToRect(window, size, workAreaWindow); + FancyZonesWindowUtils::SizeWindowToRect(window, rect); + + if (FancyZonesSettings::settings().disableRoundCorners) { - FancyZonesWindowUtils::SaveWindowSizeAndOrigin(window); - - auto rect = FancyZonesWindowUtils::AdjustRectForSizeWindowToRect(window, size, workAreaWindow); - FancyZonesWindowUtils::SizeWindowToRect(window, rect); - - if (FancyZonesSettings::settings().disableRoundCorners) - { - FancyZonesWindowUtils::DisableRoundCorners(window); - } + FancyZonesWindowUtils::DisableRoundCorners(window); } FancyZonesWindowProperties::StampZoneIndexProperty(window, indexSet); @@ -569,7 +566,7 @@ void ZoneSet::InsertTabIntoZone(HWND window, std::optional tabSortKeyWit } IFACEMETHODIMP_(bool) -ZoneSet::CalculateZones(RECT workAreaRect, int zoneCount, int spacing) noexcept +ZoneSet::CalculateZones(FancyZonesUtils::Rect workAreaRect, int zoneCount, int spacing) noexcept { Rect workArea(workAreaRect); //invalid work area diff --git a/src/modules/fancyzones/FancyZonesLib/ZoneSet.h b/src/modules/fancyzones/FancyZonesLib/ZoneSet.h index 794b3f78f6..b6fc6bf1ec 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZoneSet.h +++ b/src/modules/fancyzones/FancyZonesLib/ZoneSet.h @@ -2,6 +2,7 @@ #include #include "Settings.h" +#include "util.h" namespace FancyZonesDataTypes { @@ -55,9 +56,8 @@ interface __declspec(uuid("{E4839EB7-669D-49CF-84A9-71A2DFD851A3}")) IZoneSet : * @param workAreaWindow The m_window of a WorkArea, it's a hidden window representing the * current monitor desktop work area. * @param indexSet The set of zone indices within zone layout. - * @param suppressMove Whether we should just update the records or move window to the zone. */ - IFACEMETHOD_(void, MoveWindowIntoZoneByIndexSet)(HWND window, HWND workAreaWindow, const ZoneIndexSet& indexSet, bool suppressMove = false) = 0; + IFACEMETHOD_(void, MoveWindowIntoZoneByIndexSet)(HWND window, HWND workAreaWindow, const ZoneIndexSet& indexSet) = 0; /** * Assign window to the zone based on direction (using WIN + LEFT/RIGHT arrow), based on zone index numbers, * not their on-screen position. @@ -135,7 +135,7 @@ interface __declspec(uuid("{E4839EB7-669D-49CF-84A9-71A2DFD851A3}")) IZoneSet : * * @returns Boolean indicating if calculation was successful. */ - IFACEMETHOD_(bool, CalculateZones)(RECT workAreaRect, int zoneCount, int spacing) = 0; + IFACEMETHOD_(bool, CalculateZones)(FancyZonesUtils::Rect workAreaRect, int zoneCount, int spacing) = 0; /** * Check if the zone with the specified index is empty. Returns true if the zone with passed zoneIndex does not exist. * diff --git a/src/modules/fancyzones/FancyZonesTests/UnitTests/WorkArea.Spec.cpp b/src/modules/fancyzones/FancyZonesTests/UnitTests/WorkArea.Spec.cpp index 936a7a7d42..16bd7c3690 100644 --- a/src/modules/fancyzones/FancyZonesTests/UnitTests/WorkArea.Spec.cpp +++ b/src/modules/fancyzones/FancyZonesTests/UnitTests/WorkArea.Spec.cpp @@ -23,39 +23,14 @@ namespace FancyZonesUnitTests TEST_CLASS (WorkAreaCreationUnitTests) { - FancyZonesDataTypes::DeviceIdData m_parentUniqueId; FancyZonesDataTypes::DeviceIdData m_uniqueId; - - HINSTANCE m_hInst{}; - HMONITOR m_monitor{}; - MONITORINFOEX m_monitorInfo{}; - GUID m_virtualDesktopGuid{}; - - void testWorkArea(winrt::com_ptr workArea) - { - const std::wstring expectedWorkArea = std::to_wstring(m_monitorInfo.rcMonitor.right) + L"_" + std::to_wstring(m_monitorInfo.rcMonitor.bottom); - - Assert::IsNotNull(workArea.get()); - Assert::IsTrue(m_uniqueId == workArea->UniqueId()); - } + FancyZonesDataTypes::DeviceIdData m_emptyUniqueId; TEST_METHOD_INITIALIZE(Init) { - m_hInst = (HINSTANCE)GetModuleHandleW(nullptr); - - m_monitor = MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY); - m_monitorInfo.cbSize = sizeof(m_monitorInfo); - Assert::AreNotEqual(0, GetMonitorInfoW(m_monitor, &m_monitorInfo)); - - m_parentUniqueId.deviceName = L"DELA026#5&10a58c63&0&UID16777488"; - CLSIDFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC57}", &m_parentUniqueId.virtualDesktopId); - m_uniqueId.deviceName = L"DELA026#5&10a58c63&0&UID16777488"; - CLSIDFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}", &m_uniqueId.virtualDesktopId); - - auto guid = Helpers::StringToGuid(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}"); - Assert::IsTrue(guid.has_value()); - m_virtualDesktopGuid = *guid; + auto res = CLSIDFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}", &m_uniqueId.virtualDesktopId); + Assert::IsTrue(SUCCEEDED(res)); AppZoneHistory::instance().LoadData(); AppliedLayouts::instance().LoadData(); @@ -67,124 +42,76 @@ namespace FancyZonesUnitTests std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName()); } - TEST_METHOD (CreateWorkArea) - { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); - testWorkArea(workArea); + TEST_METHOD (CreateWorkArea) + { + auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId); + Assert::IsFalse(workArea == nullptr); + Assert::IsTrue(m_uniqueId == workArea->UniqueId()); - auto* zoneSet{ workArea->ZoneSet() }; - Assert::IsNotNull(zoneSet); - Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); - Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); - } + auto* zoneSet{ workArea->ZoneSet() }; + Assert::IsNotNull(zoneSet); + Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); + Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); + } - TEST_METHOD (CreateWorkAreaNoHinst) - { - auto workArea = MakeWorkArea({}, m_monitor, m_uniqueId, {}); - testWorkArea(workArea); + TEST_METHOD (CreateCombinedWorkArea) + { + auto workArea = MakeWorkArea({}, {}, m_uniqueId, m_emptyUniqueId); + Assert::IsFalse(workArea == nullptr); + Assert::IsTrue(m_uniqueId == workArea->UniqueId()); - auto* zoneSet{ workArea->ZoneSet() }; - Assert::IsNotNull(zoneSet); - Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); - Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); - } - - TEST_METHOD (CreateWorkAreaNoHinstFlashZones) - { - auto workArea = MakeWorkArea({}, m_monitor, m_uniqueId, {}); - testWorkArea(workArea); - - auto* zoneSet{ workArea->ZoneSet() }; - Assert::IsNotNull(zoneSet); - Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); - Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); - } - - TEST_METHOD (CreateWorkAreaNoMonitor) - { - auto workArea = MakeWorkArea(m_hInst, {}, m_uniqueId, {}); - testWorkArea(workArea); - } - - TEST_METHOD (CreateWorkAreaNoDeviceId) - { - // Generate unique id without device id - FancyZonesDataTypes::DeviceIdData uniqueIdData; - uniqueIdData.virtualDesktopId = m_virtualDesktopGuid; - - auto workArea = MakeWorkArea(m_hInst, m_monitor, uniqueIdData, {}); - - const std::wstring expectedWorkArea = std::to_wstring(m_monitorInfo.rcMonitor.right) + L"_" + std::to_wstring(m_monitorInfo.rcMonitor.bottom); - const FancyZonesDataTypes::DeviceIdData expectedUniqueId{ L"FallbackDevice", m_virtualDesktopGuid }; - - Assert::IsNotNull(workArea.get()); - Assert::IsTrue(expectedUniqueId == workArea->UniqueId()); - - auto* zoneSet{ workArea->ZoneSet() }; - Assert::IsNotNull(zoneSet); - Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); - Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); - } - - TEST_METHOD (CreateWorkAreaNoDesktopId) - { - // Generate unique id without virtual desktop id - FancyZonesDataTypes::DeviceIdData uniqueId; - uniqueId.deviceName = FancyZonesUtils::TrimDeviceId(m_deviceId); - - auto workArea = MakeWorkArea(m_hInst, m_monitor, uniqueId, {}); - - const std::wstring expectedWorkArea = std::to_wstring(m_monitorInfo.rcMonitor.right) + L"_" + std::to_wstring(m_monitorInfo.rcMonitor.bottom); - Assert::IsNotNull(workArea.get()); - - auto* zoneSet{ workArea->ZoneSet() }; - Assert::IsNotNull(zoneSet); - Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); - Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); - } + auto* zoneSet{ workArea->ZoneSet() }; + Assert::IsNotNull(zoneSet); + Assert::AreEqual(static_cast(zoneSet->LayoutType()), static_cast(FancyZonesDataTypes::ZoneSetLayoutType::PriorityGrid)); + Assert::AreEqual(zoneSet->GetZones().size(), static_cast(3)); + } TEST_METHOD (CreateWorkAreaClonedFromParent) { using namespace FancyZonesDataTypes; - const ZoneSetLayoutType type = ZoneSetLayoutType::PriorityGrid; - const int spacing = 10; - const int zoneCount = 5; - const auto customSetGuid = Helpers::CreateGuidString(); + FancyZonesDataTypes::DeviceIdData parentUniqueId; + parentUniqueId.deviceName = L"DELA026#5&10a58c63&0&UID16777488"; + parentUniqueId.virtualDesktopId = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC57}").value(); - auto parentWorkArea = MakeWorkArea(m_hInst, m_monitor, m_parentUniqueId, {}); - - // newWorkArea = false - workArea won't be cloned from parent - auto actualWorkArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + Layout layout{ + .uuid = FancyZonesUtils::GuidFromString(L"{61FA9FC0-26A6-4B37-A834-491C148DFC58}").value(), + .type = ZoneSetLayoutType::Rows, + .showSpacing = true, + .spacing = 10, + .zoneCount = 10, + .sensitivityRadius = 20, + }; + + auto parentWorkArea = MakeWorkArea({}, Mocks::Monitor(), parentUniqueId, m_emptyUniqueId); + AppliedLayouts::instance().ApplyLayout(parentUniqueId, layout); + + auto actualWorkArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, parentUniqueId); Assert::IsNotNull(actualWorkArea->ZoneSet()); Assert::IsTrue(AppliedLayouts::instance().GetAppliedLayoutMap().contains(m_uniqueId)); - auto currentDeviceInfo = AppliedLayouts::instance().GetAppliedLayoutMap().at(m_uniqueId); - // default values - Assert::AreEqual(true, currentDeviceInfo.showSpacing); - Assert::AreEqual(3, currentDeviceInfo.zoneCount); - Assert::AreEqual(16, currentDeviceInfo.spacing); - Assert::AreEqual(static_cast(ZoneSetLayoutType::PriorityGrid), static_cast(currentDeviceInfo.type)); + auto actualLayout = AppliedLayouts::instance().GetAppliedLayoutMap().at(m_uniqueId); + + Assert::AreEqual(static_cast(layout.type), static_cast(actualLayout.type)); + Assert::AreEqual(FancyZonesUtils::GuidToString(layout.uuid).value(), FancyZonesUtils::GuidToString(actualLayout.uuid).value()); + Assert::AreEqual(layout.sensitivityRadius, actualLayout.sensitivityRadius); + Assert::AreEqual(layout.showSpacing, actualLayout.showSpacing); + Assert::AreEqual(layout.spacing, actualLayout.spacing); + Assert::AreEqual(layout.zoneCount, actualLayout.zoneCount); } }; TEST_CLASS (WorkAreaUnitTests) { FancyZonesDataTypes::DeviceIdData m_uniqueId; + FancyZonesDataTypes::DeviceIdData m_parentUniqueId; // default empty HINSTANCE m_hInst{}; HMONITOR m_monitor{}; - MONITORINFO m_monitorInfo{}; TEST_METHOD_INITIALIZE(Init) { - m_hInst = (HINSTANCE)GetModuleHandleW(nullptr); - - m_monitor = MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY); - m_monitorInfo.cbSize = sizeof(m_monitorInfo); - Assert::AreNotEqual(0, GetMonitorInfoW(m_monitor, &m_monitorInfo)); - m_uniqueId.deviceName = L"DELA026#5&10a58c63&0&UID16777488"; CLSIDFromString(L"{39B25DD2-130D-4B5D-8851-4791D66B1539}", &m_uniqueId.virtualDesktopId); @@ -198,10 +125,10 @@ namespace FancyZonesUnitTests std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName()); } - public: + public: TEST_METHOD (MoveSizeEnter) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto expected = S_OK; const auto actual = workArea->MoveSizeEnter(Mocks::Window()); @@ -211,7 +138,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeEnterTwice) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto expected = S_OK; @@ -223,7 +150,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeUpdate) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto expected = S_OK; const auto actual = workArea->MoveSizeUpdate(POINT{ 0, 0 }, true, false); @@ -233,7 +160,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeUpdatePointNegativeCoordinates) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto expected = S_OK; const auto actual = workArea->MoveSizeUpdate(POINT{ -10, -10 }, true, false); @@ -243,17 +170,17 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeUpdatePointBigCoordinates) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto expected = S_OK; - const auto actual = workArea->MoveSizeUpdate(POINT{ m_monitorInfo.rcMonitor.right + 1, m_monitorInfo.rcMonitor.bottom + 1 }, true, false); + const auto actual = workArea->MoveSizeUpdate(POINT{ LONG_MAX, LONG_MAX }, true, false); Assert::AreEqual(expected, actual); } TEST_METHOD (MoveSizeEnd) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto window = Mocks::Window(); workArea->MoveSizeEnter(window); @@ -270,7 +197,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeEndWindowNotAdded) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto window = Mocks::Window(); workArea->MoveSizeEnter(window); @@ -286,7 +213,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeEndDifferentWindows) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto window = Mocks::Window(); workArea->MoveSizeEnter(window); @@ -299,7 +226,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeEndWindowNotSet) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto expected = E_INVALIDARG; const auto actual = workArea->MoveSizeEnd(Mocks::Window(), POINT{ 0, 0 }); @@ -309,7 +236,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveSizeEndInvalidPoint) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); const auto window = Mocks::Window(); workArea->MoveSizeEnter(window); @@ -326,7 +253,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveWindowIntoZoneByIndex) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); workArea->MoveWindowIntoZoneByIndex(Mocks::Window(), 0); @@ -336,7 +263,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveWindowIntoZoneByDirectionAndIndex) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); const auto window = Mocks::WindowCreate(m_hInst); @@ -351,7 +278,7 @@ namespace FancyZonesUnitTests TEST_METHOD (MoveWindowIntoZoneByDirectionManyTimes) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); const auto window = Mocks::WindowCreate(m_hInst); @@ -368,7 +295,7 @@ namespace FancyZonesUnitTests TEST_METHOD (SaveWindowProcessToZoneIndexNullptrWindow) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); workArea->SaveWindowProcessToZoneIndex(nullptr); @@ -379,7 +306,7 @@ namespace FancyZonesUnitTests TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAdded) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); auto window = Mocks::WindowCreate(m_hInst); @@ -393,7 +320,7 @@ namespace FancyZonesUnitTests TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAddedWithFilledAppZoneHistory) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); const auto window = Mocks::WindowCreate(m_hInst); @@ -420,7 +347,7 @@ namespace FancyZonesUnitTests TEST_METHOD (SaveWindowProcessToZoneIndexWindowAdded) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); auto window = Mocks::WindowCreate(m_hInst); @@ -449,7 +376,7 @@ namespace FancyZonesUnitTests TEST_METHOD (WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt) { - auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, {}); + auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId); Assert::IsNotNull(workArea->ZoneSet()); auto window = Mocks::WindowCreate(m_hInst);