summaryrefslogtreecommitdiff
path: root/gtk/gtkgesture.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2015-07-09 19:11:04 +0200
committerCarlos Garnacho <carlosg@gnome.org>2015-08-12 23:20:25 +0200
commit67ae7322e9569d106328ddab39296ffc9f64961a (patch)
treeaef64ef53c701a4eda22b2a53290a796d152c5f6 /gtk/gtkgesture.c
parent97e67e21a1e21215f1191a5be1f2fb102fb2d6a0 (diff)
downloadgtk+-67ae7322e9569d106328ddab39296ffc9f64961a.tar.gz
gtkgesture: Refactor n-points querying into a single function
Along the code, we're basically asking for 1) the total count of touchpoints, and 2) the number of active touchpoints (not denied nor ended). Wrap both usecases into a _gtk_gesture_get_n_physical_touchpoints(), and replace all occurrences.
Diffstat (limited to 'gtk/gtkgesture.c')
-rw-r--r--gtk/gtkgesture.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index e6eefafc9e..04c169e1aa 100644
--- a/gtk/gtkgesture.c
+++ b/gtk/gtkgesture.c
@@ -223,7 +223,8 @@ gtk_gesture_finalize (GObject *object)
}
static guint
-_gtk_gesture_effective_n_points (GtkGesture *gesture)
+_gtk_gesture_get_n_touch_points (GtkGesture *gesture,
+ gboolean only_active)
{
GtkGesturePrivate *priv;
GHashTableIter iter;
@@ -235,9 +236,10 @@ _gtk_gesture_effective_n_points (GtkGesture *gesture)
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &data))
{
- if (data->state == GTK_EVENT_SEQUENCE_DENIED ||
- data->event->type == GDK_TOUCH_END ||
- data->event->type == GDK_BUTTON_RELEASE)
+ if (only_active &&
+ (data->state == GTK_EVENT_SEQUENCE_DENIED ||
+ data->event->type == GDK_TOUCH_END ||
+ data->event->type == GDK_BUTTON_RELEASE))
continue;
n_points++;
@@ -246,6 +248,13 @@ _gtk_gesture_effective_n_points (GtkGesture *gesture)
return n_points;
}
+static guint
+_gtk_gesture_get_n_physical_points (GtkGesture *gesture,
+ gboolean only_active)
+{
+ return _gtk_gesture_get_n_touch_points (gesture, only_active);
+}
+
static gboolean
gtk_gesture_check_impl (GtkGesture *gesture)
{
@@ -253,7 +262,7 @@ gtk_gesture_check_impl (GtkGesture *gesture)
guint n_points;
priv = gtk_gesture_get_instance_private (gesture);
- n_points = _gtk_gesture_effective_n_points (gesture);
+ n_points = _gtk_gesture_get_n_physical_points (gesture, TRUE);
return n_points == priv->n_points;
}
@@ -297,12 +306,13 @@ static gboolean
_gtk_gesture_has_matching_touchpoints (GtkGesture *gesture)
{
GtkGesturePrivate *priv = gtk_gesture_get_instance_private (gesture);
- guint current_n_points;
+ guint active_n_points, current_n_points;
- current_n_points = _gtk_gesture_effective_n_points (gesture);
+ current_n_points = _gtk_gesture_get_n_physical_points (gesture, FALSE);
+ active_n_points = _gtk_gesture_get_n_physical_points (gesture, TRUE);
- return (current_n_points == priv->n_points &&
- g_hash_table_size (priv->points) == priv->n_points);
+ return (active_n_points == priv->n_points &&
+ current_n_points == priv->n_points);
}
static gboolean
@@ -483,7 +493,7 @@ _gtk_gesture_update_point (GtkGesture *gesture,
* 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)
+ if (!existed && _gtk_gesture_get_n_physical_points (gesture, FALSE) > priv->n_points)
gtk_gesture_set_sequence_state (gesture, sequence,
GTK_EVENT_SEQUENCE_DENIED);
@@ -1305,7 +1315,7 @@ gtk_gesture_is_active (GtkGesture *gesture)
{
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
- return _gtk_gesture_effective_n_points (gesture) != 0;
+ return _gtk_gesture_get_n_physical_points (gesture, TRUE) != 0;
}
/**