[gnome-shell] st: Translate StBoxLayoutChild properties to ClutterBoxChild



commit 144f7d6813a9c2e43bc2b17055a5337db97d05d3
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Jul 2 23:08:10 2013 +0200

    st: Translate StBoxLayoutChild properties to ClutterBoxChild
    
    With StBoxLayout using the Clutter layout manager, it will now respect
    actors' expand/align properties. However for the change to be transparent,
    we need to support the existing child meta properties as well. Do
    this by simply translating them to the corresponding ClutterBoxChild
    properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703810

 src/st/st-box-layout-child.c |   89 +++++++++++++++++++++++++++++++----------
 src/st/st-box-layout-child.h |    7 +--
 2 files changed, 69 insertions(+), 27 deletions(-)
---
diff --git a/src/st/st-box-layout-child.c b/src/st/st-box-layout-child.c
index 4a022b3..71a30d8 100644
--- a/src/st/st-box-layout-child.c
+++ b/src/st/st-box-layout-child.c
@@ -45,6 +45,16 @@ enum
   PROP_Y_ALIGN
 };
 
+static ClutterLayoutMeta *
+get_layout_meta (StBoxLayoutChild *self)
+{
+  ClutterChildMeta *meta = CLUTTER_CHILD_META (self);
+  ClutterActor *actor = clutter_child_meta_get_actor (meta);
+  ClutterContainer *container = clutter_child_meta_get_container (meta);
+  ClutterLayoutManager *layout = clutter_actor_get_layout_manager (CLUTTER_ACTOR (container));
+  return clutter_layout_manager_get_child_meta (layout, container, actor);
+}
+
 static void
 st_box_layout_child_get_property (GObject    *object,
                                   guint       property_id,
@@ -52,23 +62,40 @@ st_box_layout_child_get_property (GObject    *object,
                                   GParamSpec *pspec)
 {
   StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
+  GObject *meta = G_OBJECT (get_layout_meta (child));
+  gboolean expand, fill;
+  ClutterBoxAlignment layout_align;
+  StAlign align;
 
   switch (property_id)
     {
     case PROP_EXPAND:
-      g_value_set_boolean (value, child->expand);
+      g_object_get (meta, "expand", &expand, NULL);
+      g_value_set_boolean (value, expand);
       break;
     case PROP_X_FILL:
-      g_value_set_boolean (value, child->x_fill);
+      g_object_get (meta, "x-fill", &fill, NULL);
+      g_value_set_boolean (value, fill);
       break;
     case PROP_Y_FILL:
-      g_value_set_boolean (value, child->y_fill);
+      g_object_get (meta, "y-fill", &fill, NULL);
+      g_value_set_boolean (value, fill);
       break;
     case PROP_X_ALIGN:
-      g_value_set_enum (value, child->x_align);
-      break;
     case PROP_Y_ALIGN:
-      g_value_set_enum (value, child->y_align);
+      g_object_get (meta, g_param_spec_get_name (pspec), &layout_align, NULL);
+      switch (layout_align)
+        {
+        case CLUTTER_BOX_ALIGNMENT_START:
+          align = ST_ALIGN_START;
+          break;
+        case CLUTTER_BOX_ALIGNMENT_CENTER:
+          align = ST_ALIGN_MIDDLE;
+          break;
+        case CLUTTER_BOX_ALIGNMENT_END:
+          align = ST_ALIGN_END;
+        }
+      g_value_set_enum (value, align);
       break;
 
     default:
@@ -83,31 +110,56 @@ st_box_layout_child_set_property (GObject      *object,
                                   GParamSpec   *pspec)
 {
   StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
-  StBoxLayout *box = ST_BOX_LAYOUT (CLUTTER_CHILD_META (object)->container);
+  GObject *meta = G_OBJECT (get_layout_meta (child));
+  ClutterBoxAlignment align;
 
   switch (property_id)
     {
     case PROP_EXPAND:
-      child->expand = g_value_get_boolean (value);
+      g_object_set (meta, "expand", g_value_get_boolean (value), NULL);
       break;
     case PROP_X_FILL:
-      child->x_fill = g_value_get_boolean (value);
+      child->x_fill_set = TRUE;
+      g_object_set (meta, "x-fill", g_value_get_boolean (value), NULL);
       break;
     case PROP_Y_FILL:
-      child->y_fill = g_value_get_boolean (value);
+      child->y_fill_set = TRUE;
+      g_object_set (meta, "y-fill", g_value_get_boolean (value), NULL);
       break;
     case PROP_X_ALIGN:
-      child->x_align = g_value_get_enum (value);
-      break;
     case PROP_Y_ALIGN:
-      child->y_align = g_value_get_enum (value);
+      switch (g_value_get_enum (value))
+        {
+        case ST_ALIGN_START:
+          align = CLUTTER_BOX_ALIGNMENT_START;
+          break;
+        case ST_ALIGN_MIDDLE:
+          align = CLUTTER_BOX_ALIGNMENT_CENTER;
+          break;
+        case ST_ALIGN_END:
+          align = CLUTTER_BOX_ALIGNMENT_END;
+        }
+      g_object_set (meta, g_param_spec_get_name (pspec), align, NULL);
       break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
+}
 
-  clutter_actor_queue_relayout ((ClutterActor*) box);
+static void
+st_box_layout_child_constructed (GObject *object)
+{
+  StBoxLayoutChild *child = ST_BOX_LAYOUT_CHILD (object);
+  GObject *meta = G_OBJECT (get_layout_meta (child));
+
+  if (!child->x_fill_set)
+    g_object_set (meta, "x-fill", TRUE, NULL);
+
+  if (!child->y_fill_set)
+    g_object_set (meta, "y-fill", TRUE, NULL);
+
+  G_OBJECT_CLASS (st_box_layout_child_parent_class)->constructed (object);
 }
 
 static void
@@ -118,6 +170,7 @@ st_box_layout_child_class_init (StBoxLayoutChildClass *klass)
 
   object_class->get_property = st_box_layout_child_get_property;
   object_class->set_property = st_box_layout_child_set_property;
+  object_class->constructed = st_box_layout_child_constructed;
 
 
   pspec = g_param_spec_boolean ("expand", "Expand",
@@ -162,12 +215,4 @@ st_box_layout_child_class_init (StBoxLayoutChildClass *klass)
 static void
 st_box_layout_child_init (StBoxLayoutChild *self)
 {
-  self->expand = FALSE;
-
-  self->x_fill = TRUE;
-  self->y_fill = TRUE;
-
-  self->x_align = ST_ALIGN_MIDDLE;
-  self->y_align = ST_ALIGN_MIDDLE;
 }
-
diff --git a/src/st/st-box-layout-child.h b/src/st/st-box-layout-child.h
index 097da0e..6ff463a 100644
--- a/src/st/st-box-layout-child.h
+++ b/src/st/st-box-layout-child.h
@@ -63,11 +63,8 @@ struct _StBoxLayoutChild
   /*< private >*/
   ClutterChildMeta parent;
 
-  gboolean expand;
-  gboolean x_fill : 1;
-  gboolean y_fill : 1;
-  StAlign x_align;
-  StAlign y_align;
+  gboolean x_fill_set;
+  gboolean y_fill_set;
 };
 
 struct _StBoxLayoutChildClass


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