Skip to content

Commit

Permalink
environment.js: Add some convenience LayoutManager monkey patching (#…
Browse files Browse the repository at this point in the history
…12394)

Add hookup_style() to bind layoutManager properties to CSS properties
  • Loading branch information
JosephMcc authored Sep 22, 2024
1 parent f32fbb0 commit 66fccd9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions js/ui/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66fccd9

Please sign in to comment.