From d2db31ee5e0cc597c1418cc3e0bf6c8aa9382979 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 12 May 2014 17:02:03 +0200 Subject: [PATCH] multipress: Add matching ::released signal This signal will always be paired with a ::pressed signal, unless the sequence is cancelled, or the controller is reset. the n_press argument in the signal always matches the ::press signal one, even if GtkGestureMultiPress::stopped was emitted in between. --- gtk/gtkgesturemultipress.c | 43 ++++++++++++++++++++++++++++++- gtk/gtkgesturemultipressprivate.h | 6 ++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/gtk/gtkgesturemultipress.c b/gtk/gtkgesturemultipress.c index a3af2570cb..5c531c4e51 100644 --- a/gtk/gtkgesturemultipress.c +++ b/gtk/gtkgesturemultipress.c @@ -50,12 +50,14 @@ struct _GtkGestureMultiPressPrivate gdouble initial_press_y; guint double_click_timeout_id; guint n_presses; + guint n_release; guint current_button; guint rect_is_set : 1; }; enum { PRESSED, + RELEASED, STOPPED, LAST_SIGNAL }; @@ -225,7 +227,7 @@ gtk_gesture_multi_press_begin (GtkGesture *gesture, /* Increment later the real counter, just if the gesture is * reset on the pressed handler */ - n_presses = priv->n_presses + 1; + n_presses = priv->n_release = priv->n_presses + 1; g_signal_emit (gesture, signals[PRESSED], 0, n_presses, x, y); @@ -254,7 +256,22 @@ gtk_gesture_multi_press_update (GtkGesture *gesture, _gtk_gesture_multi_press_stop (multi_press); } +static void +gtk_gesture_multi_press_end (GtkGesture *gesture, + GdkEventSequence *sequence) +{ + GtkGestureMultiPress *multi_press; + GtkGestureMultiPressPrivate *priv; + GdkEventSequence *current; + gdouble x, y; + multi_press = GTK_GESTURE_MULTI_PRESS (gesture); + priv = gtk_gesture_multi_press_get_instance_private (multi_press); + current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); + gtk_gesture_get_point (gesture, current, &x, &y); + + g_signal_emit (gesture, signals[RELEASED], 0, priv->n_release, x, y); + priv->n_release = 0; } static void @@ -283,6 +300,7 @@ gtk_gesture_multi_press_class_init (GtkGestureMultiPressClass *klass) gesture_class->check = gtk_gesture_multi_press_check; gesture_class->begin = gtk_gesture_multi_press_begin; gesture_class->update = gtk_gesture_multi_press_update; + gesture_class->end = gtk_gesture_multi_press_end; gesture_class->cancel = gtk_gesture_multi_press_cancel; controller_class->reset = gtk_gesture_multi_press_reset; @@ -306,6 +324,29 @@ gtk_gesture_multi_press_class_init (GtkGestureMultiPressClass *klass) NULL, NULL, NULL, G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE); + + /** + * GtkGestureMultiPress::released: + * @gesture: the object which received the signal + * @n_press: number of press that is paired with this release + * @x: The X coordinate, in widget allocation coordinates + * @y: The Y coordinate, in widget allocation coordinates + * + * This signal is emitted when a button or touch is released. @n_press + * will report the number of press that is paired to this event, note + * that #GtkGestureMultiPress::stopped may have been emitted between the + * press and its release, @n_press will only start over at the next press. + * + * Since: 3.14 + */ + signals[RELEASED] = + g_signal_new ("released", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkGestureMultiPressClass, released), + NULL, NULL, NULL, + G_TYPE_NONE, 3, G_TYPE_INT, + G_TYPE_DOUBLE, G_TYPE_DOUBLE); /** * GtkGestureMultiPress::stopped: * @gesture: the object which received the signal diff --git a/gtk/gtkgesturemultipressprivate.h b/gtk/gtkgesturemultipressprivate.h index 58d400d10d..ae74979633 100644 --- a/gtk/gtkgesturemultipressprivate.h +++ b/gtk/gtkgesturemultipressprivate.h @@ -31,10 +31,14 @@ struct _GtkGestureMultiPressClass { GtkGestureSingleClass parent_class; - gboolean (* pressed) (GtkGestureMultiPress *gesture, + void (* pressed) (GtkGestureMultiPress *gesture, gint n_press, gdouble x, gdouble y); + void (* released) (GtkGestureMultiPress *gesture, + gint n_press, + gdouble x, + gdouble y); void (* stopped) (GtkGestureMultiPress *gesture); /**/