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



commit 0fb7266945168c34aa051ad5a467469f861d5e6d
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        |   19 +++++++++++++++----
 gtk/gtkscrolledwindow.c |   14 ++++----------
 2 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index d9bb937..924b9ce 100644
--- a/gtk/gtkgesture.c
+++ b/gtk/gtkgesture.c
@@ -268,7 +268,9 @@ _gtk_gesture_check_recognized (GtkGesture       *gesture,
 
   current_n_points = _gtk_gesture_effective_n_points (gesture);
 
-  if (priv->recognized && current_n_points != priv->n_points)
+  if (priv->recognized &&
+      (current_n_points != priv->n_points ||
+       g_hash_table_size (priv->points) != priv->n_points))
     _gtk_gesture_set_recognized (gesture, FALSE, sequence);
   else if (!priv->recognized &&
            current_n_points == priv->n_points &&
@@ -351,6 +353,7 @@ _gtk_gesture_update_point (GtkGesture     *gesture,
   GdkWindow *widget_window;
   GtkGesturePrivate *priv;
   GdkDevice *device;
+  gboolean existed;
   PointData *data;
   gdouble x, y;
 
@@ -384,9 +387,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 +410,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..1fc65d9 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -650,19 +650,13 @@ 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);
+  if (!priv->in_drag || !gtk_gesture_handles_sequence (gesture, sequence))
+    gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_DENIED);
 }
 
 static void
@@ -756,7 +750,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]