[gtk/event-controller-sensitive: 4/4] spin button: Listen for ::cancel on gestures



commit b1d90cc17125a21c93bbf7fdb656742d77bdbca5
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 2 19:09:17 2019 +0000

    spin button: Listen for ::cancel on gestures
    
    Otherwise, we keep spinning when we should stop.
    
    Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1861

 gtk/gtkspinbutton.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
---
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index b273b2e30d..b038feb444 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -809,6 +809,14 @@ button_released_cb (GtkGestureMultiPress *gesture,
     }
 }
 
+static void
+button_cancel_cb (GtkGesture       *gesture,
+                  GdkEventSequence *sequence,
+                  GtkSpinButton    *spin_button)
+{
+  gtk_spin_button_stop_spinning (spin_button);
+}
+
 static void
 key_controller_key_released (GtkEventControllerKey *key,
                              guint                  keyval,
@@ -886,6 +894,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
                                               GTK_PHASE_CAPTURE);
   g_signal_connect (gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button);
   g_signal_connect (gesture, "released", G_CALLBACK (button_released_cb), spin_button);
+  g_signal_connect (gesture, "cancel", G_CALLBACK (button_cancel_cb), spin_button);
   gtk_widget_add_controller (GTK_WIDGET (priv->down_button), GTK_EVENT_CONTROLLER (gesture));
 
   priv->up_button = gtk_button_new ();
@@ -902,6 +911,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button)
                                               GTK_PHASE_CAPTURE);
   g_signal_connect (gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button);
   g_signal_connect (gesture, "released", G_CALLBACK (button_released_cb), spin_button);
+  g_signal_connect (gesture, "cancel", G_CALLBACK (button_cancel_cb), spin_button);
   gtk_widget_add_controller (GTK_WIDGET (priv->up_button), GTK_EVENT_CONTROLLER (gesture));
 
   gtk_spin_button_set_adjustment (spin_button, NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]