Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Fixes stuck mouse buttons after drag #17035

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions native/Avalonia.Native/src/OSX/AvnView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
-(void) onClosed;
-(void) setModifiers:(NSEventModifierFlags)modifierFlags;
-(void) resetPressedMouseButtons;

-(AvnPlatformResizeReason) getResizeReason;
-(void) setResizeReason:(AvnPlatformResizeReason)reason;
Expand Down
9 changes: 9 additions & 0 deletions native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down
1 change: 1 addition & 0 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 13 additions & 9 deletions samples/ControlCatalog/Pages/DragAndDropPage.xaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
<UserControl x:Class="ControlCatalog.Pages.DragAndDropPage"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<UserControl.Styles>
<Style Selector="Border.draggable">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentColor}" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Padding" Value="16" />
</Style>
</UserControl.Styles>

<StackPanel Orientation="Vertical" Spacing="4">
<TextBlock Classes="h2">Example of Drag+Drop capabilities</TextBlock>

<WrapPanel HorizontalAlignment="Center">
<StackPanel Margin="8"
MaxWidth="160">
<Border Name="DragMeText"
Padding="16"
BorderBrush="{DynamicResource SystemAccentColor}"
BorderThickness="2">
Classes="draggable">
<TextBlock Name="DragStateText" TextWrapping="Wrap">Drag Me (text)</TextBlock>
</Border>
<Border Name="DragMeFiles"
Padding="16"
BorderBrush="{DynamicResource SystemAccentColor}"
BorderThickness="2">
Classes="draggable">
<TextBlock Name="DragStateFiles" TextWrapping="Wrap">Drag Me (files)</TextBlock>
</Border>
<Border Name="DragMeCustom"
Padding="16"
BorderBrush="{DynamicResource SystemAccentColor}"
BorderThickness="2">
Classes="draggable">
<TextBlock Name="DragStateCustom" TextWrapping="Wrap">Drag Me (custom)</TextBlock>
</Border>
</StackPanel>
Expand Down
Loading