repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

pi/agent/skills/quickshell/examples/08-notification-daemon/shell.qml

Raw
// 08-notification-daemon/shell.qml
// A minimal notification daemon. Replaces mako/dunst/swaync.
// Run with: qs -p examples/08-notification-daemon/shell.qml
// After starting, trigger a notify-send to test:
//   notify-send "Hello" "This is a test"
//
// To replace your real notification daemon: stop mako/dunst, then run this.

import QtQuick
import Quickshell
import Quickshell.Services.Notifications

Scope {
    id: root

    // The server registers itself on the DBus session bus as a notification daemon.
    NotificationServer {
        id: server

        // Optional capability hints (advertise what we support).
        actionsSupported: true
        bodyMarkupSupported: true
        persistenceSupported: true
        bodyHyperlinksSupported: true
        bodyImagesSupported: true
        inlineReplySupported: true
        keepOnReload: true

        // Keep the notification around (otherwise it's auto-dismissed on emit).
        onNotification: (notification) => {
            notification.tracked = true
            // Schedule auto-dismiss after expireTimeout.
            if (notification.expireTimeout > 0) {
                dismissTimer(notification)
            }
        }
    }

    // Helper: dismiss a notification after N ms.
    function dismissTimer(notif) {
        const ms = notif.expireTimeout * 1000
        expireTimer.createObject(root, {
            target: notif,
            interval: ms
        })
    }

    Component {
        id: expireTimer
        Timer {
            property var target: null
            running: true
            repeat: false
            onTriggered: if (target) target.tracked = false
        }
    }

    // Render each tracked notification as a panel.
    Repeater {
        model: server.trackedNotifications
        delegate: PanelWindow {
            id: popupWindow
            required property var modelData  // the Notification

            // Stack each popup above the previous one.
            anchors.bottom: true
            margins.bottom: 30 + (index * 80)
            exclusiveZone: 0

            implicitWidth: 360
            implicitHeight: 80
            color: "transparent"
            mask: Region {}  // click-through

            Rectangle {
                anchors.fill: parent
                radius: 8
                color: "#dd1e1e2e"
                border.color: "#444"
                border.width: 1

                Column {
                    anchors.fill: parent
                    anchors.margins: 12
                    spacing: 4

                    Text {
                        text: popupWindow.modelData ? popupWindow.modelData.summary : ""
                        color: "white"
                        font.pointSize: 12
                        font.bold: true
                        elide: Text.ElideRight
                        width: parent.width
                    }
                    Text {
                        text: popupWindow.modelData ? popupWindow.modelData.body : ""
                        color: "#ccc"
                        font.pointSize: 10
                        wrapMode: Text.Wrap
                        width: parent.width
                        visible: text.length > 0
                    }
                }
            }
        }
    }
}