mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[FancyZones] Resize windows to match zone title bar
This commit is contained in:
@@ -295,6 +295,29 @@ ZoneSet::MoveWindowIntoZoneByIndex(HWND window, HWND workAreaWindow, ZoneIndex i
|
|||||||
MoveWindowIntoZoneByIndexSet(window, workAreaWindow, { index });
|
MoveWindowIntoZoneByIndexSet(window, workAreaWindow, { index });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ShouldSuppressMove(HWND window, RECT zoneRect, bool suppressMove)
|
||||||
|
{
|
||||||
|
if (!suppressMove)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT windowRect{};
|
||||||
|
if (GetWindowRect(window, &windowRect))
|
||||||
|
{
|
||||||
|
// Check if window is already in rect except for the zone title bar
|
||||||
|
if (zoneRect.left == windowRect.left &&
|
||||||
|
zoneRect.right == windowRect.right &&
|
||||||
|
zoneRect.bottom == windowRect.bottom &&
|
||||||
|
zoneRect.top <= windowRect.top)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
IFACEMETHODIMP_(void)
|
IFACEMETHODIMP_(void)
|
||||||
ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const ZoneIndexSet& zoneIds, bool suppressMove) noexcept
|
ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const ZoneIndexSet& zoneIds, bool suppressMove) noexcept
|
||||||
{
|
{
|
||||||
@@ -349,6 +372,7 @@ ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const Zo
|
|||||||
if (!sizeEmpty)
|
if (!sizeEmpty)
|
||||||
{
|
{
|
||||||
auto zoneTitleBar = m_zoneTitleBarByIndexSets.find(indexSet);
|
auto zoneTitleBar = m_zoneTitleBarByIndexSets.find(indexSet);
|
||||||
|
auto zoneTitleBarHeight = 0;
|
||||||
|
|
||||||
// Are we are not alone?
|
// Are we are not alone?
|
||||||
if (!m_windowsByIndexSets[indexSet].empty())
|
if (!m_windowsByIndexSets[indexSet].empty())
|
||||||
@@ -363,30 +387,36 @@ ZoneSet::MoveWindowIntoZoneByIndexSet(HWND window, HWND workAreaWindow, const Zo
|
|||||||
|
|
||||||
zoneTitleBar = m_zoneTitleBarByIndexSets.emplace(indexSet, MakeZoneTitleBar(m_config.ZoneTitleBarStyle, m_hinstance, zone)).first;
|
zoneTitleBar = m_zoneTitleBarByIndexSets.emplace(indexSet, MakeZoneTitleBar(m_config.ZoneTitleBarStyle, m_hinstance, zone)).first;
|
||||||
|
|
||||||
// Adjust the rect
|
// Get the other window
|
||||||
size.top += zoneTitleBar->second->GetHeight();
|
|
||||||
|
|
||||||
// Adjust the other window
|
|
||||||
auto hwnd = m_windowsByIndexSets[indexSet].front();
|
auto hwnd = m_windowsByIndexSets[indexSet].front();
|
||||||
|
|
||||||
if (!suppressMove)
|
// Adjust the other window
|
||||||
|
auto rect = AdjustRectForSizeWindowToRect(hwnd, size, workAreaWindow);
|
||||||
|
|
||||||
|
// Adjust the rect
|
||||||
|
if (!ShouldSuppressMove(hwnd, rect, suppressMove))
|
||||||
{
|
{
|
||||||
auto rect = AdjustRectForSizeWindowToRect(hwnd, size, workAreaWindow);
|
zoneTitleBarHeight = zoneTitleBar->second->GetHeight();
|
||||||
|
rect.top += zoneTitleBarHeight;
|
||||||
SizeWindowToRect(hwnd, rect);
|
SizeWindowToRect(hwnd, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Adjust the rect
|
// Adjust the rect
|
||||||
size.top += zoneTitleBar->second->GetHeight();
|
zoneTitleBarHeight = zoneTitleBar->second->GetHeight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!suppressMove)
|
if (!suppressMove)
|
||||||
{
|
{
|
||||||
SaveWindowSizeAndOrigin(window);
|
SaveWindowSizeAndOrigin(window);
|
||||||
|
}
|
||||||
|
|
||||||
auto rect = AdjustRectForSizeWindowToRect(window, size, workAreaWindow);
|
auto rect = AdjustRectForSizeWindowToRect(window, size, workAreaWindow);
|
||||||
|
if (!ShouldSuppressMove(window, rect, suppressMove))
|
||||||
|
{
|
||||||
|
rect.top += zoneTitleBarHeight;
|
||||||
SizeWindowToRect(window, rect);
|
SizeWindowToRect(window, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user