Tkdnd file drop to Gtk3 app is ignored

File drags from a tcl/tkdnd app into a GTK3 app are ignored. The issue appears to be that the drop data is interpreted as a string rather than a list of file URIs, e.g. dropData.get_data() returns the dropped file name but dropData.get_uris() returns an empty list, as demonstrated by the following demo code. I also noticed that the drop target cursor changes to a hand when dropping a file from Nautilus’ File tool but it does not change when dropping from the tcl/tk app. Any pointers on how to get the tck/tk client to work with Gtk3 are much appreciated. Alternatively, is there a tool that I can use to view the WM messages that are sent during the drag/drop in order to debug the issue? I am running Gnome 42.9 on Ubuntu 22.04.

Tcl/tkdnd drop file source app:

package require tkdnd
catch {console show}

pack [ttk::button .drag_source_files -text " Drag File "] -fill x -padx 20 -pady 20

tkdnd::drag_source register .drag_source_files DND_Files

bind .drag_source_files <<DragInitCmd>> \
  {list {copy} DND_Files [list "file:///tmp/test.wav" ]}

## Event <<DragEndCmd>>
bind .drag_source_files <<DragEndCmd>> {
  puts "Drop action: %A"
}

GTK3 drop file receiver app:

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

window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)

box = Gtk.HBox()
window.add(box)

# Called when the Drop button is dropped on
def on_drag_data_received(widget, drag_context, x, y, data, info, time):
    print("Received uris: {}".format(data.get_uris())) # returns empty list
    print("Received data: {}".format(data.get_data())) # returns file name

# The button into which the file can be dropped
drop_button = Gtk.Button(label="Drop")
drop_button.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
drop_button.drag_dest_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drop_button.connect("drag-data-received", on_drag_data_received)
box.add(drop_button)

window.show_all()
Gtk.main()

Hi,

In Gtk4 there is a new content type Gdk.FileList, that seems to match better what your Tk code provides.

I’m not aware of any equivalent for Gtk3… Maybe you will have to extend the Tk code to provide URIs too?

I believe that the problem lies with tkdnd because file transfers using other ‘clients’ already work with Gtk3. I would like to fix the issue but I’ve received no response on this from the tkdnd supporters as to how to proceed, hence the request to the Gnome folks for any pointers.

I suggest to use the Gtk4 inspector to check what tkdnd provides:

Open any gtk4 application, start the inspector with Ctrl+Shift+I, select “Global” > “Clipboard” and try to drop something from tkdnd to the drop area. Gtk will then list all supported content types, maybe that will give you some hints.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.