From f13c86d65168b03769de29524bf2229c815715ab Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 25 Jun 2014 12:31:58 +0200 Subject: [PATCH] gesture-tracker: Implement threshold-based sequence rejection If a sequence moves past a certain distance without being used by a gesture, reject it so clients may see and react to it ASAP. This makes gestures to be began by initially quasi-static touchpoints, in addition to quasi-simultaneous. --- src/core/gesture-tracker.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/gesture-tracker.c b/src/core/gesture-tracker.c index 5fd657909..bbb9187cc 100644 --- a/src/core/gesture-tracker.c +++ b/src/core/gesture-tracker.c @@ -23,6 +23,8 @@ #include "gesture-tracker-private.h" #include "meta-surface-actor.h" +#define DISTANCE_THRESHOLD 30 + typedef struct _MetaGestureTrackerPrivate MetaGestureTrackerPrivate; typedef struct _GestureActionData GestureActionData; typedef struct _MetaSequenceInfo MetaSequenceInfo; @@ -33,6 +35,8 @@ struct _MetaSequenceInfo ClutterEventSequence *sequence; MetaSequenceState state; guint autodeny_timeout_id; + gfloat start_x; + gfloat start_y; }; struct _GestureActionData @@ -185,6 +189,8 @@ meta_sequence_info_new (MetaGestureTracker *tracker, info->state = META_SEQUENCE_NONE; info->autodeny_timeout_id = g_timeout_add (ms, autodeny_sequence, info); + clutter_event_get_coords (event, &info->start_x, &info->start_y); + return info; } @@ -397,6 +403,7 @@ meta_gesture_tracker_handle_event (MetaGestureTracker *tracker, ClutterEventSequence *sequence; MetaSequenceInfo *info; ClutterActor *stage; + gfloat x, y; sequence = clutter_event_get_event_sequence (event); @@ -447,6 +454,18 @@ meta_gesture_tracker_handle_event (MetaGestureTracker *tracker, meta_gesture_tracker_untrack_stage (tracker); break; case CLUTTER_TOUCH_UPDATE: + info = g_hash_table_lookup (priv->sequences, sequence); + + if (!info) + return FALSE; + + clutter_event_get_coords (event, &x, &y); + + if (info->state == META_SEQUENCE_NONE && + (ABS (info->start_x - x) > DISTANCE_THRESHOLD || + ABS (info->start_y - y) > DISTANCE_THRESHOLD)) + meta_gesture_tracker_set_sequence_state (tracker, sequence, + META_SEQUENCE_REJECTED); break; default: return FALSE;