summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2025-09-12 22:01:51 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2025-09-12 22:01:51 +0200
commit666464567055a2e4ba9f6bb310e901cdc27977f7 (patch)
tree45e626dc591803925880230a3e06d568e6a5fa48 /accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml
parent1ff0e9ecbef79e1b3592cd4a68ce3e90c8536bdb (diff)
downloadnixos-666464567055a2e4ba9f6bb310e901cdc27977f7.tar
nixos-666464567055a2e4ba9f6bb310e901cdc27977f7.tar.gz
nixos-666464567055a2e4ba9f6bb310e901cdc27977f7.tar.bz2
nixos-666464567055a2e4ba9f6bb310e901cdc27977f7.tar.xz
nixos-666464567055a2e4ba9f6bb310e901cdc27977f7.zip
...
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml')
-rw-r--r--accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml98
1 files changed, 98 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml b/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml
new file mode 100644
index 00000000..778cdc2a
--- /dev/null
+++ b/accounts/gkleen@sif/shell/quickshell/Services/NotificationManager.qml
@@ -0,0 +1,98 @@
1pragma Singleton
2
3import QtQml
4import Quickshell
5import Quickshell.Services.Notifications
6
7Singleton {
8 id: root
9
10 property bool displayInhibited: false
11 property alias trackedNotifications: server.trackedNotifications
12 readonly property var groups: {
13 function matchesGroupKey(notif, groupKey) {
14 var matches = true;
15 for (const prop in groupKey.test) {
16 if (notif[prop] !== groupKey.test[prop]) {
17 matches = false;
18 break;
19 }
20 }
21 return matches;
22 }
23
24 var groups = new Map();
25 var notifs = new Array();
26 for (const [ix, notif] of server.trackedNotifications.values.entries()) {
27 var didGroup = false;
28 for (const groupKey of root.groupKeys) {
29 if (!matchesGroupKey(notif, groupKey))
30 continue;
31
32 const key = JSON.stringify({
33 "key": groupKey,
34 "values": Object.assign({}, ...(Array.from(groupKey["group-by"]).map(prop => {
35 var res = {};
36 res[prop] = notif[prop];
37 return res;
38 })))
39 });
40 if (!groups.has(key))
41 groups.set(key, new Array());
42 groups.get(key).push({ "ix": ix, "notif": notif });
43 didGroup = true;
44 break;
45 }
46
47 if (!didGroup)
48 notifs.push([{ "ix": ix, "notif": notif }]);
49 }
50 notifs.push(...groups.values());
51 notifs.sort((as, bs) => Math.min(...(as.map(o => o.ix))) - Math.min(...(bs.map(o => o.ix))));
52 return notifs.map(ns => ns.map(n => n.notif));
53 }
54
55 property var groupKeys: [
56 { "test": { "appName": "Element" }, "group-by": [ "summary" ] }
57 ];
58
59 Component {
60 id: expirationTimer
61
62 QtObject {
63 id: timer
64
65 required property QtObject parent
66 required property int expirationTime
67 property list<QtObject> data: [
68 Timer {
69 running: !root.displayInhibited
70 interval: timer.expirationTime
71 onTriggered: timer.parent.expire()
72 }
73 ]
74 }
75 }
76
77 NotificationServer {
78 id: server
79
80 bodySupported: true
81 actionsSupported: true
82 actionIconsSupported: true
83 imageSupported: true
84 bodyMarkupSupported: true
85 bodyImagesSupported: true
86
87 onNotification: notification => {
88 var timeout = notification.expireTimeout * 1000;
89 if (notification.appName == "poweralertd")
90 timeout = 2000;
91 if (timeout > 0) {
92 Object.defineProperty(notification, "expirationTimer", { configurable: true, enumerable: true, writable: true });
93 notification.expirationTimer = expirationTimer.createObject(notification, { parent: notification, expirationTime: timeout });
94 }
95 notification.tracked = true;
96 }
97 }
98}