mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[FancyZones] Fix updating window position after switching virtual desktop (#22072)
This commit is contained in:
@@ -714,11 +714,8 @@ void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept
|
|||||||
|
|
||||||
UpdateWorkAreas();
|
UpdateWorkAreas();
|
||||||
|
|
||||||
if (FancyZonesSettings::settings().displayChange_moveWindows)
|
auto activeWorkAreas = m_workAreaHandler.GetWorkAreasByDesktopId(VirtualDesktop::instance().GetCurrentVirtualDesktopId());
|
||||||
{
|
m_windowMoveHandler.AssignWindowsToZones(activeWorkAreas, FancyZonesSettings::settings().displayChange_moveWindows && changeType != DisplayChangeType::VirtualDesktop);
|
||||||
auto activeWorkAreas = m_workAreaHandler.GetWorkAreasByDesktopId(VirtualDesktop::instance().GetCurrentVirtualDesktopId());
|
|
||||||
m_windowMoveHandler.UpdateWindowsPositions(activeWorkAreas);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZones::AddWorkArea(HMONITOR monitor, const FancyZonesDataTypes::WorkAreaId& id) noexcept
|
void FancyZones::AddWorkArea(HMONITOR monitor, const FancyZonesDataTypes::WorkAreaId& id) noexcept
|
||||||
@@ -1115,7 +1112,7 @@ void FancyZones::UpdateZoneSets() noexcept
|
|||||||
if (FancyZonesSettings::settings().zoneSetChange_moveWindows)
|
if (FancyZonesSettings::settings().zoneSetChange_moveWindows)
|
||||||
{
|
{
|
||||||
auto activeWorkAreas = m_workAreaHandler.GetWorkAreasByDesktopId(VirtualDesktop::instance().GetCurrentVirtualDesktopId());
|
auto activeWorkAreas = m_workAreaHandler.GetWorkAreasByDesktopId(VirtualDesktop::instance().GetCurrentVirtualDesktopId());
|
||||||
m_windowMoveHandler.UpdateWindowsPositions(activeWorkAreas);
|
m_windowMoveHandler.AssignWindowsToZones(activeWorkAreas, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ bool WindowMoveHandler::ExtendWindowByDirectionAndPosition(HWND window, DWORD vk
|
|||||||
return workArea && workArea->ExtendWindowByDirectionAndPosition(window, vkCode);
|
return workArea && workArea->ExtendWindowByDirectionAndPosition(window, vkCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowMoveHandler::UpdateWindowsPositions(const std::unordered_map<HMONITOR, std::shared_ptr<WorkArea>>& activeWorkAreas) noexcept
|
void WindowMoveHandler::AssignWindowsToZones(const std::unordered_map<HMONITOR, std::shared_ptr<WorkArea>>& activeWorkAreas, bool updatePositions) noexcept
|
||||||
{
|
{
|
||||||
for (const auto& window : VirtualDesktop::instance().GetWindowsFromCurrentDesktop())
|
for (const auto& window : VirtualDesktop::instance().GetWindowsFromCurrentDesktop())
|
||||||
{
|
{
|
||||||
@@ -346,7 +346,7 @@ void WindowMoveHandler::UpdateWindowsPositions(const std::unordered_map<HMONITOR
|
|||||||
auto monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
|
auto monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
|
||||||
if (monitor && activeWorkAreas.contains(monitor))
|
if (monitor && activeWorkAreas.contains(monitor))
|
||||||
{
|
{
|
||||||
activeWorkAreas.at(monitor)->MoveWindowIntoZoneByIndexSet(window, zoneIndexSet);
|
activeWorkAreas.at(monitor)->MoveWindowIntoZoneByIndexSet(window, zoneIndexSet, updatePositions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public:
|
|||||||
bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle, std::shared_ptr<WorkArea> workArea) noexcept;
|
bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle, std::shared_ptr<WorkArea> workArea) noexcept;
|
||||||
bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode, std::shared_ptr<WorkArea> workArea) noexcept;
|
bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode, std::shared_ptr<WorkArea> workArea) noexcept;
|
||||||
|
|
||||||
void UpdateWindowsPositions(const std::unordered_map<HMONITOR, std::shared_ptr<WorkArea>>& activeWorkAreas) noexcept;
|
void AssignWindowsToZones(const std::unordered_map<HMONITOR, std::shared_ptr<WorkArea>>& activeWorkAreas, bool updatePositions) noexcept;
|
||||||
|
|
||||||
inline void OnMouseDown() noexcept
|
inline void OnMouseDown() noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ void WorkArea::MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept
|
|||||||
MoveWindowIntoZoneByIndexSet(window, { index });
|
MoveWindowIntoZoneByIndexSet(window, { index });
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorkArea::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet) noexcept
|
void WorkArea::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool updatePosition /* = true*/) noexcept
|
||||||
{
|
{
|
||||||
if (!m_layout || !m_layoutWindows || m_layout->Zones().empty() || indexSet.empty())
|
if (!m_layout || !m_layoutWindows || m_layout->Zones().empty() || indexSet.empty())
|
||||||
{
|
{
|
||||||
@@ -209,10 +209,14 @@ void WorkArea::MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& ind
|
|||||||
}
|
}
|
||||||
|
|
||||||
FancyZonesWindowUtils::SaveWindowSizeAndOrigin(window);
|
FancyZonesWindowUtils::SaveWindowSizeAndOrigin(window);
|
||||||
auto rect = m_layout->GetCombinedZonesRect(indexSet);
|
|
||||||
auto adjustedRect = FancyZonesWindowUtils::AdjustRectForSizeWindowToRect(window, rect, m_window);
|
|
||||||
FancyZonesWindowUtils::SizeWindowToRect(window, adjustedRect);
|
|
||||||
|
|
||||||
|
if (updatePosition)
|
||||||
|
{
|
||||||
|
auto rect = m_layout->GetCombinedZonesRect(indexSet);
|
||||||
|
auto adjustedRect = FancyZonesWindowUtils::AdjustRectForSizeWindowToRect(window, rect, m_window);
|
||||||
|
FancyZonesWindowUtils::SizeWindowToRect(window, adjustedRect);
|
||||||
|
}
|
||||||
|
|
||||||
m_layoutWindows->Assign(window, indexSet);
|
m_layoutWindows->Assign(window, indexSet);
|
||||||
FancyZonesWindowProperties::StampZoneIndexProperty(window, indexSet);
|
FancyZonesWindowProperties::StampZoneIndexProperty(window, indexSet);
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
HRESULT MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) noexcept;
|
HRESULT MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool selectManyZones) noexcept;
|
||||||
HRESULT MoveSizeEnd(HWND window) noexcept;
|
HRESULT MoveSizeEnd(HWND window) noexcept;
|
||||||
void MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept;
|
void MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept;
|
||||||
void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet) noexcept;
|
void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool updatePosition = true) noexcept;
|
||||||
bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept;
|
bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept;
|
||||||
bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept;
|
bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept;
|
||||||
bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept;
|
bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept;
|
||||||
|
|||||||
Reference in New Issue
Block a user