Skip to content

Commit 49fb9ff

Browse files
authored
[macOS] Fixes stuck mouse buttons after drag (#17035)
* Reset pressed mouse buttons on drag on macOS * Make draggable borders easier to click in ControlCatalog
1 parent 0aac1e4 commit 49fb9ff

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

native/Avalonia.Native/src/OSX/AvnView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
2020
-(void) onClosed;
2121
-(void) setModifiers:(NSEventModifierFlags)modifierFlags;
22+
-(void) resetPressedMouseButtons;
2223

2324
-(AvnPlatformResizeReason) getResizeReason;
2425
-(void) setResizeReason:(AvnPlatformResizeReason)reason;

native/Avalonia.Native/src/OSX/AvnView.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ - (void)setModifiers:(NSEventModifierFlags)modifierFlags
485485
_modifierState = [self getModifiers:modifierFlags];
486486
}
487487

488+
- (void)resetPressedMouseButtons
489+
{
490+
_isLeftPressed = false;
491+
_isRightPressed = false;
492+
_isMiddlePressed = false;
493+
_isXButton1Pressed = false;
494+
_isXButton2Pressed = false;
495+
}
496+
488497
- (void)flagsChanged:(NSEvent *)event
489498
{
490499
auto newModifierState = [self getModifiers:[event modifierFlags]];

native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@
430430
op |= NSDragOperationLink;
431431
if ((ieffects & (int) AvnDragDropEffects::Move) != 0)
432432
op |= NSDragOperationMove;
433+
[View resetPressedMouseButtons];
433434
[View beginDraggingSessionWithItems:@[dragItem] event:nsevent
434435
source:CreateDraggingSource((NSDragOperation) op, cb, sourceHandle)];
435436
return S_OK;

samples/ControlCatalog/Pages/DragAndDropPage.xaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<UserControl x:Class="ControlCatalog.Pages.DragAndDropPage"
22
xmlns="https://github.com/avaloniaui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
4+
5+
<UserControl.Styles>
6+
<Style Selector="Border.draggable">
7+
<Setter Property="Background" Value="Transparent" />
8+
<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentColor}" />
9+
<Setter Property="BorderThickness" Value="2" />
10+
<Setter Property="Padding" Value="16" />
11+
</Style>
12+
</UserControl.Styles>
13+
414
<StackPanel Orientation="Vertical" Spacing="4">
515
<TextBlock Classes="h2">Example of Drag+Drop capabilities</TextBlock>
616

717
<WrapPanel HorizontalAlignment="Center">
818
<StackPanel Margin="8"
919
MaxWidth="160">
1020
<Border Name="DragMeText"
11-
Padding="16"
12-
BorderBrush="{DynamicResource SystemAccentColor}"
13-
BorderThickness="2">
21+
Classes="draggable">
1422
<TextBlock Name="DragStateText" TextWrapping="Wrap">Drag Me (text)</TextBlock>
1523
</Border>
1624
<Border Name="DragMeFiles"
17-
Padding="16"
18-
BorderBrush="{DynamicResource SystemAccentColor}"
19-
BorderThickness="2">
25+
Classes="draggable">
2026
<TextBlock Name="DragStateFiles" TextWrapping="Wrap">Drag Me (files)</TextBlock>
2127
</Border>
2228
<Border Name="DragMeCustom"
23-
Padding="16"
24-
BorderBrush="{DynamicResource SystemAccentColor}"
25-
BorderThickness="2">
29+
Classes="draggable">
2630
<TextBlock Name="DragStateCustom" TextWrapping="Wrap">Drag Me (custom)</TextBlock>
2731
</Border>
2832
</StackPanel>

0 commit comments

Comments
 (0)