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

[Known][Waiting] Drag and Drop files doesn't work on Linux #6085

Open
AnonymousWalker opened this issue Jun 16, 2021 · 10 comments
Open

[Known][Waiting] Drag and Drop files doesn't work on Linux #6085

AnonymousWalker opened this issue Jun 16, 2021 · 10 comments

Comments

@AnonymousWalker
Copy link

AnonymousWalker commented Jun 16, 2021

Similar to dan0v/xdelta3-cross-gui#2

The drag and drop (files/folder) from Files window to the app doesn't work on Linux. It works normally on Windows and MacOS.

@tonyvfish
Copy link

Is there any know work around for this please

@Jon-Murray
Copy link

Fwiw I've had a crack at this today. I did have some limited success in implementing the "Connect" callback, but couldn't seem to wire everything up completely. I don't think it will be too bad - given a lot of the boilerplate is already there. However, I was basically hacking away at stuff by spawning a function to "RunOnGlibThread" on the MainWindow, and trying to stuff it all in there as a PoC... and it all just felt incredibly dirty and hacky, and I figure it is best to leave it to those who actually know what they're doing.

It would be really nice to get this sorted though, so we have all 3 platforms working with drag and drop. I've attached a really simple python script which I was using on KDE/Wayland with success to demo the APIs in use. There's no way I'd be able to take it further than this though, as I just don't have the skillset to sort it, sorry.

#!/usr/bin/env python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject

class DragDropWindow(Gtk.Window):

    def __init__(self):

        Gtk.Window.__init__(self, title='Drag and drop test')
        self.set_default_size(400, 400)

        # Set up drag and drop
#       self.connect("drag-motion", self.motion_cb)
#       self.connect("drag-drop", self.drop_cb)
        self.connect("drag-data-received", self.got_data_cb)
#       self.drag_dest_set(0, [], 0)
        targets = Gtk.TargetList.new([])
        targets.add_uri_targets(2)
        self.drag_dest_set_target_list(targets)
        self.drag_dest_add_text_targets()
        
#      { "STRING",        0, TARGET_STRING },
#      { "text/plain",    0, TARGET_STRING },
#      { "text/uri-list", 0, TARGET_URL },

#    def motion_cb(self, wid, context, x, y, time):
#        Gdk.drag_status(context,Gdk.DragAction.COPY, time)
#        return True

#    def drop_cb(self, wid, context, x, y, time):
#        wid.drag_get_data(context, context.list_targets()[-1], time)

    def got_data_cb(self, wid, context, x, y, data, info, time):

        print("got cb")

        if info == 0:
            text = data.get_text()
            datatype = data.get_target()
            print("Received text: %s" % text)
            print("Data type:     %s" % datatype)

        elif info == 2:
            print("Path/s %s" % data.get_uris())
            print("Size %s" % data.get_length())
            print("datatype/mime %s" % data.get_target())

        context.finish(True, False, time)

win = DragDropWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

@Mikolaytis
Copy link
Contributor

Lack of drag drop on linux is actually a surprise for me. I thought it's done long ago. I think that this feature is mandatory. Priority is the same as clipboard support.

@xecrets
Copy link

xecrets commented Sep 20, 2023

Still no drag and drop support on Linux!? It's a fairly basic feature, although perhaps not trivial to implement... Still, perhaps it would be better to say "limited Linux support" and list the limitations since Avalonia is touted as a "cross-platform UI framework" with no mention that Windows is the primary platform, and the support for the other platforms vary. Still very cool and very useful, but this is a bit of a disappointment and it comes after investing quite a bit into it just to realize that there's no drag and drop on Linux, and doesn't appear to be a very high priority either. The original post here is now over 2 years old...

(Also, it can be noted slightly off-topic that copy/paste support is also sketchy on macOS and Linux and needs a bit of client OS-dependent code to work around the limitations, but at least it's possible to make it work with reasonable effort)

@timunie
Copy link
Contributor

timunie commented Sep 21, 2023

@xecrets I understand your needs, but the thing is that Linux has several different window managers, all working differently. We are still trying to figure out a proper API for it. #11011

As the issue is labeled with help-wanted, if you or anyone else want to take a look into providing DnD support, a PR is welcome.

@xecrets
Copy link

xecrets commented Sep 21, 2023

@timunie - Thanks for explaining. I do realize there's a challenge, and would love to contribute - but it's simply way above my pay-grade to write Linux-specific implementations of this sort, for perhaps also three window managers too to boot! I have considered it, especially for the somewhat related issue of copy/paste, where more of the scaffolding seems to be in place. But then again, I really have no idea of how the different window managers differ.

As the issue is indeed non-trivial, and it's likely to take some time, it would be nice if the documentation would mention supported platforms, and if there was like a table of what feature groups are supported on what platforms. As the number of platforms increase, I'm guessing this will become even more valuable.

For now, I've implemented OS-specific wrappers of IClipboard for macOS and Linux (Ubuntu/Gnome) that handles DataFormats.Text and DataFormats.Files at least well enough for my current needs. As for DnD I'm now in the process of having OS-specific text prompts and documentation that simply avoids mentioning DnD for Linux... By the way, isn't it a little strange to have an incomplete IClipboard implementation - and then adding an [NotClientImplementable] attribute to the interface ;-) ?

@timunie
Copy link
Contributor

timunie commented Sep 21, 2023

By the way, isn't it a little strange to have an incomplete IClipboard implementation - and then adding an [NotClientImplementable] attribute to the interface ;-) ?

No. This exactly allows us to improve / implement it without breaking changes. If we would have make it implementable, we couldn't add it during 11.x timeframe. I also think if someone wants to implement it, Avalonia should be fixed. Not a hack-fix in the App.

@HookedBehemoth
Copy link

I looked into how X11 Drag & Drop (XDND) could be added into Avalonia.

The current IDataObject interface critically assumes that Get is sync. In XDND a client can read the mime types in sync but to receive the actual content or file, the receiver calls XConvertSelection, the sender responds to SelectionRequest, the receiver receives SelectionNotify and can then read the property that actually holds the content or file.

The workaround I could think off here is to assume that the library user just accepts the known mime type, request it, receive the contents and only then emit the event.

@kekekeks
Copy link
Member

kekekeks commented Nov 1, 2023

The current IDataObject was copy-pasted from WPF without any thought about X11 and it got merged because we didn't have "the proposed API needs to be supported across all platforms before merging" policy back in the day.

My current idea about fixing the mess is to have a dedicated X11 thread just for clipboard and DND.

@MatteoCelardo
Copy link

MatteoCelardo commented Apr 24, 2024

If someone is still interested in this topic, I found this on the avalonia docs that does not allow to drag and drop things but at least permits to import a specified file.
This is not what I can call a solution, but it is something, at least

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants