Skip to content

Commit

Permalink
Update to Avalonia@54158b47 (Jul 12 2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jul 12, 2023
1 parent b764e0c commit 57144d2
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 46 deletions.
1 change: 1 addition & 0 deletions build/update-avalonia.csx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 7 additions & 7 deletions src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -168,7 +168,7 @@ public ILockedFramebuffer Lock()
return new DeferredFramebuffer(_target, cb =>
{
lock (_parent._syncRoot)
{
{
if (_parent._native != null && _target != null)
{
cb(_parent._native);
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 36 additions & 0 deletions src/Modern.WindowKit/Avalonia.Win32/WinUiCompositionShared.cs
Original file line number Diff line number Diff line change
@@ -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<ICompositor5>();
// BlurBrush = WinUiCompositionUtils.CreateAcrylicBlurBackdropBrush(compositor);
// MicaBrush = WinUiCompositionUtils.CreateMicaBackdropBrush(compositor);
// DesktopInterop = compositor.QueryInterface<ICompositorDesktopInterop>();
//}

public void Dispose()
{
//BlurBrush.Dispose();
//MicaBrush?.Dispose();
//DesktopInterop.Dispose();
//Compositor.Dispose();
//Compositor5.Dispose();
}
}
76 changes: 38 additions & 38 deletions src/Modern.WindowKit/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -247,7 +247,7 @@ public Thickness BorderThickness
public double DesktopScaling => RenderScaling;

public Size ClientSize
{
{
get
{
GetClientRect(_hwnd, out var rect);
Expand Down Expand Up @@ -302,7 +302,7 @@ public WindowState WindowState
ShowWindowCommand.Minimize => WindowState.Minimized,
_ => WindowState.Normal
};
}
}

set
{
Expand All @@ -313,7 +313,7 @@ public WindowState WindowState

_lastWindowState = value;
_showWindowState = value;
}
}
}

public WindowTransparencyLevel TransparencyLevel
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -537,7 +537,7 @@ public PixelPoint Position
0,
SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOZORDER);
}
}
}

private bool HasFullDecorations => _windowProperties.Decorations == SystemDecorations.Full;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -678,7 +678,7 @@ public void SetParent(IWindowImpl? parent)
{
parentHwnd = OffscreenParentWindow.Handle;
_hiddenWindowIsParent = true;
}
}

SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, parentHwnd);
}
Expand Down Expand Up @@ -861,7 +861,7 @@ private void CreateWindow()
out _) == 0)
{
_scaling = dpix / 96.0;
}
}
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1100,10 +1100,10 @@ private void ShowWindow(WindowState state, bool activate)
if (command.HasValue)
{
UnmanagedMethods.ShowWindow(_hwnd, command.Value);
}
}

if (state == WindowState.Maximized)
{
{
MaximizeWithoutCoveringTaskbar();
}

Expand All @@ -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
Expand Down Expand Up @@ -1146,15 +1146,15 @@ private void AfterCloseCleanup()
{
UnregisterClass(_className, GetModuleHandle(null));
_className = null;
}
}
}

private void MaximizeWithoutCoveringTaskbar()
{
IntPtr monitor = MonitorFromWindow(_hwnd, MONITOR.MONITOR_DEFAULTTONEAREST);

if (monitor != IntPtr.Zero)
{
{
var monitorInfo = MONITORINFO.Create();

if (GetMonitorInfo(monitor, ref monitorInfo))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
}
}
}

Expand Down Expand Up @@ -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; }
Expand All @@ -1474,7 +1474,7 @@ public ResizeReasonScope(WindowImpl owner, WindowResizeReason restore)
{
_owner = owner;
_restore = restore;
}
}

public void Dispose() => _owner._resizeReason = _restore;
}
Expand Down
1 change: 1 addition & 0 deletions src/Modern.WindowKit/Avalonia.X11/X11Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,5 @@ public static class AvaloniaX11PlatformExtensions
public static void InitializeX11Platform(X11PlatformOptions options = null) =>

Check warning on line 355 in src/Modern.WindowKit/Avalonia.X11/X11Platform.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Cannot convert null literal to non-nullable reference type.
new AvaloniaX11Platform().Initialize(options ?? new X11PlatformOptions());
}

}
2 changes: 1 addition & 1 deletion src/Modern.WindowKit/PickerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class PickerOptions
{
/// <summary>
/// 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.
/// </summary>
public string? Title { get; set; }

Expand Down

0 comments on commit 57144d2

Please sign in to comment.