[Xfce4-commits] [apps/xfdashboard] 01/01: Implemented xfdashboard_traverse_actor() utility function which iterates through all children beginning at a provided actor. For each child matching the provided selector it calls a callback function.

noreply at xfce.org noreply at xfce.org
Sat Jun 11 15:01:25 CEST 2016


This is an automated email from the git hooks/post-receive script.

nomad pushed a commit to branch master
in repository apps/xfdashboard.

commit 91e4eb81196271f2d5e0d2c4f7352bd1940b0a9e
Author: Stephan Haller <nomad at froevel.de>
Date:   Sat Jun 11 15:01:16 2016 +0200

    Implemented xfdashboard_traverse_actor() utility function which iterates through all children beginning at a provided actor. For each child matching the provided selector it calls a callback function.
    
    This function is mainly useful for plugin which need to find actors to modify them when this plugin was enabled specially after a long the application has already run and stage was setup.
---
 libxfdashboard/utils.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libxfdashboard/utils.h | 35 +++++++++++++++++++
 2 files changed, 126 insertions(+)

diff --git a/libxfdashboard/utils.c b/libxfdashboard/utils.c
index 5202828..bd1457f 100644
--- a/libxfdashboard/utils.c
+++ b/libxfdashboard/utils.c
@@ -405,6 +405,97 @@ ClutterActor* xfdashboard_find_actor_by_name(ClutterActor *inActor, const gchar
 	return(NULL);
 }
 
+static gboolean _xfdashboard_traverse_actor_internal(ClutterActor *inActor,
+														XfdashboardCssSelector *inSelector,
+														XfdashboardTraversalCallback inCallback,
+														gpointer inUserData)
+{
+	ClutterActorIter	iter;
+	ClutterActor		*child;
+	gint				score;
+	gboolean			doContinueTraversal;
+
+	g_return_val_if_fail(CLUTTER_IS_ACTOR(inActor), XFDASHBOARD_TRAVERSAL_CONTINUE);
+	g_return_val_if_fail(XFDASHBOARD_IS_CSS_SELECTOR(inSelector), XFDASHBOARD_TRAVERSAL_CONTINUE);
+	g_return_val_if_fail(inCallback, XFDASHBOARD_TRAVERSAL_CONTINUE);
+
+	/* Check if given actor matches selector if a selector is provided
+	 * otherwise each child will match. Call callback for matching children.
+	 */
+	if(XFDASHBOARD_IS_STYLABLE(inActor))
+	{
+		score=xfdashboard_css_selector_score_matching_stylable_node(inSelector, XFDASHBOARD_STYLABLE(inActor));
+		if(score>=0)
+		{
+			doContinueTraversal=(inCallback)(inActor, inUserData);
+			if(!doContinueTraversal) return(doContinueTraversal);
+		}
+	}
+
+	/* For each child of actor call ourselve recursive */
+	clutter_actor_iter_init(&iter, inActor);
+	while(clutter_actor_iter_next(&iter, &child))
+	{
+		doContinueTraversal=_xfdashboard_traverse_actor_internal(child, inSelector, inCallback, inUserData);
+		if(!doContinueTraversal) return(doContinueTraversal);
+	}
+
+	/* If we get here return and continue traversal */
+	return(XFDASHBOARD_TRAVERSAL_CONTINUE);
+}
+
+/**
+ * xfdashboard_traverse_actor:
+ * @inActor: The root #ClutterActor where to begin traversing
+ * @inSelector: A #XfdashboardCssSelector to filter actors while traversing or
+ *   %NULL to disable filterting
+ * @inCallback: Function to call on matching children
+ * @inUserData: Data to pass to callback function
+ *
+ * Iterates through all children of @inActor recursively beginning at @inRootActor
+ * and for each child matching the selector @inSelector it calls the callback
+ * function @inCallback with the matching child and the user-data at @inUserData.
+ *
+ * If @inRootActor is %NULL it begins at the global stage.
+ *
+ * If the selector @inSelector is %NULL all children will match and the callback
+ * function @inCallback is called for all	 children.
+ *
+ */
+void xfdashboard_traverse_actor(ClutterActor *inRootActor,
+								XfdashboardCssSelector *inSelector,
+								XfdashboardTraversalCallback inCallback,
+								gpointer inUserData)
+{
+	g_return_if_fail(!inRootActor || CLUTTER_IS_ACTOR(inRootActor));
+	g_return_if_fail(!inSelector || XFDASHBOARD_IS_CSS_SELECTOR(inSelector));
+	g_return_if_fail(inCallback);
+
+	/* If root actor where begin traversal is NULL then begin at stage */
+	if(!inRootActor)
+	{
+		ClutterStageManager		*stageManager;
+		ClutterStage			*defaultStage;
+
+		stageManager=clutter_stage_manager_get_default();
+		defaultStage=clutter_stage_manager_get_default_stage(stageManager);
+		inRootActor=CLUTTER_ACTOR(defaultStage);
+	}
+
+	/* If no selector is provider create a seletor matching all actors.
+	 * Otherwise take an extra ref on provided selector to prevent
+	 * destruction when we unref it later.
+	 */
+	if(!inSelector) inSelector=xfdashboard_css_selector_new_from_string("*");
+		else g_object_ref(inSelector);
+
+	/* Do traversal */
+	_xfdashboard_traverse_actor_internal(inRootActor, inSelector, inCallback, inUserData);
+
+	/* Release reference on selector */
+	g_object_unref(inSelector);
+}
+
 /**
  * xfdashboard_get_stage_of_actor:
  * @inActor: The #ClutterActor for which to find the stage
diff --git a/libxfdashboard/utils.h b/libxfdashboard/utils.h
index 4cc3c7a..de79a4f 100644
--- a/libxfdashboard/utils.h
+++ b/libxfdashboard/utils.h
@@ -34,6 +34,7 @@
 #include <libxfdashboard/window-tracker-workspace.h>
 #include <libxfdashboard/stage-interface.h>
 #include <libxfdashboard/stage.h>
+#include <libxfdashboard/css-selector.h>
 
 G_BEGIN_DECLS
 
@@ -91,6 +92,40 @@ void xfdashboard_register_gvalue_transformation_funcs(void);
 
 ClutterActor* xfdashboard_find_actor_by_name(ClutterActor *inActor, const gchar *inName);
 
+/**
+ * XfdashboardTraversalCallback:
+ * @inActor: The actor currently processed and has matched the selector in traversal
+ * @user_data: Data passed to the function, set with xfdashboard_traverse_actor()
+ *
+ * A callback called each time an actor matches the provided css selector
+ * in xfdashboard_traverse_actor().
+ *
+ * Returns: %FALSE if the traversal should be stopped. #XFDASHBOARD_TRAVERSAL_STOP
+ * and #XFDASHBOARD_TRAVERSAL_CONTINUE are more memorable names for the return value.
+ */
+typedef gboolean (*XfdashboardTraversalCallback)(ClutterActor *inActor, gpointer inUserData);
+
+/**
+ * XFDASHBOARD_TRAVERSAL_STOP:
+ *
+ * Use this macro as the return value of a #XfdashboardTraversalCallback to stop
+ * further traversal in xfdashboard_traverse_actor().
+ */
+#define XFDASHBOARD_TRAVERSAL_STOP			(FALSE)
+
+/**
+ * XFDASHBOARD_TRAVERSAL_CONTINUE:
+ *
+ * Use this macro as the return value of a #XfdashboardTraversalCallback to continue
+ * further traversal in xfdashboard_traverse_actor().
+ */
+#define XFDASHBOARD_TRAVERSAL_CONTINUE		(TRUE)
+
+void xfdashboard_traverse_actor(ClutterActor *inRootActor,
+								XfdashboardCssSelector *inSelector,
+								XfdashboardTraversalCallback inCallback,
+								gpointer inUserData);
+
 XfdashboardStageInterface* xfdashboard_get_stage_of_actor(ClutterActor *inActor);
 XfdashboardStage* xfdashboard_get_global_stage_of_actor(ClutterActor *inActor);
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list