ags(notifications): reset notification timeout on replaced + better styles

This commit is contained in:
retrozinndev
2025-03-10 21:18:06 -03:00
parent 19c90581ae
commit 8ae855d6e0
4 changed files with 59 additions and 45 deletions
+9 -26
View File
@@ -3,11 +3,8 @@ import AstalNotifd from "gi://AstalNotifd";
import { bind } from "astal/binding";
import { Notifications } from "../scripts/notifications";
import { NotificationWidget } from "../widget/Notification";
import { timeout } from "astal";
import { VarMap } from "../scripts/varmap";
const connections: Array<number> = [];
const notifWidgets = new VarMap<number, Widget.Revealer>();
export const FloatingNotifications: Widget.Window = new Widget.Window({
namespace: "floating-notifications",
@@ -20,30 +17,11 @@ export const FloatingNotifications: Widget.Window = new Widget.Window({
exclusivity: Astal.Exclusivity.NORMAL,
setup: (window) => {
connections.push(
Notifications.getDefault().connect("notification-added", (_, notif: AstalNotifd.Notification) => {
Notifications.getDefault().connect("notification-added", (_, _notif: AstalNotifd.Notification) => {
!window.is_visible() && window.show();
notifWidgets.set(notif.id, new Widget.Revealer({
revealChild: false,
transitionDuration: 320,
transitionType: Gtk.RevealerTransitionType.SLIDE_RIGHT,
child: NotificationWidget(notif,
() => Notifications.getDefault().removeNotification(notif.id)),
} as Widget.RevealerProps));
notifWidgets.getValue(notif.id)!.revealChild = true;
}),
Notifications.getDefault().connect("notification-removed", (_, id: number) => {
notifWidgets.getValue(id)!.revealChild = false;
timeout(
(notifWidgets.getValue(id)?.get_transition_duration() || 0) + 50,
() => {
notifWidgets.delete(id);
Notifications.getDefault().notifications.length === 0 &&
window.is_visible() && window.hide();
}
);
Notifications.getDefault().connect("notification-removed", (_: Notifications, _id: number) => {
window.is_visible() && _.notifications.length === 0 && window.hide()
})
);
},
@@ -53,6 +31,11 @@ export const FloatingNotifications: Widget.Window = new Widget.Window({
orientation: Gtk.Orientation.VERTICAL,
homogeneous: false,
visible: bind(Notifications.getDefault(), "notifications").as(notifs => notifs.length > 0),
children: bind(notifWidgets).as((map) => [...map.values()].map((revealer) => revealer))
children: bind(Notifications.getDefault(), "notifications").as((notifs) =>
notifs.map((item) =>
NotificationWidget(item,
() => Notifications.getDefault().removeNotification(item))
)
),
} as Widget.BoxProps)
} as Widget.WindowProps);