From ffe74ceaa49b7be878c006c030422bf2d5b0fa73 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 17 Nov 2022 19:54:14 -0500 Subject: [PATCH] Merge pull request #9221 from AvaloniaUI/fixes/8869-show-windowstate Fix setting WindowState before showing Window. --- samples/IntegrationTestApp/MainWindow.axaml | 6 ++++++ samples/IntegrationTestApp/MainWindow.axaml.cs | 2 ++ samples/IntegrationTestApp/ShowWindowTest.axaml | 2 +- src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs | 10 +++++++--- src/Windows/Avalonia.Win32/WindowImpl.cs | 11 +++++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/samples/IntegrationTestApp/MainWindow.axaml b/samples/IntegrationTestApp/MainWindow.axaml index f4d6ad3ace9..952165b827e 100644 --- a/samples/IntegrationTestApp/MainWindow.axaml +++ b/samples/IntegrationTestApp/MainWindow.axaml @@ -109,6 +109,12 @@ CenterScreen CenterOwner + + Normal + Minimized + Maximized + FullScreen + diff --git a/samples/IntegrationTestApp/MainWindow.axaml.cs b/samples/IntegrationTestApp/MainWindow.axaml.cs index 1dab74dc9e7..d086ffb97b4 100644 --- a/samples/IntegrationTestApp/MainWindow.axaml.cs +++ b/samples/IntegrationTestApp/MainWindow.axaml.cs @@ -53,6 +53,7 @@ private void ShowWindow() var sizeTextBox = this.GetControl("ShowWindowSize"); var modeComboBox = this.GetControl("ShowWindowMode"); var locationComboBox = this.GetControl("ShowWindowLocation"); + var stateComboBox = this.GetControl("ShowWindowState"); var size = !string.IsNullOrWhiteSpace(sizeTextBox.Text) ? Size.Parse(sizeTextBox.Text) : (Size?)null; var owner = (Window)this.GetVisualRoot()!; @@ -68,6 +69,7 @@ private void ShowWindow() } sizeTextBox.Text = string.Empty; + window.WindowState = (WindowState)stateComboBox.SelectedIndex; switch (modeComboBox.SelectedIndex) { diff --git a/samples/IntegrationTestApp/ShowWindowTest.axaml b/samples/IntegrationTestApp/ShowWindowTest.axaml index 4001bac7e20..effa55e0611 100644 --- a/samples/IntegrationTestApp/ShowWindowTest.axaml +++ b/samples/IntegrationTestApp/ShowWindowTest.axaml @@ -29,7 +29,7 @@ Normal Minimized Maximized - Fullscreen + FullScreen diff --git a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs index 88a0744e3ee..e5c01f99f64 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs @@ -399,9 +399,13 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, Resized(clientSize / RenderScaling, _resizeReason); } - var windowState = size == SizeCommand.Maximized ? - WindowState.Maximized : - (size == SizeCommand.Minimized ? WindowState.Minimized : WindowState.Normal); + var windowState = size switch + { + SizeCommand.Maximized => WindowState.Maximized, + SizeCommand.Minimized => WindowState.Minimized, + _ when _isFullScreenActive => WindowState.FullScreen, + _ => WindowState.Normal, + }; if (windowState != _lastWindowState) { diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index f62335b3f3d..922bffd2fdb 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -245,6 +245,11 @@ public WindowState WindowState { get { + if (!IsWindowVisible(_hwnd)) + { + return _showWindowState; + } + if (_isFullScreenActive) { return WindowState.FullScreen; @@ -511,6 +516,9 @@ public IRenderer CreateRenderer(IRenderRoot root) public void Resize(Size value, PlatformResizeReason reason) { + if (WindowState != WindowState.Normal) + return; + int requestedClientWidth = (int)(value.Width * RenderScaling); int requestedClientHeight = (int)(value.Height * RenderScaling); @@ -856,11 +864,10 @@ private void SetFullScreen(bool fullscreen) var window_rect = monitor_info.rcMonitor.ToPixelRect(); + _isFullScreenActive = true; SetWindowPos(_hwnd, IntPtr.Zero, window_rect.X, window_rect.Y, window_rect.Width, window_rect.Height, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED); - - _isFullScreenActive = true; } else {