Hi! I’m trying to program drag and drop of files from my Gtk4 app into other Gnome apps - particularily nautilus.
The code I am using is along the lines of:
def on_setup(factory, listitem):
widget = ...
listitem.set_child(widget)
ev_drag = Gtk.DragSource(actions=Gdk.DragAction.COPY)
ev_drag.connect('prepare', on_drag_prepare)
widget.add_controller(ev_drag)
def on_bind(factory, listitem):
widget = listitem.get_child()
item = listitem.get_item()
widget.item = item # to find the item from the widget
def on_drag_prepare(event, x, y):
widget = event.get_widget()
item = widget.item
gfile = ... # get the Gio.File from 'item' here
content = Gdk.FileList.new_from_list([gfile])
return Gdk.ContentProvider.new_for_value(content)
Wierdly enough, drag and drop works with Visual Studio Code and within the app but with no other apps.
Any thoughts on how to make this work? I am using Python but tips in any other programming languages are welcome.