[clutter/wip/carlosg/touchpad-gestures: 7/7] swipe-action: Implement the ClutterTouchpadGesture interface
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/wip/carlosg/touchpad-gestures: 7/7] swipe-action: Implement the ClutterTouchpadGesture interface
- Date: Fri, 22 May 2015 17:16:52 +0000 (UTC)
commit 6e4f018ad3d26b950be6dcc5b3459284628daff0
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri May 22 18:36:07 2015 +0200
swipe-action: Implement the ClutterTouchpadGesture interface
This takes care of the emission on ::swipe/swept under the same
conditions than on touch events.
clutter/clutter-swipe-action.c | 115 +++++++++++++++++++++++++++++++++-------
1 files changed, 96 insertions(+), 19 deletions(-)
---
diff --git a/clutter/clutter-swipe-action.c b/clutter/clutter-swipe-action.c
index 2f022f4..41658ca 100644
--- a/clutter/clutter-swipe-action.c
+++ b/clutter/clutter-swipe-action.c
@@ -46,6 +46,7 @@
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-gesture-action-private.h"
+#include "clutter-touchpad-gesture-private.h"
#include "clutter-marshal.h"
#include "clutter-private.h"
@@ -55,6 +56,7 @@ struct _ClutterSwipeActionPrivate
ClutterSwipeDirection v_direction;
float distance_x, distance_y;
+ float accum_x, accum_y;
};
enum
@@ -67,7 +69,96 @@ enum
static guint swipe_signals[LAST_SIGNAL] = { 0, };
-G_DEFINE_TYPE_WITH_PRIVATE (ClutterSwipeAction, clutter_swipe_action, CLUTTER_TYPE_GESTURE_ACTION)
+static void clutter_swipe_touchpad_gesture_iface_init (ClutterTouchpadGestureIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (ClutterSwipeAction, clutter_swipe_action, CLUTTER_TYPE_GESTURE_ACTION,
+ G_ADD_PRIVATE (ClutterSwipeAction)
+ G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_TOUCHPAD_GESTURE,
+ clutter_swipe_touchpad_gesture_iface_init))
+
+static gboolean
+clutter_swipe_touchpad_begin (ClutterTouchpadGesture *gesture,
+ const ClutterEvent *event)
+{
+ ClutterSwipeActionPrivate *priv = CLUTTER_SWIPE_ACTION (gesture)->priv;
+
+ if (event->type != CLUTTER_TOUCHPAD_SWIPE_BEGIN)
+ return CLUTTER_EVENT_STOP;
+
+ priv->accum_x = priv->accum_y = 0;
+ return CLUTTER_EVENT_PROPAGATE;
+}
+
+static gboolean
+clutter_swipe_touchpad_update (ClutterTouchpadGesture *gesture,
+ const ClutterEvent *event)
+{
+ ClutterSwipeActionPrivate *priv = CLUTTER_SWIPE_ACTION (gesture)->priv;
+
+ if (event->type != CLUTTER_TOUCHPAD_SWIPE_UPDATE)
+ return CLUTTER_EVENT_STOP;
+
+ priv->accum_x += event->touchpad_swipe.dx;
+ priv->accum_y += event->touchpad_swipe.dy;
+ return CLUTTER_EVENT_PROPAGATE;
+}
+
+static void
+finish_gesture (ClutterSwipeAction *action,
+ ClutterActor *actor,
+ gfloat dx,
+ gfloat dy)
+{
+ ClutterSwipeActionPrivate *priv = action->priv;
+ ClutterSwipeDirection direction = 0;
+ gboolean can_emit_swipe;
+
+ if (dx > priv->distance_x)
+ direction |= CLUTTER_SWIPE_DIRECTION_RIGHT;
+ else if (ABS (dx) > priv->distance_x)
+ direction |= CLUTTER_SWIPE_DIRECTION_LEFT;
+
+ if (dy > priv->distance_y)
+ direction |= CLUTTER_SWIPE_DIRECTION_DOWN;
+ else if (ABS (dy) > priv->distance_y)
+ direction |= CLUTTER_SWIPE_DIRECTION_UP;
+
+ /* XXX:2.0 remove */
+ g_signal_emit (action, swipe_signals[SWIPE], 0, actor, direction,
+ &can_emit_swipe);
+ if (can_emit_swipe)
+ g_signal_emit (action, swipe_signals[SWEPT], 0, actor, direction);
+}
+
+static void
+clutter_swipe_touchpad_end (ClutterTouchpadGesture *gesture,
+ const ClutterEvent *event)
+{
+ ClutterSwipeActionPrivate *priv = CLUTTER_SWIPE_ACTION (gesture)->priv;
+
+ if (event->type != CLUTTER_TOUCHPAD_SWIPE_END)
+ return;
+
+ finish_gesture (CLUTTER_SWIPE_ACTION (gesture),
+ clutter_event_get_source (event),
+ priv->accum_x, priv->accum_y);
+ priv->accum_x = priv->accum_y = 0;
+}
+
+static void
+clutter_swipe_touchpad_cancel (ClutterTouchpadGesture *gesture,
+ const ClutterEvent *event)
+{
+}
+
+static void
+clutter_swipe_touchpad_gesture_iface_init (ClutterTouchpadGestureIface *iface)
+{
+ iface->begin = clutter_swipe_touchpad_begin;
+ iface->update = clutter_swipe_touchpad_update;
+ iface->end = clutter_swipe_touchpad_end;
+ iface->cancel = clutter_swipe_touchpad_cancel;
+}
static gboolean
gesture_begin (ClutterGestureAction *action,
@@ -140,11 +231,8 @@ static void
gesture_end (ClutterGestureAction *action,
ClutterActor *actor)
{
- ClutterSwipeActionPrivate *priv = CLUTTER_SWIPE_ACTION (action)->priv;
gfloat press_x, press_y;
gfloat release_x, release_y;
- ClutterSwipeDirection direction = 0;
- gboolean can_emit_swipe;
const ClutterEvent *last_event;
clutter_gesture_action_get_press_coords (action,
@@ -154,21 +242,10 @@ gesture_end (ClutterGestureAction *action,
last_event = clutter_gesture_action_get_last_event (action, 0);
clutter_event_get_coords (last_event, &release_x, &release_y);
- if (release_x - press_x > priv->distance_x)
- direction |= CLUTTER_SWIPE_DIRECTION_RIGHT;
- else if (press_x - release_x > priv->distance_x)
- direction |= CLUTTER_SWIPE_DIRECTION_LEFT;
-
- if (release_y - press_y > priv->distance_y)
- direction |= CLUTTER_SWIPE_DIRECTION_DOWN;
- else if (press_y - release_y > priv->distance_y)
- direction |= CLUTTER_SWIPE_DIRECTION_UP;
-
- /* XXX:2.0 remove */
- g_signal_emit (action, swipe_signals[SWIPE], 0, actor, direction,
- &can_emit_swipe);
- if (can_emit_swipe)
- g_signal_emit (action, swipe_signals[SWEPT], 0, actor, direction);
+ finish_gesture (CLUTTER_SWIPE_ACTION (action),
+ actor,
+ release_x - press_x,
+ release_y - press_y);
}
/* XXX:2.0 remove */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]