Skip to content

Commit

Permalink
Win32: fix position being changed on Resize while minimized (#17559)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJul authored Nov 20, 2024
1 parent 001c939 commit a7c3ad9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Windows/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,27 @@ public void Resize(Size value, WindowResizeReason reason)
return;
}

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

windowPlacement.NormalPosition = requestedWindowRect;
windowPlacement.NormalPosition.right = windowPlacement.NormalPosition.left + windowWidth;
windowPlacement.NormalPosition.bottom = windowPlacement.NormalPosition.top + windowHeight;

windowPlacement.ShowCmd = !_shown ? ShowWindowCommand.Hide : _lastWindowState switch
{
Expand Down

0 comments on commit a7c3ad9

Please sign in to comment.