summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gjs/src/astalify.ts17
-rw-r--r--gjs/src/overrides.ts23
2 files changed, 24 insertions, 16 deletions
diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts
index e46872e..009cc18 100644
--- a/gjs/src/astalify.ts
+++ b/gjs/src/astalify.ts
@@ -1,6 +1,7 @@
import Binding, { kebabify, type Connectable, type Subscribable } from "./binding.js"
import { Astal, Gtk } from "./imports.js"
import { execAsync } from "./process.js"
+import { setChild } from "./overrides.js"
export type Widget<C extends { new(...args: any): Gtk.Widget }> = InstanceType<C> & {
className: string
@@ -42,16 +43,6 @@ function hook(
return self
}
-function setChild(parent: Gtk.Widget, child: Gtk.Widget) {
- if (parent instanceof Gtk.Bin) {
- const rm = parent.get_child()
- if (rm)
- parent.remove(rm)
- }
- if (parent instanceof Gtk.Container)
- parent.add(child)
-}
-
function ctor(self: any, config: any, ...children: Gtk.Widget[]) {
const { setup, child, ...props } = config
props.visible ??= true
@@ -147,12 +138,6 @@ function proxify<
set(v) { Astal.widget_set_cursor(this, v) },
})
- // gjs deprecated the child setter
- Object.defineProperty(klass.prototype, "child", {
- get() { return this.get_child?.() },
- set(v) { setChild(this, v) },
- })
-
const proxy = new Proxy(klass, {
construct(_, [conf, ...children]) {
const self = new klass
diff --git a/gjs/src/overrides.ts b/gjs/src/overrides.ts
new file mode 100644
index 0000000..e3d3df5
--- /dev/null
+++ b/gjs/src/overrides.ts
@@ -0,0 +1,23 @@
+import { Gtk, Astal } from "./imports.js"
+
+export function setChild(parent: Gtk.Widget, child: Gtk.Widget) {
+ if (parent instanceof Gtk.Bin) {
+ const rm = parent.get_child()
+ if (rm)
+ parent.remove(rm)
+ }
+ if (parent instanceof Gtk.Container)
+ parent.add(child)
+}
+
+// gjs fails to map List types?
+Object.defineProperty(Astal.Box.prototype, "children", {
+ get() { return this.get_children() },
+ set(v) { this.set_children(v) },
+})
+
+// gjs deprecated the child setter
+Object.defineProperty(Gtk.Container.prototype, "child", {
+ get() { return this.get_child?.() },
+ set(v) { setChild(this, v) },
+})