tree-view: drag-gesture events ending immediately
Steps to reproduce
Compile and run this C code with gtk4
#include <gtk/gtk.h>
void
drag_end (GtkGestureDrag * drag, gdouble x, gdouble y, gpointer data)
{
g_print ("drag-end: %g, %g\n", x, y);
}
void
drag_update (GtkGestureDrag * drag, gdouble x, gdouble y, gpointer data)
{
g_print ("drag-update: %g, %g\n", x, y);
}
void
drag_begin (GtkGestureDrag * drag, gdouble x, gdouble y, gpointer data)
{
g_print ("drag-begin: %g, %g\n", x, y);
}
void
activate (GApplication * app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new (GTK_APPLICATION (app));
GtkWidget *view = gtk_tree_view_new ();
GtkGesture *drag = gtk_gesture_drag_new ();
gtk_window_set_child (GTK_WINDOW (window), view);
g_signal_connect (drag, "drag-begin", G_CALLBACK (drag_begin), NULL);
g_signal_connect (drag, "drag-update", G_CALLBACK (drag_update), NULL);
g_signal_connect (drag, "drag-end", G_CALLBACK (drag_end), NULL);
gtk_widget_add_controller (view, GTK_EVENT_CONTROLLER (drag));
gtk_widget_show (window);
}
int
main ()
{
GtkApplication *app;
gtk_init ();
app = gtk_application_new ("test.treeview-drag-events", 0);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
g_application_run (G_APPLICATION (app), 0, NULL);
g_object_unref (app);
return 0;
}
Current behavior
When starting a drag action with a held mouse button over the tree view, drag_begin
is called, as expected, but is then immediately followed by a drag_end
even though the physical mouse button is still pressed. drag_update
is never called, and drag_end
isn't called when the button is released.
For example, the output of one drag operation is
drag-begin: 141.566, 73.8867
drag-end: 0, 0
It seems the drag action is immediately cancelled for a GtkTreeView
. I couldn't reproduce this issue with drag actions attached to a GtkWindow
or a GtkLabel
, so I think this is a problem specific to GtkTreeView
.
Expected outcome
The drag gesture should continue until the mouse button is released, as is the case for other widgets.
Version information
This was found in gtk version 4.0.2 (with Wayland). I did not have this issue in the previous version I used 3.98.4.