flocon/home/programs/ags/notificationPopups.js

125 lines
3.1 KiB
JavaScript
Raw Normal View History

repo: add ags, a gtk shell commit 75cf6a4d67149ebf8952333f95bc58990b8ddb41 Author: Anthony Rodriguez <anthony@nezia.dev> Date: Fri Oct 11 15:34:14 2024 +0200 home/programs/niri: use gtk portals for most things, and gnome for screencast commit 5ccb424079facbfc2538b5ec51a5a9c2f4f29a45 Author: Anthony Rodriguez <anthony@nezia.dev> Date: Thu Oct 10 21:19:33 2024 +0200 home/programs/niri: add play/pause, add settings button on fn key f12 commit 8b7164739d8bd9f7bce19404a842446c77e4136f Author: Anthony Rodriguez <anthony@nezia.dev> Date: Thu Oct 10 00:32:40 2024 +0200 home/programs/niri: replace desktop-portal-gtk with gnome commit fe40c6c72cc9d4ee09742017e8691de697f24b92 Author: Anthony Rodriguez <anthony@nezia.dev> Date: Thu Oct 10 00:21:31 2024 +0200 home/programs/niri: add xdg-desktop-portal-gtk commit 74b7df12459ae259d646603c1212191b5b618bee Author: Anthony Rodriguez <anthony@nezia.dev> Date: Thu Oct 10 00:21:14 2024 +0200 home/programs: add fractal commit 3773095069a7170e14c339825565f2a70b0009b2 Author: Anthony Rodriguez <anthony@nezia.dev> Date: Thu Oct 10 00:21:05 2024 +0200 home/programs/gtk: use color-scheme for gtk4.0 commit 8fef768f4f830c04b1af088b1c2753d083ece2db Author: Anthony Rodriguez <anthony@nezia.dev> Date: Wed Oct 9 19:22:43 2024 +0200 system/services/regreet: ensure that regreet starts dbus session commit fcd88bfa8ed5053ef7464c79d121b3b1d0d78ffc Author: Anthony Rodriguez <anthony@nezia.dev> Date: Wed Oct 9 19:22:20 2024 +0200 repo: implement ags Implement ags, a wayland bar / GTK shell. Also added a few dependencies required for it to work properly.
2024-10-11 15:57:55 +00:00
const notifications = await Service.import("notifications");
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
function NotificationIcon({ app_entry, app_icon, image }) {
if (image) {
return Widget.Box({
css:
`background-image: url("${image}");` +
"background-size: contain;" +
"background-repeat: no-repeat;" +
"background-position: center;",
});
}
let icon = "dialog-information-symbolic";
if (Utils.lookUpIcon(app_icon)) icon = app_icon;
if (app_entry && Utils.lookUpIcon(app_entry)) icon = app_entry;
return Widget.Box({
child: Widget.Icon(icon),
});
}
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
function Notification(n) {
const icon = Widget.Box({
vpack: "start",
class_name: "icon",
child: NotificationIcon(n),
});
const title = Widget.Label({
class_name: "title",
xalign: 0,
justification: "left",
hexpand: true,
max_width_chars: 24,
truncate: "end",
wrap: true,
label: n.summary,
use_markup: true,
});
const body = Widget.Label({
class_name: "body",
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
label: n.body,
wrap: true,
});
const actions = Widget.Box({
class_name: "actions",
children: n.actions.map(({ id, label }) =>
Widget.Button({
class_name: "action-button",
on_clicked: () => {
n.invoke(id);
n.dismiss();
},
hexpand: true,
child: Widget.Label(label),
}),
),
});
return Widget.EventBox(
{
attribute: { id: n.id },
on_primary_click: n.dismiss,
},
Widget.Box(
{
class_name: `notification ${n.urgency}`,
vertical: true,
},
Widget.Box([icon, Widget.Box({ vertical: true }, title, body)]),
actions,
),
);
}
export function NotificationPopups(monitor = 0) {
const list = Widget.Box({
vertical: true,
children: notifications.popups.map(Notification),
});
function onNotified(_, /** @type {number} */ id) {
const n = notifications.getNotification(id);
if (n) list.children = [Notification(n), ...list.children];
}
function onDismissed(_, /** @type {number} */ id) {
list.children.find((n) => n.attribute.id === id)?.destroy();
}
list
.hook(notifications, onNotified, "notified")
.hook(notifications, onDismissed, "dismissed");
return Widget.Window({
monitor,
name: `notifications${monitor}`,
class_name: "notification-popups",
anchor: ["top", "right"],
child: Widget.Box({
css: "min-width: 2px; min-height: 2px;",
class_name: "notifications",
vertical: true,
child: list,
/** this is a simple one liner that could be used instead of
hooking into the 'notified' and 'dismissed' signals.
but its not very optimized becuase it will recreate
the whole list everytime a notification is added or dismissed */
// children: notifications.bind('popups')
// .as(popups => popups.map(Notification))
}),
});
}