diff --git a/js/ui/main.js b/js/ui/main.js index 837e5fffb..1f105cb86 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -34,6 +34,28 @@ let recorder = null; let modalCount = 0; let modalActorFocusStack = []; +// "monkey patch" in some varargs ClutterContainer methods; we need +// to do this per-container class since there is no representation +// of interfaces in Javascript +function _patchContainerClass(containerClass) { + // This one is a straightforward mapping of the C method + containerClass.prototype.child_set = function(actor, props) { + let meta = this.get_child_meta(actor); + for (prop in props) + meta[prop] = props[prop]; + }; + + // clutter_container_add() actually is a an add-many-actors + // method. We conveniently, but somewhat dubiously, take the + // this opportunity to make it do something more useful. + containerClass.prototype.add = function(actor, props) { + this.add_actor(actor); + if (props) + this.child_set(actor, props); + }; +} +_patchContainerClass(Nbtk.BoxLayout); + function start() { // Add a binding for "global" in the global JS namespace; (gjs // keeps the web browser convention of having that namespace be