53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
|
import style from "./styles/style.scss"
|
||
|
import { App, Gtk } from "astal/gtk4"
|
||
|
import { GLib } from "astal";
|
||
|
|
||
|
import Hyprland from "gi://AstalHyprland";
|
||
|
|
||
|
import QuickSettings from "widget/quick_settings/quick_settings";
|
||
|
import BluetoothWindow from "./widget/quick_settings/bluetooth";
|
||
|
|
||
|
import Launcher from "widget/launcher/launcher";
|
||
|
import Bar from "widget/bar/bar";
|
||
|
|
||
|
const hypr = Hyprland.get_default();
|
||
|
const windows = new Map<number, Gtk.Window[]>();
|
||
|
|
||
|
const setupBars = async (monitor_id: number) => {
|
||
|
const components = [Bar, Launcher, QuickSettings, BluetoothWindow];
|
||
|
|
||
|
const windows = await Promise.all(
|
||
|
components.map(item => Promise.resolve(item(monitor_id)) as Promise<Gtk.Window>)
|
||
|
);
|
||
|
|
||
|
return windows;
|
||
|
};
|
||
|
|
||
|
App.start({
|
||
|
css: style,
|
||
|
async main() {
|
||
|
App.add_icons(`${GLib.get_user_data_dir()}/icons/Astal`);
|
||
|
|
||
|
const monitors = App.get_monitors();
|
||
|
for (const monitor of monitors) {
|
||
|
const index = monitors.indexOf(monitor);
|
||
|
windows.set(index, await setupBars(index));
|
||
|
|
||
|
hypr.connect("monitor-added", async (_, monitor: Hyprland.Monitor) => {
|
||
|
if (!windows.has(monitor.id)) windows.set(monitor.id, await setupBars(monitor.id))
|
||
|
});
|
||
|
|
||
|
hypr.connect("monitor-removed", (_, monitor_id: number) => {
|
||
|
const monitorWindows = windows.get(monitor_id)
|
||
|
if (monitorWindows) {
|
||
|
for (const monitorWindow of monitorWindows) {
|
||
|
monitorWindow.destroy();
|
||
|
};
|
||
|
|
||
|
windows.delete(monitor_id);
|
||
|
};
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
})
|