From dd7b67e8119484fe5673e36bda7a9fa1f3a0d63c Mon Sep 17 00:00:00 2001 From: matt1432 Date: Mon, 15 Apr 2024 09:31:52 -0400 Subject: [PATCH] refactor(ags popups): use setters properly and add on_* func props --- modules/ags/config/ts/misc/popup.ts | 60 +++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/modules/ags/config/ts/misc/popup.ts b/modules/ags/config/ts/misc/popup.ts index 0a5f8a6..177feca 100644 --- a/modules/ags/config/ts/misc/popup.ts +++ b/modules/ags/config/ts/misc/popup.ts @@ -24,26 +24,54 @@ export class PopupWindow< }); } - #close_on_unfocus: CloseType; - #transition: HyprTransition; + + private _close_on_unfocus: CloseType; get close_on_unfocus() { - return this.#close_on_unfocus; + return this._close_on_unfocus; } set close_on_unfocus(value: CloseType) { - this.#close_on_unfocus = value; + this._close_on_unfocus = value; } + + private _transition = 'unset' as HyprTransition; + get transition() { - return this.#transition; + return this._transition; } set transition(t: HyprTransition) { - this.#transition = t; - Hyprland.messageAsync(`keyword layerrule animation ${t}, ${this.name}`); + Hyprland.messageAsync( + `keyword layerrule animation ${t}, ${this.name}`, + ).catch(logError); + this._transition = t; } + + private _on_open: (self: PopupWindow) => void; + + get on_open() { + return this._on_open; + } + + set on_open(fun: (self: PopupWindow) => void) { + this._on_open = fun; + } + + + private _on_close: (self: PopupWindow) => void; + + get on_close() { + return this._on_close; + } + + set on_close(fun: (self: PopupWindow) => void) { + this._on_close = fun; + } + + constructor({ transition = 'slide top', on_open = () => {/**/}, @@ -70,29 +98,29 @@ export class PopupWindow< App.openWindow(`win-${name}`); } + // Make sure Hyprland got the message + this.transition = transition; + // This connection should always run only once App.disconnect(id); }); - - Hyprland.messageAsync( - `keyword layerrule animation ${transition}, win-${name}`, - ); }, }); + this._close_on_unfocus = close_on_unfocus; + this._on_open = on_open; + this._on_close = on_close; + this.hook(App, (_, currentName, isOpen) => { if (currentName === `win-${name}`) { if (isOpen) { - on_open(this); + this.on_open(this); } else { - on_close(this); + this.on_close(this); } } }); - - this.#close_on_unfocus = close_on_unfocus; - this.#transition = transition; } set_x_pos(