import { App, Astal, Gtk } from "astal/gtk3"; import AstalNotifd from "gi://AstalNotifd"; import { notifpopups as config } from "../../config"; import { setupChildClickthrough } from "../utils/widgets"; import Notification from "../widgets/notification"; export default () => ( { const notifd = AstalNotifd.get_default(); const map = new Map(); let notifsOpen = false; self.hook(notifd, "notified", (self, id) => { if (notifsOpen) return; const notification = notifd.get_notification(id); const popup = () as Notification; popup.connect("destroy", () => map.get(notification.id) === popup && map.delete(notification.id)); map.get(notification.id)?.destroyWithAnims(); map.set(notification.id, popup); self.add( event.button === Astal.MouseButton.MIDDLE && notification.dismiss()} // Close on hover lost onHoverLost={() => popup.destroyWithAnims()} > {popup} ); // Limit number of popups if (config.maxPopups > 0 && self.children.length > config.maxPopups) map.values().next().value?.destroyWithAnims(); }); self.hook(notifd, "resolved", (_, id) => map.get(id)?.destroyWithAnims()); self.hook(App, "window-toggled", (_, window) => { if (window.name === "notifications") notifsOpen = window.visible; }); // Change input region to child region so can click through empty space setupChildClickthrough(self); }} /> );