File drag and drop in gtkmm4

how can i drag and drop in gtkmm4?
in gtkmm3 i use this code:

void callback(const Glib::RefPtr<Gdk::DragContext>& context,
              const int& x,
              const int& y, const Gtk::SelectionData& seldata, const unsigned int& info,const unsigned int& time){
    for(auto& uri : seldata.get_uris()){

},Gtk::DestDefaults::DEST_DEFAULT_ALL, Gdk::DragAction::ACTION_COPY);


in gtkmm4 i try this:

auto dnd = Gtk::DropTarget::create(GDK_TYPE_FILE_LIST,Gdk::DragAction::COPY);

dnd->signal_drop().connect([](const Glib::ValueBase& value, auto x, auto y){
   std::cout << "test" << std::endl;
   return true;

and i get this errors:

(gtk4test:162913): Gtk-WARNING **: 23:35:38.373: (../gtk/gtk/gtkdroptarget.c:477):gtk_drop_target_handle_crossing: runtime check failed: (self->drop == NULL || self->drop == crossing->drop)

(gtk4test:162913): Gtk-WARNING **: 23:35:38.404: (../gtk/gtk/gtkdroptarget.c:477):gtk_drop_target_handle_crossing: runtime check failed: (self->drop == NULL || self->drop == crossing->drop)

(gtk4test:162913): Gtk-WARNING **: 23:35:38.404: (../gtk/gtk/gtkdroptarget.c:477):gtk_drop_target_handle_crossing: runtime check failed: (self->drop == NULL || self->drop == crossing->drop)

(gtk4test:162913): Gtk-CRITICAL **: 23:35:38.404: gtk_drop_target_handle_event: assertion 'self->drop == gdk_dnd_event_get_drop (event)' failed

what am I doing wrong?

I made a small change in one of the example programs in the gtkmm tutorial,

I just changed

auto target = Gtk::DropTarget::create(ustring_type, Gdk::DragAction::COPY);


auto target = Gtk::DropTarget::create(GDK_TYPE_FILE_LIST, Gdk::DragAction::COPY);

I could drag files from nautilus. Result:

Received unexpected data type "GdkFileList" in button

which is expected. I didn’t make any change in DnDWindow::on_button_drop_drop_data().

I don’t know why you get warnings and a critical message. Which versions of
gtk and gtkmm do you use? I used gtk 4.7.1 and the latest gtkmm in the git repository.

i use gtk4 version 4.6.1-1 and gtkmm4 version 4.6.1-1. on kde with X11. I did the same as you and got the same error. looks like a bug.

it seems to be a kde bug because on xfce4 with the same library version everything works fine.

I run Ubuntu with Wayland.

I tested with gtk 4.6.1 and gtkmm 4.6.1. It works just like 4.7.1.
It also works with the original version of Then DnDWindow::on_button_drop_drop_data()
receives the names of the dragged and dropped files.

What you’ve seen might be a bug that shows up only with the X11 backend.

This is partly true. I also checked on kde wayland there are also errors BUT the callback is still called with the correct data. I don’t think this is a bug related to GTK4 because on xfce4 which works with X11 everything works (although some error also appears). It’s also worth noting that I’m using kde 5.24, maybe in 5.25 this problem has already been solved.

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