GTK3: Mouse vanishes when using drag and drop

356 views Asked by At

Im trying to use the inter-widget drag-and-drop functionalities in GTK3 with gtkmm. Im using Windows 7 x64 (msys2) and gcc 5.3.0.

When i start dragging, the mouse cursor vanishes and the DnD icon is shown at the upper left corner of the screen. Is this a bug or is there something wrong in my code?

Here you can see a very small test application with Gtk::CheckButton as drag source and drag destination.

#include <iostream>
#include <gtkmm-3.0/gtkmm.h>

struct DragButton : Gtk::CheckButton{
    DragButton(){
        this->signal_drag_begin().connect([](const Glib::RefPtr<Gdk::DragContext>& ctx){
            ctx->set_icon();
        });
        this->drag_source_set({Gtk::TargetEntry("testdata")});
        this->drag_dest_set({Gtk::TargetEntry("testdata")});

        this->signal_drag_data_get().connect(
            [this](const Glib::RefPtr<Gdk::DragContext>&,Gtk::SelectionData& s,guint,guint ){
                std::cout << "sending data." << std::endl;
            }
        );
        this->signal_drag_data_received().connect(
            [](const Glib::RefPtr<Gdk::DragContext>& c,int,int,const Gtk::SelectionData&,guint,guint time){
                std::cout << "receiving data" << std::endl;
                c->drop_finish(true,time);
            }
        );
    }
};

int main(){
    auto app = Gtk::Application::create("test");
    auto settings = Gtk::Settings::get_default();
    settings->set_property<Glib::ustring>("gtk-font-name","Sans 10");

    Gtk::Window window;
    window.set_default_size(100,50);
    Gtk::Box box;

    for(int i = 0; i < 3; i++){
        box.pack_end(*Gtk::manage(new DragButton));
    }

    window.add(box);
    window.show_all();

    app->run(window);
}

This screenshot shows the output:

2

There are 2 answers

0
tly On BEST ANSWER

I found the problem. I found out here that the adwait-icon-theme that is used as a default was not fully windows-compatible. The cursors .cur format were missing. This commit fixed the problem, I had to install the new version of the theme.

3
pozzugno On

I noticed the same behaviour here. Even with "official" gnome/gtk applications. For example, let's try to drag&drop widgets in Glade: you will have the same "strange" effect.

I think it's a bug of gtk libraries in Windows, but I can't imagine why this isn't solved yet, considering drag&drop is a very useful and used operation.