dotfiles/config/astal/util/hyprland.ts
2025-04-25 17:22:07 +02:00

29 lines
995 B
TypeScript

// ┌ ┐
// │ From https://github.com/Neurarian/matshell │
// └ ┘
import { App, Gdk } from "astal/gtk4";
import Hyprland from "gi://AstalHyprland";
/* Match Hyprland monitor to GDK monitor
THIS MAY NOT WORK AS INTENDED IF YOU HAVE MONITORS OF THE SAME MODEL
I did not find a more elegant solution to this.
On my setup GDK coordinates and hyprland coordinates are flipped,
so I cant match by coordinates. */
export function hyprToGdk(monitor: Hyprland.Monitor): Gdk.Monitor | null {
const monitors = App.get_monitors();
if (!monitors || monitors.length === 0) return null;
for (let gdkmonitor of monitors) {
if (
monitor &&
gdkmonitor &&
monitor.get_name() === gdkmonitor.get_connector()
)
return gdkmonitor;
}
// Default monitor with null safety
return monitors.length > 0 ? monitors[0] : null;
}