From 6d8842ca9611862a9730ce3370ccba36946bbe04 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 13 Jun 2014 01:08:16 +0200 Subject: [PATCH] gesturesingle: Implement GtkGesture::cancel better than GtkEventController:reset The former can be called individually on each sequence, and the latter will always call the former on all currently active sequences, so only implementing resetting on cancel() works for both cases. Also, chain up on subclasses implementing cancel. This fixes clicking on nautilus' file list after popping up a menu, as broken grabs are one of those situations where sequences get cancelled individually, the "current button" wasn't properly reset, and further clicks with button != 3 were ignored. --- gtk/gtkgesturelongpress.c | 10 +++++++++- gtk/gtkgesturemultipress.c | 1 + gtk/gtkgesturesingle.c | 13 ++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gtk/gtkgesturelongpress.c b/gtk/gtkgesturelongpress.c index f2971b3b36..09ac12df4a 100644 --- a/gtk/gtkgesturelongpress.c +++ b/gtk/gtkgesturelongpress.c @@ -175,6 +175,14 @@ gtk_gesture_long_press_end (GtkGesture *gesture, priv->cancelled = priv->triggered = FALSE; } +static void +gtk_gesture_long_press_cancel (GtkGesture *gesture, + GdkEventSequence *sequence) +{ + gtk_gesture_long_press_end (gesture, sequence); + GTK_GESTURE_CLASS (gtk_gesture_long_press_parent_class)->cancel (gesture, sequence); +} + static void gtk_gesture_long_press_sequence_state_changed (GtkGesture *gesture, GdkEventSequence *sequence, @@ -209,7 +217,7 @@ gtk_gesture_long_press_class_init (GtkGestureLongPressClass *klass) gesture_class->begin = gtk_gesture_long_press_begin; gesture_class->update = gtk_gesture_long_press_update; gesture_class->end = gtk_gesture_long_press_end; - gesture_class->cancel = gtk_gesture_long_press_end; + gesture_class->cancel = gtk_gesture_long_press_cancel; gesture_class->sequence_state_changed = gtk_gesture_long_press_sequence_state_changed; diff --git a/gtk/gtkgesturemultipress.c b/gtk/gtkgesturemultipress.c index 1f499768fd..7b0067164c 100644 --- a/gtk/gtkgesturemultipress.c +++ b/gtk/gtkgesturemultipress.c @@ -279,6 +279,7 @@ gtk_gesture_multi_press_cancel (GtkGesture *gesture, GdkEventSequence *sequence) { _gtk_gesture_multi_press_stop (GTK_GESTURE_MULTI_PRESS (gesture)); + GTK_GESTURE_CLASS (gtk_gesture_multi_press_parent_class)->cancel (gesture, sequence); } static void diff --git a/gtk/gtkgesturesingle.c b/gtk/gtkgesturesingle.c index ac91851808..d33f190292 100644 --- a/gtk/gtkgesturesingle.c +++ b/gtk/gtkgesturesingle.c @@ -112,14 +112,15 @@ gtk_gesture_single_set_property (GObject *object, } static void -gtk_gesture_single_reset (GtkEventController *controller) +gtk_gesture_single_cancel (GtkGesture *gesture, + GdkEventSequence *sequence) { GtkGestureSinglePrivate *priv; - priv = gtk_gesture_single_get_instance_private (GTK_GESTURE_SINGLE (controller)); - priv->current_button = 0; + priv = gtk_gesture_single_get_instance_private (GTK_GESTURE_SINGLE (gesture)); - GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_single_parent_class)->reset (controller); + if (sequence == priv->current_sequence) + priv->current_button = 0; } static gboolean @@ -219,14 +220,16 @@ static void gtk_gesture_single_class_init (GtkGestureSingleClass *klass) { GtkEventControllerClass *controller_class = GTK_EVENT_CONTROLLER_CLASS (klass); + GtkGestureClass *gesture_class = GTK_GESTURE_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = gtk_gesture_single_get_property; object_class->set_property = gtk_gesture_single_set_property; - controller_class->reset = gtk_gesture_single_reset; controller_class->handle_event = gtk_gesture_single_handle_event; + gesture_class->cancel = gtk_gesture_single_cancel; + /** * GtkGestureSingle:touch-only: *