Browse Source

Win32: Fix window animations in extended mode (#21498)

release/12.0
Julien Lebosquain 4 months ago
parent
commit
458906d8d6
  1. 6
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
  2. 27
      src/Windows/Avalonia.Win32/WindowImpl.cs

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

@ -93,11 +93,9 @@ namespace Avalonia.Win32
}
else
{
// There's no extra border on top with WS_CAPTION: it's part of the caption.
adjuster.Adjust(ref borderThickness, style, 0);
var thinBorderThickness = new RECT();
adjuster.Adjust(ref thinBorderThickness, style & ~(WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME) | WindowStyles.WS_BORDER, 0);
borderThickness.top = thinBorderThickness.top;
borderThickness.top = 0;
}
}
else if (style.HasAllFlags(WindowStyles.WS_BORDER))

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

@ -596,12 +596,18 @@ namespace Avalonia.Win32
if (_isClientAreaExtended)
{
// We told Windows we have a caption, but since we're actually extending into it,
// We told Windows we have a border, but since we're actually extending into it,
// it should be excluded from the final window bounds.
if (_windowProperties.Decorations != WindowDecorations.None)
var style = GetStyle();
if ((style & WindowStyles.WS_BORDER) != 0)
{
var borderOnlyRect = ClientRectToWindowRect(requestedClientRect, WindowStyles.WS_BORDER);
requestedWindowRect.top = borderOnlyRect.top;
// If we're supposed to have a caption, the top border is actually collapsed into it.
if ((style & WindowStyles.WS_CAPTION) == WindowStyles.WS_CAPTION)
requestedWindowRect.top += 1;
}
}
@ -1400,10 +1406,6 @@ namespace Avalonia.Win32
private void UpdateWindowProperties(WindowProperties newProperties, bool forceChanges = false)
{
// Implementation note: this method tries to keep the same styles for extended and non-extended modes.
// However, we had to make an exception for WS_CAPTION since it causes issues in Windows 10.
// See https://github.com/AvaloniaUI/Avalonia/issues/21328
var oldProperties = _windowProperties;
// Calling SetWindowPos will cause events to be sent and we need to respond
@ -1471,15 +1473,7 @@ namespace Avalonia.Win32
switch (newProperties.Decorations)
{
case WindowDecorations.Full:
style |= WindowStyles.WS_BORDER | WindowStyles.WS_SYSMENU;
// When WS_CAPTION is specified, Windows 10 always draws the caption even if we extend into it.
// We can workaround that by setting DWMWA_NCRENDERING_POLICY to DISABLE, but that also removes
// shadows and borders. Remove the style completely.
// Windows 11 correctly handles this scenario.
if (!_isClientAreaExtended)
style |= WindowStyles.WS_CAPTION;
style |= WindowStyles.WS_BORDER | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION;
break;
case WindowDecorations.BorderOnly:
@ -1603,9 +1597,6 @@ namespace Avalonia.Win32
{
_isClientAreaExtended = hint;
// We may need to toggle WS_CAPTION when extending, ensure the styles are up-to-date.
UpdateWindowProperties(_windowProperties);
ExtendClientArea();
}

Loading…
Cancel
Save