Skip to content

Commit 4defeb2

Browse files
Fix resize when maximised
Warn and ignore when a fullscreen window is resized
1 parent 7633f87 commit 4defeb2

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,58 @@ public enum SizeCommand
105105

106106
public enum ShowWindowCommand
107107
{
108+
/// <summary>
109+
/// Hides the window and activates another window.
110+
/// </summary>
108111
Hide = 0,
112+
/// <summary>
113+
/// Activates and displays a window. If the window is minimized, maximized, or arranged, the system restores it to its original
114+
/// size and position. An application should specify this flag when displaying the window for the first time.
115+
/// </summary>
109116
Normal = 1,
117+
/// <summary>
118+
/// Activates the window and displays it as a minimized window.
119+
/// </summary>
110120
ShowMinimized = 2,
121+
/// <summary>
122+
/// Activates the window and displays it as a maximized window.
123+
/// </summary>
111124
Maximize = 3,
112-
ShowMaximized = 3,
125+
/// <inheritdoc cref="Maximize"/>
126+
ShowMaximized = Maximize,
127+
/// <summary>
128+
/// Displays a window in its most recent size and position. This value is similar to <see cref="Normal"/>, except that the window is not activated.
129+
/// </summary>
113130
ShowNoActivate = 4,
131+
/// <summary>
132+
/// Activates the window and displays it in its current size and position.
133+
/// </summary>
114134
Show = 5,
135+
/// <summary>
136+
/// Minimizes the specified window and activates the next top-level window in the Z order.
137+
/// </summary>
115138
Minimize = 6,
139+
/// <summary>
140+
/// Displays the window as a minimized window. This value is similar to <see cref="ShowMinimized"/>, except the window is not activated.
141+
/// </summary>
116142
ShowMinNoActive = 7,
143+
/// <summary>
144+
/// Displays the window in its current size and position. This value is similar to <see cref="Show"/>, except that the window is not activated.
145+
/// </summary>
117146
ShowNA = 8,
147+
/// <summary>
148+
/// Activates and displays the window. If the window is minimized, maximized, or arranged, the system restores it to its original size and position.
149+
/// An application should specify this flag when restoring a minimized window.
150+
/// </summary>
118151
Restore = 9,
152+
/// <summary>
153+
/// Sets the show state based on the <see cref="ShowWindowCommand"/> value specified in the STARTUPINFO structure passed to the CreateProcess function
154+
/// by the program that started the application.
155+
/// </summary>
119156
ShowDefault = 10,
157+
/// <summary>
158+
/// Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
159+
/// </summary>
120160
ForceMinimize = 11
121161
}
122162

src/Windows/Avalonia.Win32/WindowImpl.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using Avalonia.Threading;
3131
using static Avalonia.Controls.Platform.IWin32OptionsTopLevelImpl;
3232
using static Avalonia.Controls.Platform.Win32SpecificOptions;
33+
using Avalonia.Logging;
3334

3435
namespace Avalonia.Win32
3536
{
@@ -572,6 +573,14 @@ public void Resize(Size value, WindowResizeReason reason)
572573
return;
573574
}
574575

576+
if (_lastWindowState == WindowState.FullScreen)
577+
{
578+
// Fullscreen mode is really a restored window without a frame filling the whole monitor.
579+
// It doesn't make sense to resize the window in this state, so ignore this request.
580+
Logger.TryGet(LogEventLevel.Warning, LogArea.Win32Platform)?.Log(this, "Ignoring resize event on fullscreen window.");
581+
return;
582+
}
583+
575584
GetWindowPlacement(_hwnd, out var windowPlacement);
576585

577586
var clientScreenOrigin = new POINT();
@@ -598,7 +607,9 @@ public void Resize(Size value, WindowResizeReason reason)
598607
windowPlacement.ShowCmd = _lastWindowState switch
599608
{
600609
WindowState.Minimized => ShowWindowCommand.ShowMinNoActive,
601-
_ => ShowWindowCommand.ShowNoActivate,
610+
WindowState.Maximized => ShowWindowCommand.ShowMaximized,
611+
WindowState.Normal => ShowWindowCommand.ShowNoActivate,
612+
_ => throw new NotImplementedException(),
602613
};
603614

604615
using var scope = SetResizeReason(reason);

0 commit comments

Comments
 (0)