2024-12-01 17:05:55 +01:00
|
|
|
import { App, Gdk, Widget } from "astal/gtk3"
|
2024-11-24 12:56:22 +01:00
|
|
|
import style from "./style.scss"
|
|
|
|
import Bar from "./Bar"
|
2024-11-28 21:15:30 +01:00
|
|
|
import Hyprland from "gi://AstalHyprland";
|
2024-11-24 12:56:22 +01:00
|
|
|
import NotificationPopups from "./notifications/NotificationPopups"
|
|
|
|
|
2024-12-01 17:05:55 +01:00
|
|
|
const hyprland = Hyprland.get_default();
|
|
|
|
|
2024-11-28 21:15:30 +01:00
|
|
|
function find_main_monitor(): Hyprland.Monitor {
|
|
|
|
let monitors = hyprland.get_monitors()
|
|
|
|
for (let i = 0; i < monitors.length; i++) {
|
|
|
|
for (const monitor of ["eDP", "DP", "HDMI-A"]) {
|
|
|
|
if (monitors[i].get_name() == monitor + "-" + i) {
|
|
|
|
return monitors[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return monitors[0]
|
|
|
|
}
|
|
|
|
|
2024-12-01 17:05:55 +01:00
|
|
|
function register_windows(monitor: Hyprland.Monitor) {
|
|
|
|
let gtkMonitor = App.get_monitors()[0].get_display().get_monitor_at_point(monitor.get_x(), monitor.get_y())
|
|
|
|
let scale = (monitor.get_width() >= 3000)? 1.2: 1
|
|
|
|
Bar(gtkMonitor, scale)
|
|
|
|
NotificationPopups(gtkMonitor)
|
|
|
|
}
|
|
|
|
|
|
|
|
function switch_to_best_monitor() {
|
|
|
|
let mainMonitor = find_main_monitor()
|
|
|
|
for (var wd of App.get_windows()) {
|
|
|
|
wd.destroy();
|
|
|
|
}
|
|
|
|
register_windows(mainMonitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
hyprland.connect("monitor-added", (_, monitor) => {
|
|
|
|
switch_to_best_monitor()
|
|
|
|
})
|
|
|
|
|
|
|
|
hyprland.connect("monitor-removed", () => {
|
|
|
|
switch_to_best_monitor()
|
|
|
|
})
|
|
|
|
|
2024-11-24 12:56:22 +01:00
|
|
|
App.start({
|
|
|
|
css: style,
|
|
|
|
iconTheme: "Papirus",
|
|
|
|
main() {
|
2024-12-01 17:05:55 +01:00
|
|
|
switch_to_best_monitor()
|
2024-11-24 12:56:22 +01:00
|
|
|
},
|
|
|
|
})
|