[gnome-shell] box-layout: Support replacing layout manager



commit 508e751ffdb5a5356135eea85b80a5be6cc6b764
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Oct 4 03:06:34 2015 +0200

    box-layout: Support replacing layout manager
    
    There is nothing preventing callers from replacing the internal
    layout manager, and as long as the replacement is a (or derives
    from) ClutterBoxLayout, everything should work fine except for
    losing a bit of automatic property mapping - and the latter is
    easily fixable by moving the setup out of the constructor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708472

 src/st/st-box-layout.c |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/src/st/st-box-layout.c b/src/st/st-box-layout.c
index 63e2ff7..8f01b29 100644
--- a/src/st/st-box-layout.c
+++ b/src/st/st-box-layout.c
@@ -563,6 +563,24 @@ layout_notify (GObject    *object,
 }
 
 static void
+on_layout_manager_notify (GObject    *object,
+                          GParamSpec *pspec,
+                          gpointer    user_data)
+{
+  ClutterActor *actor = CLUTTER_ACTOR (object);
+  ClutterLayoutManager *layout = clutter_actor_get_layout_manager (actor);
+
+  g_warn_if_fail (CLUTTER_IS_BOX_LAYOUT (layout));
+
+  if (layout == NULL)
+    return;
+
+  g_signal_connect_swapped (layout, "layout-changed",
+                            G_CALLBACK (clutter_actor_queue_relayout), actor);
+  g_signal_connect (layout, "notify", G_CALLBACK (layout_notify), object);
+}
+
+static void
 st_box_layout_class_init (StBoxLayoutClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -614,14 +632,11 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
 static void
 st_box_layout_init (StBoxLayout *self)
 {
-  ClutterLayoutManager *layout;
-
   self->priv = BOX_LAYOUT_PRIVATE (self);
-  layout = clutter_box_layout_new ();
-  g_signal_connect_swapped (layout, "layout-changed",
-                            G_CALLBACK (clutter_actor_queue_relayout), self);
-  g_signal_connect (layout, "notify", G_CALLBACK (layout_notify), self);
-  clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), layout);
+
+  g_signal_connect (self, "notify::layout-manager",
+                    G_CALLBACK (on_layout_manager_notify), NULL);
+  clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), clutter_box_layout_new ());
 }
 
 /**


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