From 1bf7f5eacbbf6ba10207e27e0789ad797d80d96b Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 8 Jun 2021 15:06:29 +0200 Subject: [PATCH 1/2] spinbutton: Connect swipe gesture to the text entry In the GTK3 days, the spin button was an entry, with buttons on top, and the swipe gesture affected the input on the entry bits. Now the spin button is a container, so this gesture in the capture phase applies to all contained children (incl. buttons). Attach this gesture to the entry itself, so the buttons are left outside this business. The gesture is still in the capture phase in order to prevent text selection/edition/etc to happen. Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4008 --- gtk/gtkspinbutton.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index f54b8a7eb6..303a080e72 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -1075,7 +1075,8 @@ gtk_spin_button_init (GtkSpinButton *spin_button) G_CALLBACK (swipe_gesture_begin), spin_button); g_signal_connect (gesture, "update", G_CALLBACK (swipe_gesture_update), spin_button); - gtk_widget_add_controller (GTK_WIDGET (spin_button), GTK_EVENT_CONTROLLER (gesture)); + gtk_widget_add_controller (GTK_WIDGET (spin_button->entry), + GTK_EVENT_CONTROLLER (gesture)); controller = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL | GTK_EVENT_CONTROLLER_SCROLL_DISCRETE); From 915388cfdb23610e8128214cbb9a7e7248f72049 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 8 Jun 2021 15:09:37 +0200 Subject: [PATCH 2/2] spinbutton: Mind the step in the swipe gesture The swipe gesture forces values in the spin button that are "impossible" according to the adjustment. This can break things in creative ways. Ensure the steps provided are always multiples of the adjustment step value, and keep the remainder for further interaction. --- gtk/gtkspinbutton.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 303a080e72..4e70bc56d7 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -208,6 +208,7 @@ struct _GtkSpinButton double climb_rate; double timer_step; + double swipe_remainder; int width_chars; @@ -838,6 +839,7 @@ swipe_gesture_begin (GtkGesture *gesture, { gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_CLAIMED); gtk_widget_grab_focus (GTK_WIDGET (spin_button)); + spin_button->swipe_remainder = 0; } static void @@ -845,10 +847,12 @@ swipe_gesture_update (GtkGesture *gesture, GdkEventSequence *sequence, GtkSpinButton *spin_button) { - double vel_y; + double vel_y, step; gtk_gesture_swipe_get_velocity (GTK_GESTURE_SWIPE (gesture), NULL, &vel_y); - gtk_spin_button_real_spin (spin_button, -vel_y / 20); + step = (-vel_y / 20) + spin_button->swipe_remainder; + spin_button->swipe_remainder = fmod (step, gtk_adjustment_get_step_increment (spin_button->adjustment)); + gtk_spin_button_real_spin (spin_button, step - spin_button->swipe_remainder); } static gboolean