From 4c949ee628ae5394e85003ff64d054b26d32c3f4 Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Mon, 18 Mar 2024 18:02:50 +0000 Subject: [PATCH] only set window position on extended margins update when window is visible (#14954) --- src/Windows/Avalonia.Win32/WindowImpl.cs | 30 ++++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index eea8d10b50..7589f2457e 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -1199,7 +1199,7 @@ namespace Avalonia.Win32 newWindowProperties.WindowState = state; - UpdateWindowProperties(newWindowProperties); + UpdateWindowProperties(newWindowProperties, newWindowProperties.Decorations != SystemDecorations.Full); if (command.HasValue) { @@ -1468,21 +1468,25 @@ namespace Avalonia.Win32 DwmExtendFrameIntoClientArea(_hwnd, ref margins); - GetClientRect(_hwnd, out var oldClientRect); - var oldClientRectOrigin = new POINT(); - ClientToScreen(_hwnd, ref oldClientRectOrigin); - oldClientRect.Offset(oldClientRectOrigin); - - var newRect = oldClientRect; - if (newProperties.Decorations == SystemDecorations.Full) + if (_shown || forceChanges) { - AdjustWindowRectEx(ref newRect, (uint)style, false, (uint)GetExtendedStyle()); - } + GetClientRect(_hwnd, out var oldClientRect); + var oldClientRectOrigin = new POINT(); + ClientToScreen(_hwnd, ref oldClientRectOrigin); + oldClientRect.Offset(oldClientRectOrigin); + + var newRect = oldClientRect; - SetWindowPos(_hwnd, IntPtr.Zero, newRect.left, newRect.top, newRect.Width, newRect.Height, - SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | - SetWindowPosFlags.SWP_FRAMECHANGED); + if (newProperties.Decorations == SystemDecorations.Full) + { + AdjustWindowRectEx(ref newRect, (uint)style, false, (uint)GetExtendedStyle()); + } + + SetWindowPos(_hwnd, IntPtr.Zero, newRect.left, newRect.top, newRect.Width, newRect.Height, + SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | + SetWindowPosFlags.SWP_FRAMECHANGED); + } } // Ensure window state if decorations change