[mutter/wip/carlosg/sanitize-gestures: 84/92] clutter: Add information about event phase in ClutterActions




commit d18a75f88d930c2d4a0f0d2529d4a3100fb7ed3e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jul 16 14:43:04 2021 +0200

    clutter: Add information about event phase in ClutterActions
    
    These will stick to a single phase, instead of juggling capture and
    bubble event handlers to do whatever they want.

 clutter/clutter/clutter-action-private.h | 41 +++++++++++++++++++++++++
 clutter/clutter/clutter-action.c         | 34 +++++++++++++++++++--
 clutter/clutter/clutter-action.h         |  7 +++++
 clutter/clutter/clutter-actor.c          | 52 ++++++++++++++++++++++++--------
 clutter/clutter/clutter-enums.h          |  6 ++++
 5 files changed, 125 insertions(+), 15 deletions(-)
---
diff --git a/clutter/clutter/clutter-action-private.h b/clutter/clutter/clutter-action-private.h
new file mode 100644
index 0000000000..638609b004
--- /dev/null
+++ b/clutter/clutter/clutter-action-private.h
@@ -0,0 +1,41 @@
+/*
+ * Clutter.
+ *
+ * An OpenGL based 'interactive canvas' library.
+ *
+ * Copyright (C) 2021 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ *   Carlos Garnacho <carlosg gnome org>
+ */
+
+#ifndef CLUTTER_ACTION_PRIVATE_H
+#define CLUTTER_ACTION_PRIVATE_H
+
+#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
+#error "Only <clutter/clutter.h> can be included directly."
+#endif
+
+#include <clutter/clutter-action.h>
+
+G_BEGIN_DECLS
+
+void clutter_action_set_phase (ClutterAction     *action,
+                               ClutterEventPhase  phase);
+
+G_END_DECLS
+
+#endif /* CLUTTER_ACTION_PRIVATE_H */
diff --git a/clutter/clutter/clutter-action.c b/clutter/clutter/clutter-action.c
index a3410f184e..edf3760489 100644
--- a/clutter/clutter/clutter-action.c
+++ b/clutter/clutter/clutter-action.c
@@ -44,11 +44,19 @@
 #include "clutter-build-config.h"
 
 #include "clutter-action.h"
-
+#include "clutter-action-private.h"
 #include "clutter-debug.h"
 #include "clutter-private.h"
 
-G_DEFINE_ABSTRACT_TYPE (ClutterAction, clutter_action, CLUTTER_TYPE_ACTOR_META);
+typedef struct _ClutterActionPrivate ClutterActionPrivate;
+
+struct _ClutterActionPrivate
+{
+  ClutterEventPhase phase;
+};
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterAction, clutter_action,
+                                     CLUTTER_TYPE_ACTOR_META)
 
 static void
 clutter_action_class_init (ClutterActionClass *klass)
@@ -59,3 +67,25 @@ static void
 clutter_action_init (ClutterAction *self)
 {
 }
+
+void
+clutter_action_set_phase (ClutterAction     *action,
+                          ClutterEventPhase  phase)
+{
+  ClutterActionPrivate *priv;
+
+  priv = clutter_action_get_instance_private (action);
+  priv->phase = phase;
+}
+
+ClutterEventPhase
+clutter_action_get_phase (ClutterAction *action)
+{
+  ClutterActionPrivate *priv;
+
+  g_return_val_if_fail (CLUTTER_IS_ACTION (action), CLUTTER_PHASE_CAPTURE);
+
+  priv = clutter_action_get_instance_private (action);
+
+  return priv->phase;
+}
diff --git a/clutter/clutter/clutter-action.h b/clutter/clutter/clutter-action.h
index 8e5ea6c30c..8624ce9326 100644
--- a/clutter/clutter/clutter-action.h
+++ b/clutter/clutter/clutter-action.h
@@ -70,6 +70,11 @@ void           clutter_actor_add_action_with_name  (ClutterActor  *self,
                                                     const gchar   *name,
                                                     ClutterAction *action);
 CLUTTER_EXPORT
+void           clutter_actor_add_action_full       (ClutterActor      *self,
+                                                    const char        *name,
+                                                    ClutterEventPhase  phase,
+                                                    ClutterAction     *action);
+CLUTTER_EXPORT
 void           clutter_actor_remove_action         (ClutterActor  *self,
                                                     ClutterAction *action);
 CLUTTER_EXPORT
@@ -86,6 +91,8 @@ void           clutter_actor_clear_actions         (ClutterActor  *self);
 CLUTTER_EXPORT
 gboolean       clutter_actor_has_actions           (ClutterActor  *self);
 
+ClutterEventPhase clutter_action_get_phase (ClutterAction *action);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_ACTION_H__ */
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index 1e495c5b3a..d9c19c569f 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -613,6 +613,7 @@
 #include "clutter-actor-private.h"
 
 #include "clutter-action.h"
+#include "clutter-action-private.h"
 #include "clutter-actor-meta-private.h"
 #include "clutter-animatable.h"
 #include "clutter-color-static.h"
@@ -14665,6 +14666,27 @@ clutter_actor_has_allocation (ClutterActor *self)
          !priv->needs_allocation;
 }
 
+static void
+clutter_actor_add_action_internal (ClutterActor      *self,
+                                   ClutterAction     *action,
+                                   ClutterEventPhase  phase)
+{
+  ClutterActorPrivate *priv;
+
+  priv = self->priv;
+
+  if (priv->actions == NULL)
+    {
+      priv->actions = g_object_new (CLUTTER_TYPE_META_GROUP, NULL);
+      priv->actions->actor = self;
+    }
+
+  clutter_action_set_phase (action, phase);
+  _clutter_meta_group_add_meta (priv->actions, CLUTTER_ACTOR_META (action));
+
+  g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ACTIONS]);
+}
+
 /**
  * clutter_actor_add_action:
  * @self: a #ClutterActor
@@ -14684,22 +14706,10 @@ void
 clutter_actor_add_action (ClutterActor  *self,
                           ClutterAction *action)
 {
-  ClutterActorPrivate *priv;
-
   g_return_if_fail (CLUTTER_IS_ACTOR (self));
   g_return_if_fail (CLUTTER_IS_ACTION (action));
 
-  priv = self->priv;
-
-  if (priv->actions == NULL)
-    {
-      priv->actions = g_object_new (CLUTTER_TYPE_META_GROUP, NULL);
-      priv->actions->actor = self;
-    }
-
-  _clutter_meta_group_add_meta (priv->actions, CLUTTER_ACTOR_META (action));
-
-  g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ACTIONS]);
+  clutter_actor_add_action_internal (self, action, CLUTTER_PHASE_BUBBLE);
 }
 
 /**
@@ -14733,6 +14743,22 @@ clutter_actor_add_action_with_name (ClutterActor  *self,
   clutter_actor_add_action (self, action);
 }
 
+void
+clutter_actor_add_action_full (ClutterActor      *self,
+                               const char        *name,
+                               ClutterEventPhase  phase,
+                               ClutterAction     *action)
+{
+  g_return_if_fail (CLUTTER_IS_ACTOR (self));
+  g_return_if_fail (name != NULL);
+  g_return_if_fail (CLUTTER_IS_ACTION (action));
+  g_return_if_fail (phase == CLUTTER_PHASE_BUBBLE ||
+                    phase == CLUTTER_PHASE_CAPTURE);
+
+  clutter_actor_meta_set_name (CLUTTER_ACTOR_META (action), name);
+  clutter_actor_add_action_internal (self, action, phase);
+}
+
 /**
  * clutter_actor_remove_action:
  * @self: a #ClutterActor
diff --git a/clutter/clutter/clutter-enums.h b/clutter/clutter/clutter-enums.h
index a184d2d6fb..0c889d1482 100644
--- a/clutter/clutter/clutter-enums.h
+++ b/clutter/clutter/clutter-enums.h
@@ -1616,6 +1616,12 @@ typedef enum
   CLUTTER_PREEDIT_RESET_COMMIT,
 } ClutterPreeditResetMode;
 
+typedef enum
+{
+  CLUTTER_PHASE_CAPTURE,
+  CLUTTER_PHASE_BUBBLE,
+} ClutterEventPhase;
+
 G_END_DECLS
 
 #endif /* __CLUTTER_ENUMS_H__ */


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