Skip to content

Fix/drag and drop on linux #19232

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mikekrylov
Copy link

What does the pull request do?

Added realisation of XDnD protocol for X11 on Linux.

What is the current behavior?

There are no Drag and Drop between Avalonia window and other apps on Linux systems with X11 and Wayland-X11 mode.

What is the updated/expected behavior with this PR?

Avalonia app can receive dropped uri and text data and initiate drag for those datas on Linux (if under X11 server).
Avalonia app can receive/transmit other X11's mime types, if app's devs support them.

How was the solution implemented (if it's not obvious)?

To X11Window added helper instance of X11DropTarget, which process XDnD messages and request data according specifications. X11DropTarget works as mid-level between X11 and InputRoot system.
To X11Platform added X11DragSource (similar as OLE implementation). On drag X11DragSource creates instance of DragSourceWindow, an invisible window, which process pointer movements and sends XDnD messages to windows under the cursor.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #6085

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jul 10, 2025

  • All contributors have signed the CLA.

@mikekrylov
Copy link
Author

@cla-avalonia agree

@MrJul
Copy link
Member

MrJul commented Jul 10, 2025

Thank you for your contribution! :)

I haven't reviewed the code yet, but we're currently in the process of refactoring the clipboard and drag and drop architecture. Consequently, your PR will be on hold until that work is completed and will very likely need modifications to accommodate the new types.

@mikekrylov
Copy link
Author

@MrJul Ok, but there a no much usage of Avalonia's inner DragNDrop system, mostly implementations of lots and lots of X11 requests

@kekekeks
Copy link
Member

IDataObject can be queried for data at any stage ( DragEnter, DragOver, DragDrop, DragLeave) for any of the supported types, apps are allowed to inspect dragged contents to decide if they support the dragged data.

This behavior is actually described by XDND spec too:

If it needs to look at the data itself, it calls XConvertSelection() for XdndSelection, the data type that it is interested in, and the given time stamp. (7) It can do this more than once, if necessary.

If it can accept the drop, it should hilight its border to notify the user. If it retrieved the data, it should cache it so it does not need to be retrieved again when the actual drop occurs.

The PR only loads data for only one random data type after getting the final drop event.

So the implementation is incorrect.

@mikekrylov
Copy link
Author

@kekekeks Changed it.
Now it requests all data at DragEnter. I've read, that some X11 drag source implementations supports only one request for data, so "standart" files and text types will be asked first.
Because IDataObject allows user to ask data by type in any moment later, we need to cache all pairs type-data inside the IDataObject.

@avaloniaui-bot
Copy link

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

@kekekeks
Copy link
Member

Now it requests all data at DragEnter.

This is technically incorrect too. The dragged data could be a 8K image that is presented in multiple compressed and uncompressed formats. Transferring all of that via INCR's window of 16KB will take hours.

@kekekeks
Copy link
Member

e. g. dragging image from firefox produces the following formats:

text/uri-list
_NETSCAPE_URL
text/x-moz-url-data
text/x-moz-url-desc
application/x-moz-custom-clipdata
text/_moz_htmlcontext
text/_moz_htmlinfo
text/html
text/plain
text/plain;charset=utf-8
application/x-moz-nativeimage
image/png
image/jpeg
image/jpg
image/gif
application/x-moz-file-promise
XdndDirectSave0
application/x-moz-file-promise-url
application/x-moz-file-promise-dest-filename
application/x-qt-image

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.

[Known][Waiting] Drag and Drop files doesn't work on Linux
5 participants