This repository has been archived on 2026-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

201 lines
6.8 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Wayland
import Quickshell.Services.Notifications
import "../Shared"
PanelWindow {
id: notifWindow
property QtObject rootState
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;
// Do Not Disturb: the notification is still tracked/available
// to whatever reads NotificationServer directly, just not
// surfaced as a toast.
if (notifWindow.rootState && notifWindow.rootState.dndEnabled) return;
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.info;
}
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: Surface {
id: toast
width: list.width
height: 20 + content.implicitHeight
color: Theme.colors.surface
tint: notifWindow.colorFor(model.urgency)
glow: model.urgency === NotificationUrgency.Critical
Behavior on opacity { NumberAnimation { duration: Theme.animation.durationNormal } }
Column {
anchors.fill: parent
// Solid accent header strip
Rectangle {
width: parent.width
height: 20
color: notifWindow.colorFor(model.urgency)
Text {
anchors.left: parent.left
anchors.leftMargin: Theme.geometry.spacing
anchors.verticalCenter: parent.verticalCenter
text: notifWindow.labelFor(model.urgency).toUpperCase() + " :: " + model.appName
font.family: Theme.font.family
font.bold: true
font.pixelSize: Theme.type.caption
color: Theme.colors.textOnAccent
}
}
Row {
id: content
width: parent.width
leftPadding: Theme.geometry.padding
rightPadding: Theme.geometry.padding
topPadding: Theme.geometry.spacing
bottomPadding: Theme.geometry.spacing
spacing: Theme.geometry.spacing
Column {
width: content.width - content.leftPadding - content.rightPadding - 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: Theme.colors.text
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.textMuted
width: parent.width
wrapMode: Text.WordWrap
maximumLineCount: 3
elide: Text.ElideRight
}
}
Text {
id: closeIcon
text: "✕"
color: Theme.colors.textMuted
font.family: Theme.font.family
font.pixelSize: 12
MouseArea {
anchors.fill: parent
anchors.margins: -6
cursorShape: Qt.PointingHandCursor
onClicked: {
model.notifObj.dismiss();
toastModel.remove(index);
}
}
}
}
}
}
}
}
}