✨ ags: add ask popup, make notifications work(finally :3) and more improvements
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { Astal, Gtk, Widget } from "astal/gtk3";
|
||||
import AstalNotifd from "gi://AstalNotifd";
|
||||
import { Notifications } from "../scripts/notification-handler";
|
||||
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",
|
||||
@@ -9,14 +16,43 @@ export const FloatingNotifications: Widget.Window = new Widget.Window({
|
||||
monitor: 0,
|
||||
layer: Astal.Layer.OVERLAY,
|
||||
visible: false,
|
||||
width_request: 350,
|
||||
widthRequest: 450,
|
||||
exclusivity: Astal.Exclusivity.NORMAL,
|
||||
setup: (window) => {
|
||||
connections.push(
|
||||
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();
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
onDestroy: () => connections.map(id => Notifications.getDefault().disconnect(id)),
|
||||
child: new Widget.Box({
|
||||
className: "floating-notifications-container",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
homogeneous: false,
|
||||
children: Notifications.notifications().as((notifications: Array<AstalNotifd.Notification>) =>
|
||||
notifications.map((item: AstalNotifd.Notification) =>
|
||||
NotificationWidget(item)))
|
||||
visible: bind(Notifications.getDefault(), "notifications").as(notifs => notifs.length > 0),
|
||||
children: bind(notifWidgets).as((map) => [...map.values()].map((revealer) => revealer))
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.WindowProps);
|
||||
|
||||
Reference in New Issue
Block a user