[FancyZones]Keep maximized state when moving new window to active monitor (#28688)

This commit is contained in:
Quyen Le Van 2023-12-18 23:04:46 +07:00 коммит произвёл GitHub
Родитель 4c3e5348f0
Коммит 3299ecfece
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -360,7 +360,7 @@ namespace MonitorUtils
if (GetMonitorInfo(monitor, &destMi))
{
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{};
::GetWindowPlacement(window, &placement);
@ -265,8 +265,15 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept
::GetWindowPlacement(window, &placement);
}
BOOL maximizeLater = false;
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.
if ((placement.showCmd != SW_SHOWMINIMIZED) &&
(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()));
}
// 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
// This fixes Issue #365
result = ::SetWindowPlacement(window, &placement);

Просмотреть файл

@ -31,7 +31,7 @@ namespace FancyZonesWindowUtils
bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) 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 RestoreWindowSize(HWND window) noexcept;
void RestoreWindowOrigin(HWND window) noexcept;