Browse Source

Add support for handling rotation cursor movement via macOS titlebar

- Introduce `IsTitlebarRotationClicked` property in `MainWindowViewModel`.
- Update `MacOSTitlebar` to handle left and right-click events for rotation button.
- Adjust `WindowResizing` logic to reposition cursor based on titlebar rotation trigger.
Ruben 1 week ago
parent
commit
e4a1154006

+ 17 - 4
src/PicView.Avalonia.MacOS/Views/MacOSTitlebar.axaml.cs

@@ -1,6 +1,7 @@
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Input;
+using Avalonia.Interactivity;
 using Avalonia.Media;
 using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
@@ -47,14 +48,26 @@ public partial class MacOSTitlebar : UserControl
             RotateRightButton.ContextMenu = _rotationContextMenu;
             
             FlipButton.PointerPressed += (_, e) => { OpenContextMenu(e); };
-            RotateRightButton.PointerPressed += (_, e) => { OpenContextMenu(e); };
-
-            RotateRightButton.PointerPressed += (_, e) => { OpenContextMenu(e); };
-            FlipButton.PointerPressed += (_, e) => { OpenContextMenu(e); };
+            RotateRightButton.AddHandler(PointerPressedEvent, RotateRightButtonHandler, RoutingStrategies.Bubble | RoutingStrategies.Tunnel);
         };
         PointerPressed += (_, e) => MoveWindow(e);
     }
 
+    private void RotateRightButtonHandler(object? sender, PointerPressedEventArgs e)
+    {
+        if (e.Properties.IsLeftButtonPressed)
+        {
+            if (DataContext is MainViewModel vm)
+            {
+                vm.MainWindow.IsTitlebarRotationClicked = true;
+            }
+        }
+        else if (e.Properties.IsRightButtonPressed)
+        {
+            OpenContextMenu(e);
+        }
+    }
+
 
     private void OpenContextMenu(PointerPressedEventArgs e)
     {

+ 2 - 0
src/PicView.Avalonia/ViewModels/MainWindowViewModel.cs

@@ -22,6 +22,8 @@ public class MainWindowViewModel : IDisposable
     public bool IsClickArrowRightClicked { get; set; }
 
     public bool IsBottomToolbarRotationClicked { get; set; }
+    
+    public bool IsTitlebarRotationClicked { get; set; }
 
     public BindableReactiveProperty<Brush?> ImageBackground { get; } = new();
 

+ 5 - 0
src/PicView.Avalonia/WindowBehavior/WindowResizing.cs

@@ -81,6 +81,11 @@ public static class WindowResizing
             clicked => vm.HoverbarViewModel.IsHoverRotateLeftClicked = clicked,
             () => UIHelper.GetHoverBar.GetControl<IconButton>("RotateLeftButton"),
             new Point(11, 7));
+        
+        RepositionCursorIfTriggered(vm, vm.MainWindow.IsTitlebarRotationClicked,
+            clicked => vm.MainWindow.IsTitlebarRotationClicked = clicked,
+            () => UIHelper.GetTitlebar.GetControl<IconButton>("RotateRightButton"),
+            new Point(11, 7));
     }
 
     private static void RepositionCursorIfTriggered(