From 1d7c2b1c2643428898ab084279ed64b678613422 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 12 Oct 2012 14:08:38 -0400 Subject: [PATCH] centerLayout: Add some utilities to connect us up to CSS This allows us to automatically adjust the "spacing" property of the layout manager whenever the CSS changes. --- js/ui/centerLayout.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/ui/centerLayout.js b/js/ui/centerLayout.js index 38574fb58..eef124b89 100644 --- a/js/ui/centerLayout.js +++ b/js/ui/centerLayout.js @@ -2,6 +2,39 @@ const Lang = imports.lang; const Clutter = imports.gi.Clutter; +const St = imports.gi.St; + +function connectLayoutManager(layoutManager, styleChanged) { + let widget, styleChangedId; + + function _styleChanged() { + let themeNode = widget.get_theme_node(); + styleChanged(themeNode, widget); + } + + function actorChanged() { + if (widget) { + widget.disconnect(styleChangedId); + styleChangedId = 0; + } + + let actor = layoutManager.get_actor(); + if (actor && actor instanceof St.Widget) { + widget = actor; + styleChangedId = widget.connect('style-changed', _styleChanged); + _styleChanged(); + } + } + + layoutManager.connect('notify::actor', actorChanged); + return layoutManager; +} + +function connectSpacing(layoutManager) { + return connectLayoutManager(layoutManager, function(themeNode, widget) { + layoutManager.spacing = themeNode.get_length('spacing'); + }); +} const CenterLayout = new Lang.Class({ Name: 'CenterLayout',