[gnome-shell] shell-util: Add helper to hide actors from pick



commit 1c8955b34af959dd4ba65e911cc581eb115904eb
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Nov 17 10:59:53 2010 +0100

    shell-util: Add helper to hide actors from pick
    
    At times it is desireable to hide actors from being picked even
    with a mode of CLUTTER_PICK_ALL.
    
    Currently we use a pattern of
        clutter_actor_hide();
        clutter_stage_get_actor_at_pos();
        clutter_actor_show();
    in these cases, which gets hideous if the actor we want to exclude
    from the pick is located in another module.
    
    A more elegant solution is to connect a handler to the ::pick signal,
    which stops further emission.
    
    Credit for the idea goes to Owen Taylor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=634560

 src/shell-util.c |   40 ++++++++++++++++++++++++++++++++++++++++
 src/shell-util.h |    2 ++
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-util.c b/src/shell-util.c
index 1a643c9..86cd3a4 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -399,3 +399,43 @@ shell_util_icon_from_string (const char *string, GError **error)
 {
   return g_icon_new_for_string (string, error);
 }
+
+static void
+stop_pick (ClutterActor       *actor,
+           const ClutterColor *color)
+{
+  g_signal_stop_emission_by_name (actor, "pick");
+}
+
+/**
+ * shell_util_set_hidden_from_pick:
+ * @actor: A #ClutterActor
+ * @hidden: Whether @actor should be hidden from pick
+ *
+ * If @hidden is %TRUE, hide @actor from pick even with a mode of
+ * %CLUTTER_PICK_ALL; if @hidden is %FALSE, unhide @actor.
+ */
+void
+shell_util_set_hidden_from_pick (ClutterActor *actor,
+                                 gboolean      hidden)
+{
+  gpointer existing_handler_data;
+
+  existing_handler_data = g_object_get_data (G_OBJECT (actor),
+                                             "shell-stop-pick");
+  if (hidden)
+    {
+      if (existing_handler_data != NULL)
+        return;
+      g_signal_connect (actor, "pick", G_CALLBACK (stop_pick), NULL);
+      g_object_set_data (G_OBJECT (actor),
+                         "shell-stop-pick", GUINT_TO_POINTER (1));
+    }
+  else
+    {
+      if (existing_handler_data == NULL)
+        return;
+      g_signal_handlers_disconnect_by_func (actor, stop_pick, NULL);
+      g_object_set_data (G_OBJECT (actor), "shell-stop-pick", NULL);
+    }
+}
diff --git a/src/shell-util.h b/src/shell-util.h
index f523d44..e655905 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -4,12 +4,14 @@
 #define __SHELL_UTIL_H__
 
 #include <gio/gio.h>
+#include <clutter/clutter.h>
 
 G_BEGIN_DECLS
 
 char *shell_util_get_label_for_uri (const char *text_uri);
 GIcon *shell_util_get_icon_for_uri (const char *text_uri);
 GIcon *shell_util_icon_from_string (const char *string, GError **error);
+void   shell_util_set_hidden_from_pick (ClutterActor *actor, gboolean hidden);
 
 G_END_DECLS
 



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