From 57144d214339efe068c403eaf916300d3219370f Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Wed, 12 Jul 2023 17:42:53 -0500 Subject: [PATCH] Update to Avalonia@54158b47 (Jul 12 2023) --- build/update-avalonia.csx | 1 + .../Avalonia.Mac/WindowImplBase.cs | 14 ++-- .../Avalonia.Win32/WinUiCompositionShared.cs | 36 +++++++++ .../Avalonia.Win32/WindowImpl.cs | 76 +++++++++---------- .../Avalonia.X11/X11Platform.cs | 1 + src/Modern.WindowKit/PickerOptions.cs | 2 +- 6 files changed, 84 insertions(+), 46 deletions(-) create mode 100644 src/Modern.WindowKit/Avalonia.Win32/WinUiCompositionShared.cs diff --git a/build/update-avalonia.csx b/build/update-avalonia.csx index 476b842..262a43e 100644 --- a/build/update-avalonia.csx +++ b/build/update-avalonia.csx @@ -178,6 +178,7 @@ CopyFile ("Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs", "Avalonia.Win32/Win CopyFile ("Windows/Avalonia.Win32/Input/WindowsKeyboardDevice.cs", "Avalonia.Win32/WindowsKeyboardDevice.cs"); CopyFile ("Windows/Avalonia.Win32/Input/WindowsMouseDevice.cs", "Avalonia.Win32/WindowsMouseDevice.cs"); CopyFile ("Windows/Avalonia.Win32/WinScreen.cs", "Avalonia.Win32/WinScreen.cs"); +CopyFile ("Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositionShared.cs", "Avalonia.Win32/WinUiCompositionShared.cs"); CopyFile ("Windows/Avalonia.Win32/Win32DispatcherImpl.cs", "Avalonia.Win32/Win32DispatcherImpl.cs"); CopyFile ("Windows/Avalonia.Win32/Win32PlatformOptions.cs", "Avalonia.Win32/Win32PlatformOptions.cs"); CopyFile ("Windows/Avalonia.Win32/Win32PlatformSettings.cs", "Avalonia.Win32/Win32PlatformSettings.cs"); diff --git a/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs b/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs index 64b8af1..0ff95f9 100644 --- a/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs +++ b/src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs @@ -99,9 +99,9 @@ protected void Init(IAvnWindowBase window, IAvnScreens screens) public Size ClientSize { get - { - if (_native != null) { + if (_native != null) + { var s = _native.ClientSize; return new Size(s.Width, s.Height); } @@ -113,11 +113,11 @@ public Size ClientSize public Size? FrameSize { get - { - if (_native != null) { - unsafe + if (_native != null) { + unsafe + { var s = new AvnSize { Width = -1, Height = -1 }; _native.GetFrameSize(&s); return s.Width < 0 && s.Height < 0 ? null : new Size(s.Width, s.Height); @@ -168,7 +168,7 @@ public ILockedFramebuffer Lock() return new DeferredFramebuffer(_target, cb => { lock (_parent._syncRoot) - { + { if (_parent._native != null && _target != null) { cb(_parent._native); @@ -545,7 +545,7 @@ private set public void SetFrameThemeVariant(PlatformThemeVariant themeVariant) { - // _native.SetFrameThemeVariant((AvnPlatformThemeVariant)themeVariant); + _native.SetFrameThemeVariant((AvnPlatformThemeVariant)themeVariant); } public AcrylicPlatformCompensationLevels AcrylicCompensationLevels { get; } = new AcrylicPlatformCompensationLevels(1, 0, 0); diff --git a/src/Modern.WindowKit/Avalonia.Win32/WinUiCompositionShared.cs b/src/Modern.WindowKit/Avalonia.Win32/WinUiCompositionShared.cs new file mode 100644 index 0000000..afe442a --- /dev/null +++ b/src/Modern.WindowKit/Avalonia.Win32/WinUiCompositionShared.cs @@ -0,0 +1,36 @@ +using System; +using Modern.WindowKit.MicroCom; + +namespace Modern.WindowKit.Win32.WinRT.Composition; + +internal class WinUiCompositionShared : IDisposable +{ + //public ICompositor Compositor { get; } + //public ICompositor5 Compositor5 { get; } + //public ICompositorDesktopInterop DesktopInterop { get; } + //public ICompositionBrush BlurBrush { get; } + //public ICompositionBrush? MicaBrush { get; } + //public object SyncRoot { get; } = new(); + + public static readonly Version MinWinCompositionVersion = new(10, 0, 17134); + public static readonly Version MinAcrylicVersion = new(10, 0, 15063); + public static readonly Version MinHostBackdropVersion = new(10, 0, 22000); + + //public WinUiCompositionShared(ICompositor compositor) + //{ + // Compositor = compositor.CloneReference(); + // Compositor5 = compositor.QueryInterface(); + // BlurBrush = WinUiCompositionUtils.CreateAcrylicBlurBackdropBrush(compositor); + // MicaBrush = WinUiCompositionUtils.CreateMicaBackdropBrush(compositor); + // DesktopInterop = compositor.QueryInterface(); + //} + + public void Dispose() + { + //BlurBrush.Dispose(); + //MicaBrush?.Dispose(); + //DesktopInterop.Dispose(); + //Compositor.Dispose(); + //Compositor5.Dispose(); + } +} diff --git a/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs b/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs index 9bbcea9..e3d0aba 100644 --- a/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs +++ b/src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs @@ -21,7 +21,7 @@ using Modern.WindowKit.Win32.Interop; //using Modern.WindowKit.Win32.OpenGl.Angle; //using Modern.WindowKit.Win32.OpenGl; -//using Modern.WindowKit.Win32.WinRT.Composition; +using Modern.WindowKit.Win32.WinRT.Composition; using Modern.WindowKit.Win32.WinRT; using static Modern.WindowKit.Win32.Interop.UnmanagedMethods; using Modern.WindowKit.Input.Platform; @@ -247,7 +247,7 @@ public Thickness BorderThickness public double DesktopScaling => RenderScaling; public Size ClientSize - { + { get { GetClientRect(_hwnd, out var rect); @@ -302,7 +302,7 @@ public WindowState WindowState ShowWindowCommand.Minimize => WindowState.Minimized, _ => WindowState.Normal }; - } + } set { @@ -313,7 +313,7 @@ public WindowState WindowState _lastWindowState = value; _showWindowState = value; - } + } } public WindowTransparencyLevel TransparencyLevel @@ -413,13 +413,13 @@ private bool IsSupported(WindowTransparencyLevel level, Version windowsVersion) if (level == WindowTransparencyLevel.Blur) return windowsVersion < PlatformConstants.Windows10; - //// Acrylic is supported on Windows >= 10.0.15063. - //if (level == WindowTransparencyLevel.AcrylicBlur) - // return windowsVersion >= WinUiCompositionShared.MinAcrylicVersion; + // Acrylic is supported on Windows >= 10.0.15063. + if (level == WindowTransparencyLevel.AcrylicBlur) + return windowsVersion >= WinUiCompositionShared.MinAcrylicVersion; - //// Mica is supported on Windows >= 10.0.22000. - //if (level == WindowTransparencyLevel.Mica) - // return windowsVersion >= WinUiCompositionShared.MinHostBackdropVersion; + // Mica is supported on Windows >= 10.0.22000. + if (level == WindowTransparencyLevel.Mica) + return windowsVersion >= WinUiCompositionShared.MinHostBackdropVersion; return false; } @@ -460,7 +460,7 @@ private void SetTransparencyBlur(Version windowsVersion) private void SetTransparencyAcrylicBlur(Version windowsVersion) { // Acrylic blur only supported with composition on Windows >= 10.0.15063. - //if (!_isUsingComposition || windowsVersion < WinUiCompositionShared.MinAcrylicVersion) + if (!_isUsingComposition || windowsVersion < WinUiCompositionShared.MinAcrylicVersion) return; SetUseHostBackdropBrush(true); @@ -470,7 +470,7 @@ private void SetTransparencyAcrylicBlur(Version windowsVersion) private void SetTransparencyMica(Version windowsVersion) { // Mica only supported with composition on Windows >= 10.0.22000. - //if (!_isUsingComposition || windowsVersion < WinUiCompositionShared.MinHostBackdropVersion) + if (!_isUsingComposition || windowsVersion < WinUiCompositionShared.MinHostBackdropVersion) return; SetUseHostBackdropBrush(false); @@ -499,7 +499,7 @@ private void SetAccentState(AccentState state) private void SetUseHostBackdropBrush(bool useHostBackdropBrush) { - //if (Win32Platform.WindowsVersion < WinUiCompositionShared.MinHostBackdropVersion) + if (Win32Platform.WindowsVersion < WinUiCompositionShared.MinHostBackdropVersion) return; unsafe @@ -537,7 +537,7 @@ public PixelPoint Position 0, SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOZORDER); } - } + } private bool HasFullDecorations => _windowProperties.Decorations == SystemDecorations.Full; @@ -593,11 +593,11 @@ public void Resize(Size value, WindowResizeReason reason) requestedClientWidth + (_isClientAreaExtended ? 0 : windowRect.Width - clientRect.Width), requestedClientHeight + (_isClientAreaExtended ? 0 : windowRect.Height - clientRect.Height), SetWindowPosFlags.SWP_RESIZE); - } + } } public void Activate() - { + { SetForegroundWindow(_hwnd); } @@ -610,7 +610,7 @@ public void Dispose() // Detect if we are being closed programmatically - this would mean that WM_CLOSE was not called // and we didn't prepare this window for destruction. if (!_isCloseRequested) - { + { BeforeCloseCleanup(true); } @@ -678,7 +678,7 @@ public void SetParent(IWindowImpl? parent) { parentHwnd = OffscreenParentWindow.Handle; _hiddenWindowIsParent = true; - } + } SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, parentHwnd); } @@ -861,7 +861,7 @@ private void CreateWindow() out _) == 0) { _scaling = dpix / 96.0; - } + } } } @@ -1021,9 +1021,9 @@ private void ExtendClientArea() DwmExtendFrameIntoClientArea(_hwnd, ref margins); unsafe - { - //int cornerPreference = (int)DwmWindowCornerPreference.DWMWCP_ROUND; - //DwmSetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPreference, sizeof(int)); + { + int cornerPreference = (int)DwmWindowCornerPreference.DWMWCP_ROUND; + DwmSetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPreference, sizeof(int)); } } else @@ -1037,15 +1037,15 @@ private void ExtendClientArea() Resize(new Size(rcWindow.Width / RenderScaling, rcWindow.Height / RenderScaling), WindowResizeReason.Layout); unsafe - { - //int cornerPreference = (int)DwmWindowCornerPreference.DWMWCP_DEFAULT; - //DwmSetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPreference, sizeof(int)); + { + int cornerPreference = (int)DwmWindowCornerPreference.DWMWCP_DEFAULT; + DwmSetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_WINDOW_CORNER_PREFERENCE, &cornerPreference, sizeof(int)); } } if (!_isClientAreaExtended || (_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) && !_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.PreferSystemChrome))) - { + { EnableCloseButton(_hwnd); } else @@ -1100,10 +1100,10 @@ private void ShowWindow(WindowState state, bool activate) if (command.HasValue) { UnmanagedMethods.ShowWindow(_hwnd, command.Value); - } + } if (state == WindowState.Maximized) - { + { MaximizeWithoutCoveringTaskbar(); } @@ -1115,7 +1115,7 @@ private void ShowWindow(WindowState state, bool activate) } private void BeforeCloseCleanup(bool isDisposing) - { + { // Based on https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L4270-L4337 // We need to enable parent window before destroying child window to prevent OS from activating a random window behind us (or last active window). // This is described here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablewindow#remarks @@ -1146,7 +1146,7 @@ private void AfterCloseCleanup() { UnregisterClass(_className, GetModuleHandle(null)); _className = null; - } + } } private void MaximizeWithoutCoveringTaskbar() @@ -1154,7 +1154,7 @@ private void MaximizeWithoutCoveringTaskbar() IntPtr monitor = MonitorFromWindow(_hwnd, MONITOR.MONITOR_DEFAULTTONEAREST); if (monitor != IntPtr.Zero) - { + { var monitorInfo = MONITORINFO.Create(); if (GetMonitorInfo(monitor, ref monitorInfo)) @@ -1225,7 +1225,7 @@ private void SetStyle(WindowStyles style, bool save = true) } private void SetExtendedStyle(WindowStyles style, bool save = true) - { + { if (save) { _savedWindowInfo.ExStyle = style; @@ -1311,7 +1311,7 @@ private void UpdateWindowProperties(WindowProperties newProperties, bool forceCh } if ((oldProperties.Decorations != newProperties.Decorations) || forceChanges) - { + { style = GetStyle(); const WindowStyles fullDecorationFlags = WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU; @@ -1328,7 +1328,7 @@ private void UpdateWindowProperties(WindowProperties newProperties, bool forceCh SetStyle(style); if (!_isFullScreenActive) - { + { var margin = newProperties.Decorations == SystemDecorations.BorderOnly ? 1 : 0; var margins = new MARGINS @@ -1351,12 +1351,12 @@ private void UpdateWindowProperties(WindowProperties newProperties, bool forceCh 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); - } + } } } @@ -1451,7 +1451,7 @@ private ResizeReasonScope SetResizeReason(WindowResizeReason reason) } private struct SavedWindowInfo - { + { public WindowStyles Style { get; set; } public WindowStyles ExStyle { get; set; } public RECT WindowRect { get; set; } @@ -1474,7 +1474,7 @@ public ResizeReasonScope(WindowImpl owner, WindowResizeReason restore) { _owner = owner; _restore = restore; - } + } public void Dispose() => _owner._resizeReason = _restore; } diff --git a/src/Modern.WindowKit/Avalonia.X11/X11Platform.cs b/src/Modern.WindowKit/Avalonia.X11/X11Platform.cs index 31f97f8..d9d1ac0 100644 --- a/src/Modern.WindowKit/Avalonia.X11/X11Platform.cs +++ b/src/Modern.WindowKit/Avalonia.X11/X11Platform.cs @@ -355,4 +355,5 @@ public static class AvaloniaX11PlatformExtensions public static void InitializeX11Platform(X11PlatformOptions options = null) => new AvaloniaX11Platform().Initialize(options ?? new X11PlatformOptions()); } + } diff --git a/src/Modern.WindowKit/PickerOptions.cs b/src/Modern.WindowKit/PickerOptions.cs index 46bb85d..7f8d185 100644 --- a/src/Modern.WindowKit/PickerOptions.cs +++ b/src/Modern.WindowKit/PickerOptions.cs @@ -6,7 +6,7 @@ public class PickerOptions { /// - /// Gets or sets the text that appears in the title bar of a folder dialog. + /// Gets or sets the text that appears in the title bar of a picker. /// public string? Title { get; set; }