From 470d14a7495d3c3f84786c708237a279f04283b6 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 2 Oct 2012 12:56:36 +0200 Subject: [PATCH] swipe: enter into "recognized" state when there is a motion directionality This allows for checking the controller state as events are fed into it without connecting to begin/end signals Signed-off-by: Carlos Garnacho Acked-by: Simon Schampijer --- .../event-controller/sugar-swipe-controller.c | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/sugar3/event-controller/sugar-swipe-controller.c b/src/sugar3/event-controller/sugar-swipe-controller.c index 9acc5661..25456a0b 100644 --- a/src/sugar3/event-controller/sugar-swipe-controller.c +++ b/src/sugar3/event-controller/sugar-swipe-controller.c @@ -46,6 +46,7 @@ struct _SugarSwipeControllerPriv GdkDevice *device; GdkEventSequence *sequence; GArray *event_data; + guint swiping : 1; guint swiped : 1; }; @@ -83,6 +84,7 @@ _sugar_swipe_controller_clear_events (SugarSwipeController *controller) priv->event_data->len > 0) g_array_remove_range (priv->event_data, 0, priv->event_data->len); + priv->swiping = FALSE; priv->swiped = FALSE; } @@ -164,18 +166,18 @@ _sugar_swipe_controller_get_direction (SugarEventData *from, return FALSE; } -static void -_sugar_swipe_controller_check_emit (SugarSwipeController *controller) +static gboolean +_sugar_swipe_controller_get_event_direction (SugarSwipeController *controller, + SugarSwipeDirection *direction) { SugarSwipeControllerPriv *priv; SugarEventData *last, *check; - SugarSwipeDirection direction; gint i; priv = controller->_priv; if (!priv->event_data || priv->event_data->len == 0) - return; + return FALSE; last = &g_array_index (priv->event_data, SugarEventData, priv->event_data->len - 1); @@ -188,11 +190,20 @@ _sugar_swipe_controller_check_emit (SugarSwipeController *controller) break; } - if (_sugar_swipe_controller_get_direction (check, last, &direction)) + return _sugar_swipe_controller_get_direction (check, last, direction); +} + +static void +_sugar_swipe_controller_check_emit (SugarSwipeController *controller) +{ + SugarSwipeControllerPriv *priv; + SugarSwipeDirection direction; + + priv = controller->_priv; + + if (_sugar_swipe_controller_get_event_direction (controller, &direction)) { priv->swiped = TRUE; - g_signal_emit_by_name (G_OBJECT (controller), "began"); - g_object_notify (G_OBJECT (controller), "state"); g_signal_emit (controller, signals[SWIPE_ENDED], 0, direction); g_signal_emit_by_name (G_OBJECT (controller), "ended"); } @@ -204,6 +215,7 @@ sugar_swipe_controller_handle_event (SugarEventController *controller, { SugarSwipeControllerPriv *priv; SugarSwipeController *swipe; + SugarSwipeDirection direction; GdkEventSequence *sequence; gboolean handled = TRUE; GdkDevice *device; @@ -242,6 +254,13 @@ sugar_swipe_controller_handle_event (SugarEventController *controller, break; case GDK_TOUCH_UPDATE: _sugar_swipe_controller_store_event (swipe, event); + + if (_sugar_swipe_controller_get_event_direction (swipe, &direction)) + { + priv->swiping = TRUE; + g_signal_emit_by_name (G_OBJECT (controller), "began"); + g_object_notify (G_OBJECT (controller), "state"); + } break; default: handled = FALSE; @@ -260,7 +279,7 @@ sugar_swipe_controller_get_state (SugarEventController *controller) if (priv->device) { - if (priv->swiped) + if (priv->swiped || priv->swiping) return SUGAR_EVENT_CONTROLLER_STATE_RECOGNIZED; else if (priv->event_data->len > 0) return SUGAR_EVENT_CONTROLLER_STATE_COLLECTING;