From d7884d077d5985a9c653c150cb04bf33e7560415 Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 16 Jun 2024 02:40:29 +0200 Subject: fix(gjs): css, class_name setter --- gjs/src/astalify.ts | 28 ++++++++++++++++++++++------ gjs/src/widgets.ts | 20 ++++++++++---------- 2 files changed, 32 insertions(+), 16 deletions(-) (limited to 'gjs/src') diff --git a/gjs/src/astalify.ts b/gjs/src/astalify.ts index d7f52fa..6e5e5b5 100644 --- a/gjs/src/astalify.ts +++ b/gjs/src/astalify.ts @@ -1,5 +1,5 @@ import Binding, { kebabify, snakeify, type Connectable, type Subscribable } from "./binding.js" -import { Astal, Gtk } from "./imports.js" +import { Astal, Gtk, Gdk } from "./imports.js" import { execAsync } from "./process.js" import Variable from "./variable.js" @@ -128,11 +128,6 @@ function ctor(self: any, config: any = {}, children: any[] = []) { }, []) Object.assign(self, props) - Object.assign(self, { - hook(obj: any, sig: any, callback: any) { - return hook(self, obj, sig, callback) - }, - }) for (const [signal, callback] of onHandlers) { if (typeof callback === "function") { @@ -174,21 +169,37 @@ function ctor(self: any, config: any = {}, children: any[] = []) { function proxify< C extends { new(...args: any[]): any }, >(klass: C) { + klass.prototype.hook = function (obj: any, sig: any, callback: any) { + return hook(this, obj, sig, callback) + } + Object.defineProperty(klass.prototype, "className", { get() { return Astal.widget_get_class_names(this).join(" ") }, set(v) { Astal.widget_set_class_names(this, v.split(/\s+/)) }, }) + klass.prototype.set_class_name = function (name: string) { + this.className = name + } + Object.defineProperty(klass.prototype, "css", { get() { return Astal.widget_get_css(this) }, set(v) { Astal.widget_set_css(this, v) }, }) + klass.prototype.set_css = function (css: string) { + this.css = css + } + Object.defineProperty(klass.prototype, "cursor", { get() { return Astal.widget_get_cursor(this) }, set(v) { Astal.widget_set_cursor(this, v) }, }) + klass.prototype.set_cursor = function (cursor: string) { + this.cursor = cursor + } + const proxy = new Proxy(klass, { construct(_, [conf, ...children]) { const self = new klass @@ -243,6 +254,11 @@ export type ConstructProps< }> & { onDestroy?: (self: Widget) => unknown onDraw?: (self: Widget) => unknown + onKeyPressEvent?: (self: Widget, event: Gdk.Event) => unknown + onKeyReleaseEvent?: (self: Widget, event: Gdk.Event) => unknown + onButtonPressEvent?: (self: Widget, event: Gdk.Event) => unknown + onButtonReleaseEvent?: (self: Widget, event: Gdk.Event) => unknown + onRealize?: (self: Widget) => unknown setup?: (self: Widget) => void } diff --git a/gjs/src/widgets.ts b/gjs/src/widgets.ts index c731b02..e363da0 100644 --- a/gjs/src/widgets.ts +++ b/gjs/src/widgets.ts @@ -12,11 +12,11 @@ export type BoxProps = ConstructProps(Astal.Button) export type ButtonProps = ConstructProps // CenterBox @@ -41,11 +41,11 @@ export type EntryProps = ConstructProps(Astal.EventBox) export type EventBoxProps = ConstructProps // TODO: Fixed -- cgit v1.2.3