mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[FancyZones]Keep maximized state when moving new window to active monitor (#28688)
This commit is contained in:
@@ -360,7 +360,7 @@ namespace MonitorUtils
|
|||||||
if (GetMonitorInfo(monitor, &destMi))
|
if (GetMonitorInfo(monitor, &destMi))
|
||||||
{
|
{
|
||||||
RECT newPosition = FitOnScreen(placement.rcNormalPosition, originMi.rcWork, destMi.rcWork);
|
RECT newPosition = FitOnScreen(placement.rcNormalPosition, originMi.rcWork, destMi.rcWork);
|
||||||
FancyZonesWindowUtils::SizeWindowToRect(window, newPosition);
|
FancyZonesWindowUtils::SizeWindowToRect(window, newPosition, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ void FancyZonesWindowUtils::SwitchToWindow(HWND window) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept
|
void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect, BOOL snapZone) noexcept
|
||||||
{
|
{
|
||||||
WINDOWPLACEMENT placement{};
|
WINDOWPLACEMENT placement{};
|
||||||
::GetWindowPlacement(window, &placement);
|
::GetWindowPlacement(window, &placement);
|
||||||
@@ -265,8 +265,15 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept
|
|||||||
::GetWindowPlacement(window, &placement);
|
::GetWindowPlacement(window, &placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL maximizeLater = false;
|
||||||
if (IsWindowVisible(window))
|
if (IsWindowVisible(window))
|
||||||
{
|
{
|
||||||
|
// If is not snap zone then need keep maximize state (move to active monitor)
|
||||||
|
if (!snapZone && placement.showCmd == SW_SHOWMAXIMIZED)
|
||||||
|
{
|
||||||
|
maximizeLater = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Do not restore minimized windows. We change their placement though so they restore to the correct zone.
|
// Do not restore minimized windows. We change their placement though so they restore to the correct zone.
|
||||||
if ((placement.showCmd != SW_SHOWMINIMIZED) &&
|
if ((placement.showCmd != SW_SHOWMINIMIZED) &&
|
||||||
(placement.showCmd != SW_MINIMIZE))
|
(placement.showCmd != SW_MINIMIZE))
|
||||||
@@ -294,6 +301,12 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept
|
|||||||
Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError()));
|
Logger::error(L"SetWindowPlacement failed, {}", get_last_error_or_default(GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure window is moved to the correct monitor before maximize.
|
||||||
|
if (maximizeLater)
|
||||||
|
{
|
||||||
|
placement.showCmd = SW_SHOWMAXIMIZED;
|
||||||
|
}
|
||||||
|
|
||||||
// Do it again, allowing Windows to resize the window and set correct scaling
|
// Do it again, allowing Windows to resize the window and set correct scaling
|
||||||
// This fixes Issue #365
|
// This fixes Issue #365
|
||||||
result = ::SetWindowPlacement(window, &placement);
|
result = ::SetWindowPlacement(window, &placement);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace FancyZonesWindowUtils
|
|||||||
bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept;
|
bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept;
|
||||||
|
|
||||||
void SwitchToWindow(HWND window) noexcept;
|
void SwitchToWindow(HWND window) noexcept;
|
||||||
void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
|
void SizeWindowToRect(HWND window, RECT rect, BOOL snapZone = true) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
|
||||||
void SaveWindowSizeAndOrigin(HWND window) noexcept;
|
void SaveWindowSizeAndOrigin(HWND window) noexcept;
|
||||||
void RestoreWindowSize(HWND window) noexcept;
|
void RestoreWindowSize(HWND window) noexcept;
|
||||||
void RestoreWindowOrigin(HWND window) noexcept;
|
void RestoreWindowOrigin(HWND window) noexcept;
|
||||||
|
|||||||
Reference in New Issue
Block a user