Skip to content

Commit

Permalink
Fancy zones preserve size of non-resizable windows (#1974)
Browse files Browse the repository at this point in the history
* fancy zones preserve size of non-resizable windows

* Changed the method of determining if window is resizable

* minor merge fix
  • Loading branch information
PrzemyslawTusinski committed Apr 8, 2020
1 parent fa51560 commit 17022d5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/modules/fancyzones/lib/Zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept
{
return;
}

// Take care of 1px border
RECT zoneRect = m_zoneRect;
RECT newWindowRect = m_zoneRect;

RECT windowRect{};
::GetWindowRect(window, &windowRect);
Expand All @@ -82,29 +82,35 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept
const auto left_margin = frameRect.left - windowRect.left;
const auto right_margin = frameRect.right - windowRect.right;
const auto bottom_margin = frameRect.bottom - windowRect.bottom;
zoneRect.left -= left_margin;
zoneRect.right -= right_margin;
zoneRect.bottom -= bottom_margin;
newWindowRect.left -= left_margin;
newWindowRect.right -= right_margin;
newWindowRect.bottom -= bottom_margin;
}

// Map to screen coords
MapWindowRect(zoneWindow, nullptr, &zoneRect);
MapWindowRect(zoneWindow, nullptr, &newWindowRect);

MONITORINFO mi{sizeof(mi)};
MONITORINFO mi{ sizeof(mi) };
if (GetMonitorInfoW(MonitorFromWindow(zoneWindow, MONITOR_DEFAULTTONEAREST), &mi))
{
const auto taskbar_left_size = std::abs(mi.rcMonitor.left - mi.rcWork.left);
const auto taskbar_top_size = std::abs(mi.rcMonitor.top - mi.rcWork.top);
OffsetRect(&zoneRect, -taskbar_left_size, -taskbar_top_size);
OffsetRect(&newWindowRect, -taskbar_left_size, -taskbar_top_size);
if (accountForUnawareness)
{
zoneRect.left = max(mi.rcMonitor.left, zoneRect.left);
zoneRect.right = min(mi.rcMonitor.right - taskbar_left_size, zoneRect.right);
zoneRect.top = max(mi.rcMonitor.top, zoneRect.top);
zoneRect.bottom = min(mi.rcMonitor.bottom - taskbar_top_size, zoneRect.bottom);
newWindowRect.left = max(mi.rcMonitor.left, newWindowRect.left);
newWindowRect.right = min(mi.rcMonitor.right - taskbar_left_size, newWindowRect.right);
newWindowRect.top = max(mi.rcMonitor.top, newWindowRect.top);
newWindowRect.bottom = min(mi.rcMonitor.bottom - taskbar_top_size, newWindowRect.bottom);
}
}

if ((::GetWindowLong(window, GWL_STYLE) & WS_SIZEBOX) == 0)
{
newWindowRect.right = newWindowRect.left + (windowRect.right - windowRect.left);
newWindowRect.bottom = newWindowRect.top + (windowRect.bottom - windowRect.top);
}

WINDOWPLACEMENT placement{};
::GetWindowPlacement(window, &placement);

Expand All @@ -121,7 +127,7 @@ void Zone::SizeWindowToZone(HWND window, HWND zoneWindow) noexcept
placement.showCmd = SW_RESTORE | SW_SHOWNA;
}

placement.rcNormalPosition = zoneRect;
placement.rcNormalPosition = newWindowRect;
placement.flags |= WPF_ASYNCWINDOWPLACEMENT;

::SetWindowPlacement(window, &placement);
Expand Down

0 comments on commit 17022d5

Please sign in to comment.