Commit 5c9f4bd0 authored by Carlos Garnacho's avatar Carlos Garnacho

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.
parent 134acf3f
......@@ -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,
return TRUE;
......@@ -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,
if (!priv->in_drag || !gtk_gesture_handles_sequence (gesture, sequence))
gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_DENIED);
static void
......@@ -759,7 +753,7 @@ gtk_scrolled_window_init (GtkScrolledWindow *scrolled_window)
g_signal_connect_swapped (priv->drag_gesture, "drag-update",
G_CALLBACK (scrolled_window_drag_update_cb),
g_signal_connect_swapped (priv->drag_gesture, "drag-end",
g_signal_connect_swapped (priv->drag_gesture, "end",
G_CALLBACK (scrolled_window_drag_end_cb),
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment