From 7673dd6a77a9ea3899eb3e3adb1909c70571030b Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Mon, 16 Sep 2024 18:06:36 +0200 Subject: [PATCH 1/2] Reset pressed mouse buttons on drag on macOS --- native/Avalonia.Native/src/OSX/AvnView.h | 1 + native/Avalonia.Native/src/OSX/AvnView.mm | 9 +++++++++ native/Avalonia.Native/src/OSX/WindowBaseImpl.mm | 1 + 3 files changed, 11 insertions(+) diff --git a/native/Avalonia.Native/src/OSX/AvnView.h b/native/Avalonia.Native/src/OSX/AvnView.h index 030330c9081..c80805a15c5 100644 --- a/native/Avalonia.Native/src/OSX/AvnView.h +++ b/native/Avalonia.Native/src/OSX/AvnView.h @@ -19,6 +19,7 @@ -(AvnPoint) translateLocalPoint:(AvnPoint)pt; -(void) onClosed; -(void) setModifiers:(NSEventModifierFlags)modifierFlags; +-(void) resetPressedMouseButtons; -(AvnPlatformResizeReason) getResizeReason; -(void) setResizeReason:(AvnPlatformResizeReason)reason; diff --git a/native/Avalonia.Native/src/OSX/AvnView.mm b/native/Avalonia.Native/src/OSX/AvnView.mm index 664ac81e2f3..dad670c3d1e 100644 --- a/native/Avalonia.Native/src/OSX/AvnView.mm +++ b/native/Avalonia.Native/src/OSX/AvnView.mm @@ -485,6 +485,15 @@ - (void)setModifiers:(NSEventModifierFlags)modifierFlags _modifierState = [self getModifiers:modifierFlags]; } +- (void)resetPressedMouseButtons +{ + _isLeftPressed = false; + _isRightPressed = false; + _isMiddlePressed = false; + _isXButton1Pressed = false; + _isXButton2Pressed = false; +} + - (void)flagsChanged:(NSEvent *)event { auto newModifierState = [self getModifiers:[event modifierFlags]]; diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm index afae6d6b5bc..0335d9e4093 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm @@ -430,6 +430,7 @@ op |= NSDragOperationLink; if ((ieffects & (int) AvnDragDropEffects::Move) != 0) op |= NSDragOperationMove; + [View resetPressedMouseButtons]; [View beginDraggingSessionWithItems:@[dragItem] event:nsevent source:CreateDraggingSource((NSDragOperation) op, cb, sourceHandle)]; return S_OK; From 581e247f5fa42cfd1af39ec5ef3e1cf5301a3cb8 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Mon, 16 Sep 2024 18:10:00 +0200 Subject: [PATCH 2/2] Make draggable borders easier to click in ControlCatalog --- .../ControlCatalog/Pages/DragAndDropPage.xaml | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/samples/ControlCatalog/Pages/DragAndDropPage.xaml b/samples/ControlCatalog/Pages/DragAndDropPage.xaml index 390fa32b9cb..d01cd8b1df2 100644 --- a/samples/ControlCatalog/Pages/DragAndDropPage.xaml +++ b/samples/ControlCatalog/Pages/DragAndDropPage.xaml @@ -1,6 +1,16 @@ + + + + + Example of Drag+Drop capabilities @@ -8,21 +18,15 @@ + Classes="draggable"> Drag Me (text) + Classes="draggable"> Drag Me (files) + Classes="draggable"> Drag Me (custom)