import QtQuick import Quickshell import Quickshell.Wayland import Quickshell.Services.Notifications import "../Shared" PanelWindow { id: notifWindow anchors { top: true right: true } margins { top: Theme.geometry.padding right: Theme.geometry.padding } exclusiveZone: 0 color: "transparent" implicitWidth: 320 implicitHeight: list.height WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.namespace: "quickshell-notifications" NotificationServer { id: server keepOnReload: true bodySupported: true bodyMarkupSupported: true actionsSupported: true imageSupported: true onNotification: notification => { notification.tracked = true; toastModel.insert(0, { notifObj: notification, appName: notification.appName, summary: notification.summary, body: notification.body, urgency: notification.urgency }); function removeFromModel() { for (let i = 0; i < toastModel.count; i++) { if (toastModel.get(i).notifObj === notification) { toastModel.remove(i); break; } } } notification.closed.connect(removeFromModel); let timeout = notification.expireTimeout > 0 ? notification.expireTimeout : 5000; dismissTimer.createObject(notifWindow, { targetNotification: notification, interval: timeout }); } } Component { id: dismissTimer Timer { property var targetNotification running: true repeat: false onTriggered: { for (let i = 0; i < toastModel.count; i++) { if (toastModel.get(i).notifObj === targetNotification) { toastModel.remove(i); break; } } destroy(); } } } ListModel { id: toastModel } function colorFor(urgency) { if (urgency === NotificationUrgency.Critical) return Theme.colors.alert; if (urgency === NotificationUrgency.Low) return Theme.colors.success; return Theme.colors.primary; } function labelFor(urgency) { if (urgency === NotificationUrgency.Critical) return "Warning"; if (urgency === NotificationUrgency.Low) return "Notice"; return "Info"; } Column { id: list width: parent.width spacing: Theme.geometry.spacing Repeater { model: toastModel delegate: Rectangle { id: toast width: list.width height: content.implicitHeight + Theme.geometry.padding * 2 radius: Theme.geometry.radiusMedium color: Qt.alpha(notifWindow.colorFor(model.urgency), 0.15) border.color: Qt.alpha(notifWindow.colorFor(model.urgency), 0.3) border.width: 1 Behavior on opacity { NumberAnimation { duration: Theme.animation.durationNormal } } Row { id: content anchors.left: parent.left anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter anchors.margins: Theme.geometry.padding spacing: Theme.geometry.spacing Rectangle { width: 16 height: 16 radius: 8 color: notifWindow.colorFor(model.urgency) anchors.top: parent.top anchors.topMargin: 2 } Column { width: content.width - 16 - Theme.geometry.spacing - closeIcon.width - Theme.geometry.spacing spacing: 2 Text { text: model.summary && model.summary.length > 0 ? model.summary : model.appName font.family: Theme.font.family font.pixelSize: 12 font.bold: true color: notifWindow.colorFor(model.urgency) width: parent.width elide: Text.ElideRight } Text { visible: model.body && model.body.length > 0 text: model.body font.family: Theme.font.family font.pixelSize: 12 color: Theme.colors.text width: parent.width wrapMode: Text.WordWrap maximumLineCount: 3 elide: Text.ElideRight } } Text { id: closeIcon text: "✕" color: Theme.colors.textMuted font.pixelSize: 12 anchors.top: parent.top MouseArea { anchors.fill: parent anchors.margins: -6 cursorShape: Qt.PointingHandCursor onClicked: { model.notifObj.dismiss(); toastModel.remove(index); } } } } } } } }