nixos-configs/modules/ags/config/ts/lib.ts
matt1432 8abca33123
All checks were successful
Discord / discord commits (push) Has been skipped
feat(ags): use hyprland desc for monitor names in the code
2024-06-19 12:54:01 -04:00

32 lines
1,014 B
TypeScript

const Hyprland = await Service.import('hyprland');
import Gdk from 'gi://Gdk?version=3.0';
export const get_hyprland_monitor_desc = (monitor: Gdk.Monitor): string => {
const manufacturer = monitor.manufacturer?.replace(',', '');
const model = monitor.model?.replace(',', '');
const start = `${manufacturer} ${model}`;
return `desc:${Hyprland.monitors.find((m) => m.description.startsWith(start))?.description}`;
};
export const get_gdkmonitor_from_desc = (desc: string): Gdk.Monitor => {
const display = Gdk.Display.get_default();
for (let m = 0; m < (display?.get_n_monitors() ?? 0); m++) {
const monitor = display?.get_monitor(m);
if (monitor && desc === get_hyprland_monitor_desc(monitor)) {
return monitor;
}
}
throw Error(`Monitor ${desc} not found`);
};
export const get_monitor_desc_from_id = (id: number): string => {
const monitor = Hyprland.monitors.find((m) => m.id === id);
return `desc:${monitor?.description}`;
};