This commit is contained in:
2025-12-01 06:45:17 -04:00
parent f50cc9928f
commit c8d6711466
17 changed files with 298 additions and 100 deletions
+53 -10
View File
@@ -17,8 +17,10 @@ import AstalHyprland from "gi://AstalHyprland";
export type WindowInstance = { instance?: Astal.Window, connections: Array<number> };
export type WindowData = {
create: () => (Astal.Window | Array<Astal.Window>);
createForMonitor?: (mon: number) => Astal.Window;
instance?: WindowInstance | Array<WindowInstance>;
status?: "open" | "closed";
preferredMonitor?: number | null;
};
@@ -41,12 +43,12 @@ export class Windows extends GObject.Object {
#scope!: ReturnType<typeof getScope>;
#windows: Record<string, WindowData> = {
"bar": { create: this.createWindowForMonitors(Bar) },
"osd": { create: this.createWindowForFocusedMonitor(OSD), },
"control-center": { create: this.createWindowForFocusedMonitor(ControlCenter), },
"center-window": { create: this.createWindowForFocusedMonitor(CenterWindow), },
"logout-menu": { create: this.createWindowForFocusedMonitor(LogoutMenu), },
"floating-notifications": { create: this.createWindowForFocusedMonitor(FloatingNotifications), },
"apps-window": { create: this.createWindowForFocusedMonitor(AppsWindow) }
"osd": { create: this.createWindowForFocusedMonitor(OSD), createForMonitor: this.createWindowForMonitor(OSD) },
"control-center": { create: this.createWindowForFocusedMonitor(ControlCenter), createForMonitor: this.createWindowForMonitor(ControlCenter) },
"center-window": { create: this.createWindowForFocusedMonitor(CenterWindow), createForMonitor: this.createWindowForMonitor(CenterWindow) },
"logout-menu": { create: this.createWindowForFocusedMonitor(LogoutMenu), createForMonitor: this.createWindowForMonitor(LogoutMenu) },
"floating-notifications": { create: this.createWindowForFocusedMonitor(FloatingNotifications), createForMonitor: this.createWindowForMonitor(FloatingNotifications) },
"apps-window": { create: this.createWindowForFocusedMonitor(AppsWindow), createForMonitor: this.createWindowForMonitor(AppsWindow) }
};
@signal(String) windowOpen(_name: string) {}
@@ -244,6 +246,29 @@ export class Windows extends GObject.Object {
}
}
/**
* Creates a window instance for a specific monitor
* @param create generates the window. use provided monitor number in the returned window
* @returns a function that when called with a monitor ID, returns a Astal.Window instance
*/
public createWindowForMonitor(create: (mon: number, scope: ReturnType<typeof getScope>) => GObject.Object|Astal.Window): ((mon: number) => Astal.Window) {
return (mon: number) => {
return createRoot((dispose) => {
const scope = getScope();
const instance = create(mon, scope) as Astal.Window;
const connection = instance.connect("close-request", () => dispose());
this.#scope.onMount(dispose)
scope.onCleanup(() =>
GObject.signal_handler_is_connected(instance, connection) &&
instance.disconnect(connection)
);
return instance;
});
}
}
public addWindow(name: string, create: () => Astal.Window|Array<Astal.Window>): void {
this.#windows[name] = { create };
}
@@ -264,7 +289,7 @@ export class Windows extends GObject.Object {
return this.openWindows.includes(name);
}
public open(name: string, ignoreOpenStatus: boolean = false): void {
public open(name: string, ignoreOpenStatus: boolean = false, monitor?: number | null): void {
if(this.isOpen(name) && !ignoreOpenStatus) return;
const window = this.#windows[name];
@@ -273,8 +298,22 @@ export class Windows extends GObject.Object {
return;
}
// Store preferred monitor if provided
if(monitor !== undefined) {
window.preferredMonitor = monitor;
}
this.#windows[name].status = "open";
const windowInstance = window.create();
// Use createForMonitor if monitor is specified and available, otherwise use default create
let windowInstance: Astal.Window | Array<Astal.Window>;
if(monitor !== null && monitor !== undefined && window.createForMonitor) {
windowInstance = window.createForMonitor(monitor);
} else if(window.preferredMonitor !== null && window.preferredMonitor !== undefined && window.createForMonitor) {
windowInstance = window.createForMonitor(window.preferredMonitor);
} else {
windowInstance = window.create();
}
if(Array.isArray(windowInstance)) {
window.instance = windowInstance.map(wi => {
@@ -309,8 +348,12 @@ export class Windows extends GObject.Object {
this.notify("open-windows");
}
public toggle(name: string): void {
this.isOpen(name) ? this.close(name) : this.open(name);
public toggle(name: string, monitor?: number | null): void {
if(this.isOpen(name)) {
this.close(name);
} else {
this.open(name, false, monitor);
}
}
public closeAll(): void {