Skip to content

Change DoDragDropAsync trigger event to PointerPressedEventArgs - #20988

Merged
MrJul merged 7 commits into
AvaloniaUI:masterfrom
MrJul:fix/dodragdrop-trigger-event
Mar 30, 2026
Merged

Change DoDragDropAsync trigger event to PointerPressedEventArgs#20988
MrJul merged 7 commits into
AvaloniaUI:masterfrom
MrJul:fix/dodragdrop-trigger-event

Conversation

@MrJul

@MrJul MrJul commented Mar 25, 2026

Copy link
Copy Markdown
Member

What does the pull request do?

This PR changes the type of the triggerEvent parameter of DragDrop.DoDragDropAsync from PointerEventArgs to PointerPressedEventArgs.

It is not valid to start a drag from other types of events.

Comment thread src/Avalonia.Base/Input/Platform/IPlatformDragSource.cs Outdated
kekekeks
kekekeks previously approved these changes Mar 25, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0064051-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@amwx

amwx commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

It is not valid to start a drag from other types of events.

Why not? What about cases like this:

protected override async void OnPointerMoved(PointerEventArgs e)
{
    if (_initialPoint.HasValue)
    {
        var currentPoint = e.GetCurrentPoint(this);
        var delta = _initialPoint.Value - currentPoint.Position;

        if (Math.Abs(delta.X) > _cxDrag || Math.Abs(delta.Y) > _cyDrag)
        {
            // Start Drag
            var result = await DragDrop.DoDragDropAsync(...);
        }
    }
}

where you want to ensure the cursor is moved a minimum distance before initiating drag, which is done in PointerMoved? Why make the user store the PointerPressed args to do something like this?

@maxkatz6

maxkatz6 commented Mar 26, 2026

Copy link
Copy Markdown
Member

@amwx the answer is Wayland.
See https://gitlab.freedesktop.org/wayland/wayland/-/blob/main/protocol/wayland.xml#L951 by the protocol it expects time of the grab, not move.

      <arg name="serial" type="uint" summary="serial number of the implicit grab on the origin"/>

Where implicit grab is initiated on pointer press. It might work with pre-stored PointerPressed though, not sure exactly. @kekekeks in case if we can resolve something like "current implicit grab serial from the specified pointer id".

@kekekeks

Copy link
Copy Markdown
Member

It should work with stored event, the protocol is async, after all. But we need to use the initial pointer press to start the dnd operation.

@amwx

amwx commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

I see... I just don't like the limiting of the public API based on one platform. IMO single platform limitations should be handled internally, but I'm also not the one to manage/maintain all this and have limited Wayland knowledge so what do I know...

Though instead of just saying "not valid", that rationale should've been included in the initial description since pretty much every other platform doesn't have this issue. I live in Windows world, so the only thing I know about Wayland is that every time I learn something new about it I hate it more :) and I'm sure there's other Avalonia users that have limited knowledge on Wayland too

@MrJul

MrJul commented Mar 27, 2026

Copy link
Copy Markdown
Member Author

Though instead of just saying "not valid", that rationale should've been included in the initial description since pretty much every other platform doesn't have this issue.

Yes, you're completely right about that. The discussion mostly took place internally, and I should have conveyed the rationale more clearly.

Note that it's not only Wayland. In the new XDND implementation, we're taking an explicit pointer grab when drag starts. This causes the pointer to be completely locked up, system-wide, if, for example, a breakpoint is triggered, or user code causes the application to freeze for any reason.

Instead, we want to rely on the implicit grab that X11 takes when the pointer is pressed. We can only do that if the drag is started from a pointer-pressed event.

@MrJul
MrJul enabled auto-merge March 30, 2026 07:59
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0064233-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

kekekeks
kekekeks previously approved these changes Mar 30, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0064277-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0064315-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul
MrJul disabled auto-merge March 30, 2026 21:04
@MrJul
MrJul merged commit 5ba8672 into AvaloniaUI:master Mar 30, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants