I’m trying to register to the “drag-end” signal on a Gtk.Scale to do some expensive updates, but the signal is emitted immediately after “drag-begin” for some reason, and I also don’t see any “drag-update” events. What am I doing wrong?
Here is a minimal example:
#include <gtk/gtk.h>
static void drag_begin(GtkEventControllerMotion* self, gpointer user_data)
{
fprintf(stderr, "drag_begin()\n");
}
static void drag_update(GtkEventControllerMotion* self, gpointer user_data)
{
fprintf(stderr, "drag_update()\n");
}
static void drag_end(GtkEventControllerMotion* self, gpointer user_data)
{
fprintf(stderr, "drag_end()\n");
}
static void activate(GtkApplication* app, gpointer user_data)
{
GtkWidget* window;
GtkWidget* grid;
GtkWidget* scale;
GtkAdjustment* adj;
GtkGesture* gesture;
adj = gtk_adjustment_new(5.0, 1.0, 10.0, 0.0, 0.0, 0.0);
scale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj);
gtk_widget_set_hexpand(scale, TRUE);
gesture = gtk_gesture_drag_new();
g_signal_connect(gesture, "drag-begin", G_CALLBACK(drag_begin), NULL);
g_signal_connect(gesture, "drag-update", G_CALLBACK(drag_update), NULL);
g_signal_connect(gesture, "drag-end", G_CALLBACK(drag_end), NULL);
gtk_widget_add_controller(scale, GTK_EVENT_CONTROLLER(gesture));
grid = gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), scale, 0, 0, 1, 1);
window = gtk_application_window_new(app);
gtk_window_set_child(GTK_WINDOW(window), grid);
gtk_widget_set_visible(window, 1);
}
int main(int argc, char** argv)
{
GtkApplication* app;
int status = EXIT_FAILURE;
app = gtk_application_new("com.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
