From a264194772891346cb48a5fd76e495c21467ed3d Mon Sep 17 00:00:00 2001 From: qinware Date: Tue, 16 Sep 2025 18:42:32 +0800 Subject: [PATCH] Optimize Window Template for linux --- .../Window/Themes/WindowTheme.axaml | 22 ++++++++++++++++--- src/AtomUI.Controls/Window/Window.cs | 21 ++++++------------ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml b/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml index 21be9065f..485920874 100644 --- a/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml +++ b/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml @@ -12,7 +12,9 @@ + @@ -33,12 +35,10 @@ HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" /> - - @@ -80,12 +80,28 @@ + + + diff --git a/src/AtomUI.Controls/Window/Window.cs b/src/AtomUI.Controls/Window/Window.cs index ca37d1c1a..d743a13e3 100644 --- a/src/AtomUI.Controls/Window/Window.cs +++ b/src/AtomUI.Controls/Window/Window.cs @@ -62,7 +62,6 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable public static readonly StyledProperty IsResizeEnabledProperty = AvaloniaProperty.Register(nameof(IsResizeEnabled), defaultValue: true); -#if PLATFORM_MACOS public static readonly StyledProperty MacOSCaptionGroupOffsetProperty = AvaloniaProperty.Register(nameof(MacOSCaptionGroupOffset), defaultValue: new Point(10, 0)); @@ -72,10 +71,9 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable public static readonly DirectProperty MacOSTitleBarMarginProperty = AvaloniaProperty.RegisterDirect(nameof (MacOSTitleBarMargin), o => o.MacOSTitleBarMargin); - + public static readonly StyledProperty OperationSystemTypeProperty = OperationSystemAwareControlProperty.OperationSystemTypeProperty.AddOwner(); -#endif public double TitleFontSize { @@ -161,7 +159,6 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable set => SetValue(IsResizeEnabledProperty, value); } -#if PLATFORM_MACOS public Point MacOSCaptionGroupOffset { get => GetValue(MacOSCaptionGroupOffsetProperty); @@ -182,7 +179,6 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable private Thickness _macOSTitleBarMargin; public OperationSystemType OperationSystemType => GetValue(OperationSystemTypeProperty); -#endif #endregion @@ -238,16 +234,15 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable } HandleWindowStateChanged(oldWindowState, newWindowState); } - +#if PLATFORM_MACOS if (this.IsAttachedToVisualTree()) { if (change.Property == IsCloseCaptionButtonEnabledProperty) { -#if PLATFORM_MACOS this.SetMacOSWindowClosable(IsCloseCaptionButtonEnabled); -#endif } } +#endif } private void HandleWindowStateChanged(WindowState oldState, WindowState newState) @@ -404,14 +399,11 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable _disposeActions.Clear(); } +#if PLATFORM_MACOS protected override void OnSizeChanged(SizeChangedEventArgs e) { base.OnSizeChanged(e); - - if (OperatingSystem.IsMacCatalyst() || OperatingSystem.IsMacOS()) - { - ConfigureMacOSCaptionGroupOffset(); - } + ConfigureMacOSCaptionGroupOffset(); } private void ConfigureMacOSCaptionGroupOffset() @@ -420,7 +412,8 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable var cationsSize = this.GetMacOSOptionsSize(MacOSCaptionGroupSpacing); MacOSTitleBarMargin = new Thickness(cationsSize.Width + MacOSCaptionGroupOffset.X, 0, 0, 0); } - +#endif + void IOperationSystemAware.SetOperationSystemType(OperationSystemType operationSystemType) { SetValue(OperationSystemTypeProperty, operationSystemType);