From 66fccd94e62e9b18a1a2d2d004159f3bfb0df202 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sun, 22 Sep 2024 12:05:04 -0700 Subject: [PATCH] environment.js: Add some convenience LayoutManager monkey patching (#12394) Add hookup_style() to bind layoutManager properties to CSS properties --- js/ui/environment.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/ui/environment.js b/js/ui/environment.js index 707d45f3c0..d8ae645364 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -46,6 +46,20 @@ function _patchContainerClass(containerClass) { }; } +function _patchLayoutClass(layoutClass, styleProps) { + if (styleProps) + layoutClass.prototype.hookup_style = function(container) { + container.connect('style-changed', () => { + let node = container.get_theme_node(); + for (let prop in styleProps) { + let [found, length] = node.lookup_length(styleProps[prop], false); + if (found) + this[prop] = length; + } + }); + }; +} + function readOnlyError(property) { global.logError(`The ${property} object is read-only.`); }; @@ -279,6 +293,10 @@ function init() { _patchContainerClass(St.BoxLayout); _patchContainerClass(St.Table); + _patchLayoutClass(Clutter.GridLayout, { row_spacing: 'spacing-rows', + column_spacing: 'spacing-columns' }); + _patchLayoutClass(Clutter.BoxLayout, { spacing: 'spacing' }); + // Cache the original toString since it will be overridden for Clutter.Actor GObject.Object.prototype._toString = GObject.Object.prototype.toString; // Add method to determine if a GObject is finalized - needed to prevent accessing