Skip to content

Commit 8f5d506

Browse files
MrJulmaxkatz6
authored andcommitted
Win32: fix position being changed on Resize while minimized (#17559)
1 parent fe28a3f commit 8f5d506

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/Windows/Avalonia.Win32/WindowImpl.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,27 @@ public void Resize(Size value, WindowResizeReason reason)
581581
return;
582582
}
583583

584-
var position = Position;
585-
requestedWindowRect.left = position.X;
586-
requestedWindowRect.top = position.Y;
587-
requestedWindowRect.right = position.X + windowWidth;
588-
requestedWindowRect.bottom = position.Y + windowHeight;
584+
// If the window is minimized, don't change the restore position, because this.Position is currently
585+
// out of screen with values similar to -32000,-32000. Windows considers such a position invalid on restore
586+
// and instead moves the window back to 0,0.
587+
if (windowPlacement.ShowCmd == ShowWindowCommand.ShowMinimized)
588+
{
589+
// The window is minimized but will be restored to maximized: don't change our normal size,
590+
// or it will incorrectly be set to the maximized size.
591+
if ((windowPlacement.Flags & WindowPlacementFlags.RestoreToMaximized) != 0)
592+
{
593+
return;
594+
}
595+
}
596+
else
597+
{
598+
var position = Position;
599+
windowPlacement.NormalPosition.left = position.X;
600+
windowPlacement.NormalPosition.top = position.Y;
601+
}
589602

590-
windowPlacement.NormalPosition = requestedWindowRect;
603+
windowPlacement.NormalPosition.right = windowPlacement.NormalPosition.left + windowWidth;
604+
windowPlacement.NormalPosition.bottom = windowPlacement.NormalPosition.top + windowHeight;
591605

592606
windowPlacement.ShowCmd = !_shown ? ShowWindowCommand.Hide : _lastWindowState switch
593607
{

0 commit comments

Comments
 (0)