[gtk+/gestures: 132/140] gesture: Cancel sequences that make a gesture exceed the number of touches as they happen



commit 0b868b27dfcea2fcf154e7551d80066f373dcead
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 6 15:20:56 2014 +0200

    gesture: Cancel sequences that make a gesture exceed the number of touches as they happen
    
    This makes it possible to track those through gtk_gesture_handles_sequence(),
    without guessing from last event type or sequence state.

 gtk/gtkgesture.c        |   15 ++++++++++++---
 gtk/gtkscrolledwindow.c |   17 +++++------------
 2 files changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index d9bb937..10b10c2 100644
--- a/gtk/gtkgesture.c
+++ b/gtk/gtkgesture.c
@@ -351,6 +351,7 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
   GdkWindow *widget_window;
   GtkGesturePrivate *priv;
   GdkDevice *device;
+  gboolean existed;
   PointData *data;
   gdouble x, y;
 
@@ -384,9 +385,9 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
     return FALSE;
 
   sequence = gdk_event_get_event_sequence (event);
-
-  if (!g_hash_table_lookup_extended (priv->points, sequence,
-                                     NULL, (gpointer *) &data))
+  existed = g_hash_table_lookup_extended (priv->points, sequence,
+                                          NULL, (gpointer *) &data);
+  if (!existed)
     {
       if (!add)
         return FALSE;
@@ -407,6 +408,14 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
   data->event = gdk_event_copy (event);
   _update_widget_coordinates (gesture, data);
 
+  /* Deny the sequence right away if the expected
+   * number of points is exceeded, so this sequence
+   * can be tracked with gtk_gesture_handles_sequence().
+   */
+  if (!existed && g_hash_table_size (priv->points) > priv->n_points)
+    gtk_gesture_set_sequence_state (gesture, sequence,
+                                    GTK_EVENT_SEQUENCE_DENIED);
+
   return TRUE;
 }
 
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 157fb5c..2c3b3ff 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -650,19 +650,12 @@ scrolled_window_drag_update_cb (GtkScrolledWindow *scrolled_window,
 
 static void
 scrolled_window_drag_end_cb (GtkScrolledWindow *scrolled_window,
-                             gdouble            offset_x,
-                             gdouble            offset_y,
+                             GdkEventSequence  *sequence,
                              GtkGesture        *gesture)
 {
-  GtkScrolledWindowPrivate *priv = scrolled_window->priv;
-  GdkEventSequence *current, *last;
-
-  current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
-  last = gtk_gesture_get_last_updated_sequence (gesture);
-
-  if (!priv->in_drag || current != last)
-    gtk_gesture_set_sequence_state (gesture, current,
-                                    GTK_EVENT_SEQUENCE_DENIED);
+  /* Cancel the gesture group if any extra touches came in */
+  if (!gtk_gesture_handles_sequence (gesture, sequence))
+    gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_DENIED);
 }
 
 static void
@@ -756,7 +749,7 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
   g_signal_connect_swapped (priv->drag_gesture, "drag-update",
                             G_CALLBACK (scrolled_window_drag_update_cb),
                             scrolled_window);
-  g_signal_connect_swapped (priv->drag_gesture, "drag-end",
+  g_signal_connect_swapped (priv->drag_gesture, "end",
                             G_CALLBACK (scrolled_window_drag_end_cb),
                             scrolled_window);
 


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