Skip to content

Commit ffe74ce

Browse files
maxkatz6grokys
authored andcommitted
Merge pull request #9221 from AvaloniaUI/fixes/8869-show-windowstate
Fix setting WindowState before showing Window.
1 parent a64fcdd commit ffe74ce

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

samples/IntegrationTestApp/MainWindow.axaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@
109109
<ComboBoxItem>CenterScreen</ComboBoxItem>
110110
<ComboBoxItem>CenterOwner</ComboBoxItem>
111111
</ComboBox>
112+
<ComboBox Name="ShowWindowState" SelectedIndex="0">
113+
<ComboBoxItem>Normal</ComboBoxItem>
114+
<ComboBoxItem>Minimized</ComboBoxItem>
115+
<ComboBoxItem>Maximized</ComboBoxItem>
116+
<ComboBoxItem>FullScreen</ComboBoxItem>
117+
</ComboBox>
112118
<Button Name="ShowWindow">Show Window</Button>
113119
<Button Name="SendToBack">Send to Back</Button>
114120
<Button Name="ExitFullscreen">Exit Fullscreen</Button>

samples/IntegrationTestApp/MainWindow.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private void ShowWindow()
5353
var sizeTextBox = this.GetControl<TextBox>("ShowWindowSize");
5454
var modeComboBox = this.GetControl<ComboBox>("ShowWindowMode");
5555
var locationComboBox = this.GetControl<ComboBox>("ShowWindowLocation");
56+
var stateComboBox = this.GetControl<ComboBox>("ShowWindowState");
5657
var size = !string.IsNullOrWhiteSpace(sizeTextBox.Text) ? Size.Parse(sizeTextBox.Text) : (Size?)null;
5758
var owner = (Window)this.GetVisualRoot()!;
5859

@@ -68,6 +69,7 @@ private void ShowWindow()
6869
}
6970

7071
sizeTextBox.Text = string.Empty;
72+
window.WindowState = (WindowState)stateComboBox.SelectedIndex;
7173

7274
switch (modeComboBox.SelectedIndex)
7375
{

samples/IntegrationTestApp/ShowWindowTest.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<ComboBoxItem>Normal</ComboBoxItem>
3030
<ComboBoxItem>Minimized</ComboBoxItem>
3131
<ComboBoxItem>Maximized</ComboBoxItem>
32-
<ComboBoxItem>Fullscreen</ComboBoxItem>
32+
<ComboBoxItem>FullScreen</ComboBoxItem>
3333
</ComboBox>
3434
<Button Name="HideButton" Grid.Row="8" Command="{Binding $parent[Window].Hide}">Hide</Button>
3535
</Grid>

src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,13 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
399399
Resized(clientSize / RenderScaling, _resizeReason);
400400
}
401401

402-
var windowState = size == SizeCommand.Maximized ?
403-
WindowState.Maximized :
404-
(size == SizeCommand.Minimized ? WindowState.Minimized : WindowState.Normal);
402+
var windowState = size switch
403+
{
404+
SizeCommand.Maximized => WindowState.Maximized,
405+
SizeCommand.Minimized => WindowState.Minimized,
406+
_ when _isFullScreenActive => WindowState.FullScreen,
407+
_ => WindowState.Normal,
408+
};
405409

406410
if (windowState != _lastWindowState)
407411
{

src/Windows/Avalonia.Win32/WindowImpl.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ public WindowState WindowState
245245
{
246246
get
247247
{
248+
if (!IsWindowVisible(_hwnd))
249+
{
250+
return _showWindowState;
251+
}
252+
248253
if (_isFullScreenActive)
249254
{
250255
return WindowState.FullScreen;
@@ -511,6 +516,9 @@ public IRenderer CreateRenderer(IRenderRoot root)
511516

512517
public void Resize(Size value, PlatformResizeReason reason)
513518
{
519+
if (WindowState != WindowState.Normal)
520+
return;
521+
514522
int requestedClientWidth = (int)(value.Width * RenderScaling);
515523
int requestedClientHeight = (int)(value.Height * RenderScaling);
516524

@@ -856,11 +864,10 @@ private void SetFullScreen(bool fullscreen)
856864

857865
var window_rect = monitor_info.rcMonitor.ToPixelRect();
858866

867+
_isFullScreenActive = true;
859868
SetWindowPos(_hwnd, IntPtr.Zero, window_rect.X, window_rect.Y,
860869
window_rect.Width, window_rect.Height,
861870
SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
862-
863-
_isFullScreenActive = true;
864871
}
865872
else
866873
{

0 commit comments

Comments
 (0)