[clutter/wip/carlosg/touchpad-gestures: 6/7] gesture-action: Prepare for ClutterTouchpadGesture implementations



commit 0eb5eb031e3757082add5005ddfba5c59eb5742b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 22 18:34:27 2015 +0200

    gesture-action: Prepare for ClutterTouchpadGesture implementations
    
    The raw signals are delivered on those if touchpad events are received,
    and the gesture is not busy already with touch events.

 clutter/clutter-gesture-action.c |   96 +++++++++++++++++++++++++++++++++++---
 1 files changed, 89 insertions(+), 7 deletions(-)
---
diff --git a/clutter/clutter-gesture-action.c b/clutter/clutter-gesture-action.c
index 6eca26f..df0acb0 100644
--- a/clutter/clutter-gesture-action.c
+++ b/clutter/clutter-gesture-action.c
@@ -93,6 +93,7 @@
 #include "clutter-enum-types.h"
 #include "clutter-marshal.h"
 #include "clutter-private.h"
+#include "clutter-touchpad-gesture-private.h"
 
 #include <math.h>
 
@@ -127,6 +128,7 @@ struct _ClutterGestureActionPrivate
   float distance_x, distance_y;
 
   guint in_gesture : 1;
+  guint touchpad   : 1;
 };
 
 enum
@@ -364,7 +366,7 @@ stage_captured_event_cb (ClutterActor         *stage,
   gint position;
   float threshold_x, threshold_y;
   gboolean return_value;
-  GesturePoint *point;
+  GesturePoint *point = NULL;
   ClutterEventType event_type;
 
   event_type = clutter_event_type (event);
@@ -372,10 +374,16 @@ stage_captured_event_cb (ClutterActor         *stage,
       event_type != CLUTTER_TOUCH_UPDATE &&
       event_type != CLUTTER_TOUCH_END &&
       event_type != CLUTTER_MOTION &&
-      event_type != CLUTTER_BUTTON_RELEASE)
+      event_type != CLUTTER_BUTTON_RELEASE &&
+      event_type != CLUTTER_TOUCHPAD_PINCH_UPDATE &&
+      event_type != CLUTTER_TOUCHPAD_PINCH_END &&
+      event_type != CLUTTER_TOUCHPAD_PINCH_CANCEL &&
+      event_type != CLUTTER_TOUCHPAD_SWIPE_UPDATE &&
+      event_type != CLUTTER_TOUCHPAD_SWIPE_END &&
+      event_type != CLUTTER_TOUCHPAD_SWIPE_CANCEL)
     return CLUTTER_EVENT_PROPAGATE;
 
-  if ((point = gesture_find_point (action, event, &position)) == NULL)
+  if (!priv->touchpad && (point = gesture_find_point (action, event, &position)) == NULL)
     return CLUTTER_EVENT_PROPAGATE;
 
   actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (action));
@@ -479,11 +487,44 @@ stage_captured_event_cb (ClutterActor         *stage,
       }
       break;
 
+    case CLUTTER_TOUCHPAD_PINCH_UPDATE:
+    case CLUTTER_TOUCHPAD_SWIPE_UPDATE:
+      if (priv->touchpad)
+        {
+          g_signal_emit_by_name (action, "touchpad-gesture-update",
+                                 event, &return_value);
+
+          if (return_value)
+            {
+              g_signal_emit_by_name (action, "touchpad-gesture-cancel", event);
+              priv->touchpad = FALSE;
+            }
+        }
+      break;
+
+    case CLUTTER_TOUCHPAD_PINCH_END:
+    case CLUTTER_TOUCHPAD_SWIPE_END:
+      if (priv->touchpad)
+        {
+          g_signal_emit_by_name (action, "touchpad-gesture-end", event);
+          priv->touchpad = FALSE;
+        }
+      break;
+
+    case CLUTTER_TOUCHPAD_PINCH_CANCEL:
+    case CLUTTER_TOUCHPAD_SWIPE_CANCEL:
+      if (priv->touchpad)
+        {
+          g_signal_emit_by_name (action, "touchpad-gesture-cancel", event);
+          priv->touchpad = FALSE;
+        }
+
     default:
       break;
     }
 
-  if (priv->points->len == 0 && priv->stage_capture_id)
+  if (priv->stage_capture_id &&
+      (priv->points->len == 0 && !priv->touchpad))
     {
       g_signal_handler_disconnect (priv->stage, priv->stage_capture_id);
       priv->stage_capture_id = 0;
@@ -499,15 +540,30 @@ actor_captured_event_cb (ClutterActor *actor,
 {
   ClutterGestureActionPrivate *priv = action->priv;
   GesturePoint *point G_GNUC_UNUSED;
+  guint n_points;
 
   if ((clutter_event_type (event) != CLUTTER_BUTTON_PRESS) &&
-      (clutter_event_type (event) != CLUTTER_TOUCH_BEGIN))
+      (clutter_event_type (event) != CLUTTER_TOUCH_BEGIN) &&
+      (clutter_event_type (event) != CLUTTER_TOUCHPAD_PINCH_BEGIN) &&
+      (clutter_event_type (event) != CLUTTER_TOUCHPAD_SWIPE_BEGIN))
     return CLUTTER_EVENT_PROPAGATE;
 
   if (!clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (action)))
     return CLUTTER_EVENT_PROPAGATE;
 
-  point = gesture_register_point (action, event);
+  if (clutter_event_type (event) == CLUTTER_TOUCHPAD_PINCH_BEGIN ||
+      clutter_event_type (event) == CLUTTER_TOUCHPAD_SWIPE_BEGIN)
+    {
+      if (!CLUTTER_IS_TOUCHPAD_GESTURE (action) || priv->in_gesture)
+        return CLUTTER_EVENT_PROPAGATE;
+    }
+  else
+    {
+      if (priv->touchpad)
+        return CLUTTER_EVENT_PROPAGATE;
+
+      point = gesture_register_point (action, event);
+    }
 
   if (priv->stage == NULL)
     priv->stage = clutter_actor_get_stage (actor);
@@ -518,11 +574,37 @@ actor_captured_event_cb (ClutterActor *actor,
                               G_CALLBACK (stage_captured_event_cb),
                               action);
 
+  switch (clutter_event_type (event))
+    {
+    case CLUTTER_TOUCHPAD_PINCH_BEGIN:
+      n_points = 2;
+      break;
+    case CLUTTER_TOUCHPAD_SWIPE_BEGIN:
+      n_points = event->touchpad_swipe.n_fingers;
+      break;
+    default:
+      n_points = priv->points->len;
+      break;
+    }
+
   /* Start the gesture immediately if the gesture has no
    * _TRIGGER_EDGE_AFTER drag threshold. */
-  if ((priv->points->len >= priv->requested_nb_points) &&
+  if ((n_points >= priv->requested_nb_points) &&
       (priv->edge != CLUTTER_GESTURE_TRIGGER_EDGE_AFTER))
     begin_gesture (action, actor);
+  else if ((n_points >= priv->requested_nb_points) &&
+           CLUTTER_IS_TOUCHPAD_GESTURE (action) &&
+           (clutter_event_type (event) == CLUTTER_TOUCHPAD_PINCH_BEGIN ||
+            clutter_event_type (event) == CLUTTER_TOUCHPAD_SWIPE_BEGIN))
+    {
+      /* FIXME: We're entirely bypassing trigger edge and the gesture_prepare vfunc */
+      gboolean propagate;
+
+      g_signal_emit_by_name (action, "touchpad-gesture-begin", event, &propagate);
+
+      if (!propagate)
+        priv->touchpad = TRUE;
+    }
 
   return CLUTTER_EVENT_PROPAGATE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]