From 6d5805e66204caa599a8a2996238adf7931cb95b Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:20:39 +1100 Subject: refactor: move popdowns to own folder And group them like osds --- src/modules/popdowns/notifications.tsx | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/modules/popdowns/notifications.tsx (limited to 'src/modules/popdowns/notifications.tsx') diff --git a/src/modules/popdowns/notifications.tsx b/src/modules/popdowns/notifications.tsx new file mode 100644 index 0000000..bb08c13 --- /dev/null +++ b/src/modules/popdowns/notifications.tsx @@ -0,0 +1,65 @@ +import { bind } from "astal"; +import { Astal, Gtk } from "astal/gtk3"; +import AstalNotifd from "gi://AstalNotifd"; +import Notification from "../../widgets/notification"; +import PopdownWindow from "../../widgets/popdownwindow"; + +const List = () => ( + { + const notifd = AstalNotifd.get_default(); + const map = new Map(); + + const addNotification = (notification: AstalNotifd.Notification) => { + const notif = () as Notification; + notif.connect("destroy", () => map.get(notification.id) === notif && map.delete(notification.id)); + map.get(notification.id)?.destroyWithAnims(); + map.set(notification.id, notif); + + self.pack_end( + event.button === Astal.MouseButton.MIDDLE && notification.dismiss()} + > + {notif} + , + false, + false, + 0 + ); + }; + + notifd + .get_notifications() + .sort((a, b) => a.time - b.time) + .forEach(addNotification); + + self.hook(notifd, "notified", (_, id) => addNotification(notifd.get_notification(id))); + self.hook(notifd, "resolved", (_, id) => map.get(id)?.destroyWithAnims()); + }} + /> +); + +export default () => ( + n.length)} + headerButtons={[ + { + label: "Silence", + onClicked: () => (AstalNotifd.get_default().dontDisturb = !AstalNotifd.get_default().dontDisturb), + className: bind(AstalNotifd.get_default(), "dontDisturb").as(d => (d ? "enabled" : "")), + }, + { + label: "Clear", + onClicked: () => AstalNotifd.get_default().notifications.forEach(n => n.dismiss()), + }, + ]} + emptyIcon="notifications_active" + emptyLabel="All caught up!" + list={} + /> +); -- cgit v1.2.3-freya