✨ ags(windows): use astal decorator functions to make the GObject class instead of gjs ones
This commit is contained in:
+38
-26
@@ -8,28 +8,24 @@ import { LogoutMenu } from "./window/LogoutMenu";
|
|||||||
import { FloatingNotifications } from "./window/FloatingNotifications";
|
import { FloatingNotifications } from "./window/FloatingNotifications";
|
||||||
import { AppsWindow } from "./window/AppsWindow";
|
import { AppsWindow } from "./window/AppsWindow";
|
||||||
import AstalHyprland from "gi://AstalHyprland";
|
import AstalHyprland from "gi://AstalHyprland";
|
||||||
import { GObject } from "astal";
|
import { GObject, property, register, signal } from "astal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get open windows / interact with windows(e.g.: close, open or toggle)
|
* Windowing System
|
||||||
|
* Possible actions: getting window states(visible or not), close, open or toggle windows,
|
||||||
|
* registering windows(they are monitored through signals, and their state is changed when needed)
|
||||||
|
* Also contains util functions to create dynamic windows, opening the window only on focused
|
||||||
|
* monitor, or all available monitors!
|
||||||
*/
|
*/
|
||||||
export const Windows = GObject.registerClass({
|
@register({ GTypeName: "Windows" })
|
||||||
GTypeName: "Windows",
|
class WindowsClass extends GObject.Object {
|
||||||
Signals: {
|
|
||||||
"open": { param_types: [ GObject.TYPE_STRING ] },
|
|
||||||
"close": { param_types: [ GObject.TYPE_STRING ] }
|
|
||||||
},
|
|
||||||
Properties: {
|
|
||||||
"open-windows": GObject.ParamSpec.jsobject(
|
|
||||||
"open-windows",
|
|
||||||
"Open Windows",
|
|
||||||
"A Readonly object that stores open GTK+ Windows",
|
|
||||||
GObject.ParamFlags.READABLE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}, class Windows extends GObject.Object {
|
|
||||||
#openWindows: Record<string, Widget.Window | Array<Widget.Window>> = {};
|
#openWindows: Record<string, Widget.Window | Array<Widget.Window>> = {};
|
||||||
static #instance: (Windows | null);
|
private static instance: (WindowsClass | null);
|
||||||
|
|
||||||
|
@signal(String)
|
||||||
|
declare opened: () => string;
|
||||||
|
@signal(String)
|
||||||
|
declare closed: () => string;
|
||||||
|
|
||||||
#windows: Record<string, (() => (Widget.Window | Array<Widget.Window>))> = {
|
#windows: Record<string, (() => (Widget.Window | Array<Widget.Window>))> = {
|
||||||
"bar": this.createWindowForMonitors(Bar),
|
"bar": this.createWindowForMonitors(Bar),
|
||||||
@@ -45,6 +41,8 @@ export const Windows = GObject.registerClass({
|
|||||||
#appConnections: Array<number> = [];
|
#appConnections: Array<number> = [];
|
||||||
|
|
||||||
get windows() { return this.#windows; }
|
get windows() { return this.#windows; }
|
||||||
|
|
||||||
|
@property(Object)
|
||||||
get openWindows(): Record<string, Widget.Window | Array<Widget.Window>> { return this.#openWindows; };
|
get openWindows(): Record<string, Widget.Window | Array<Widget.Window>> { return this.#openWindows; };
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -154,11 +152,11 @@ export const Windows = GObject.registerClass({
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDefault(): Windows {
|
public static getDefault(): WindowsClass {
|
||||||
if(!this.#instance)
|
if(!this.instance)
|
||||||
this.#instance = new Windows();
|
this.instance = new WindowsClass();
|
||||||
|
|
||||||
return this.#instance;
|
return this.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,6 +212,10 @@ export const Windows = GObject.registerClass({
|
|||||||
public getWindows(): Array<(() => (Widget.Window | Array<Widget.Window>))> {
|
public getWindows(): Array<(() => (Widget.Window | Array<Widget.Window>))> {
|
||||||
return Object.values(this.windows);
|
return Object.values(this.windows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getFocusedMonitorId(): (number|null) {
|
||||||
|
return AstalHyprland.get_default().get_monitors().filter(mon => mon.focused)?.[0]?.id ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
public isVisible(name: keyof typeof this.windows): boolean {
|
public isVisible(name: keyof typeof this.windows): boolean {
|
||||||
return Object.hasOwn(this.#openWindows, name) || Object.hasOwn(this.#windowConnections, name);
|
return Object.hasOwn(this.#openWindows, name) || Object.hasOwn(this.#windowConnections, name);
|
||||||
@@ -228,7 +230,7 @@ export const Windows = GObject.registerClass({
|
|||||||
|
|
||||||
this.connectWindow(name);
|
this.connectWindow(name);
|
||||||
|
|
||||||
this.emit("open", name);
|
this.emit("opened", name);
|
||||||
this.notify("open-windows");
|
this.notify("open-windows");
|
||||||
|
|
||||||
if(Array.isArray(openWindows)) {
|
if(Array.isArray(openWindows)) {
|
||||||
@@ -248,13 +250,13 @@ export const Windows = GObject.registerClass({
|
|||||||
|
|
||||||
if(Array.isArray(window)) {
|
if(Array.isArray(window)) {
|
||||||
window.map(win => win.close());
|
window.map(win => win.close());
|
||||||
this.emit("close", name);
|
this.emit("closed", name);
|
||||||
this.notify("open-windows");
|
this.notify("open-windows");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.close();
|
window.close();
|
||||||
this.emit("close", name);
|
this.emit("closed", name);
|
||||||
this.notify("open-windows");
|
this.notify("open-windows");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,4 +273,14 @@ export const Windows = GObject.registerClass({
|
|||||||
this.closeAll();
|
this.closeAll();
|
||||||
openWins.map(name => this.open(name));
|
openWins.map(name => this.open(name));
|
||||||
}
|
}
|
||||||
}).getDefault();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Windowing System
|
||||||
|
* Possible actions: getting window states(visible or not), close, open or toggle windows,
|
||||||
|
* registering windows(they are monitored through signals, and their state is changed when needed)
|
||||||
|
* Also contains util functions to create dynamic windows, opening the window only on focused
|
||||||
|
* monitor, or all available monitors!
|
||||||
|
*/
|
||||||
|
export const Windows = WindowsClass.getDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user