From 8face442308f9933377c85fc0cd4afd02271a1ae Mon Sep 17 00:00:00 2001 From: qinware Date: Mon, 4 Aug 2025 16:30:47 +0800 Subject: [PATCH] Add IsResizeEnabled for Window --- .../Window/Themes/WindowTheme.axaml | 2 +- src/AtomUI.Controls/Window/Window.cs | 39 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml b/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml index ecd5c2230..2c85d5df9 100644 --- a/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml +++ b/src/AtomUI.Controls/Window/Themes/WindowTheme.axaml @@ -14,7 +14,7 @@ + IsVisible="{Binding $parent[atom:Window].IsResizeEnabled}"/> diff --git a/src/AtomUI.Controls/Window/Window.cs b/src/AtomUI.Controls/Window/Window.cs index 56dcc7265..1e373bbdb 100644 --- a/src/AtomUI.Controls/Window/Window.cs +++ b/src/AtomUI.Controls/Window/Window.cs @@ -58,6 +58,9 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable public static readonly StyledProperty IsMoveEnabledProperty = AvaloniaProperty.Register(nameof(IsMoveEnabled), defaultValue: true); + public static readonly StyledProperty IsResizeEnabledProperty = + AvaloniaProperty.Register(nameof(IsResizeEnabled), defaultValue: true); + public static readonly StyledProperty MacOSCaptionGroupOffsetProperty = AvaloniaProperty.Register(nameof(MacOSCaptionGroupOffset), defaultValue: new Point(10, 0)); @@ -149,6 +152,12 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable set => SetValue(IsMoveEnabledProperty, value); } + public bool IsResizeEnabled + { + get => GetValue(IsResizeEnabledProperty); + set => SetValue(IsResizeEnabledProperty, value); + } + public Point MacOSCaptionGroupOffset { get => GetValue(MacOSCaptionGroupOffsetProperty); @@ -179,11 +188,6 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable nameof(PreviousVisibleWindowState), o => o.PreviousVisibleWindowState); - internal static readonly DirectProperty IsUseNativeResizerProperty = - AvaloniaProperty.RegisterDirect( - nameof(IsUseNativeResizer), - o => o.IsUseNativeResizer); - private WindowState _previousVisibleWindowState = WindowState.Normal; internal WindowState PreviousVisibleWindowState @@ -192,14 +196,6 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable private set => SetAndRaise(PreviousVisibleWindowStateProperty, ref _previousVisibleWindowState, value); } - private bool _isUseNativeResizer = true; - - internal bool IsUseNativeResizer - { - get => _isUseNativeResizer; - private set => SetAndRaise(IsUseNativeResizerProperty, ref _isUseNativeResizer, value); - } - #endregion protected override Type StyleKeyOverride { get; } = typeof(Window); @@ -215,11 +211,6 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable { ScalingChanged += HandleScalingChanged; this.ConfigureOperationSystemType(); - - if (OperationSystemType == OperationSystemType.Linux) - { - IsUseNativeResizer = false; - } } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) @@ -319,9 +310,15 @@ public class Window : AvaloniaWindow, IOperationSystemAware, IDisposable { return; } - WindowState = windowState == WindowState.Maximized - ? WindowState.Normal - : WindowState.Maximized; + + if (windowState == WindowState.Normal && IsMaximizeCaptionButtonEnabled) + { + WindowState = WindowState.Maximized; + } + else if (windowState == WindowState.Maximized) + { + WindowState = WindowState.Normal; + } } private void HandleTitleBarPointerPressed(object? sender, PointerPressedEventArgs e)