import QtQuick import Quickshell.Services.Notifications QtObject { id: root property ListModel notifications: ListModel {} function indexOfId(notificationId) { for (let i = 0; i < notifications.count; i++) { const row = notifications.get(i); if (row.rowNotificationId === notificationId) return i; } return -1; } function timeoutMsFor(notificationObject) { const isCritical = notificationObject.urgency === NotificationUrgency.Critical; if (isCritical) return -1; const rawSeconds = Number(notificationObject.expireTimeout); if (!Number.isFinite(rawSeconds) || rawSeconds <= 0) return 5000; return Math.max(1000, Math.round(rawSeconds * 1000)); } function addNotification(notificationObject) { if (notificationObject.lastGeneration) { notificationObject.dismiss(); return; } const existingIndex = indexOfId(notificationObject.id); if (existingIndex >= 0) notifications.remove(existingIndex); notificationObject.tracked = true; const idCopy = notificationObject.id; notificationObject.closed.connect(function () { const rowIndex = indexOfId(idCopy); if (rowIndex >= 0) notifications.remove(rowIndex); }); notifications.append({ rowNotificationId: notificationObject.id, rowTitle: String(notificationObject.summary || ""), rowBody: String(notificationObject.body || ""), rowUrgency: NotificationUrgency.toString(notificationObject.urgency), rowAppName: String(notificationObject.appName || ""), rowAppIcon: String(notificationObject.appIcon || ""), rowImage: String(notificationObject.image || ""), rowTimeoutMs: timeoutMsFor(notificationObject), rowCritical: notificationObject.urgency === NotificationUrgency.Critical, rowHints: notificationObject.hints || ({}), rowObject: notificationObject }); } function closeById(notificationId, reason) { const rowIndex = indexOfId(notificationId); if (rowIndex < 0) return; const row = notifications.get(rowIndex); const notifObject = row.rowObject; if (notifObject) { if (reason === "timeout") notifObject.expire(); else notifObject.dismiss(); } notifications.remove(rowIndex); } property NotificationServer server: NotificationServer { keepOnReload: false bodySupported: true bodyMarkupSupported: false bodyHyperlinksSupported: false // NotificationServer is Quickshell's DBus implementation for // org.freedesktop.Notifications, so this is the notification source. onNotification: function (notificationObject) { root.addNotification(notificationObject); } } }