50 lines
2.1 KiB
QML
50 lines
2.1 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import QtQuick.Controls
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
import "services"
|
|
import "services/NotificationPolicy.js" as Policy
|
|
import "components"
|
|
|
|
PanelWindow {
|
|
id: toast
|
|
property var notification: null
|
|
visible: notification !== null && !Notifications.dnd
|
|
anchors { top: true; right: true }
|
|
margins { top: 64; right: 12 }
|
|
implicitWidth: Math.min(360, screen.width - 24)
|
|
implicitHeight: labels.implicitHeight + 32
|
|
exclusionMode: ExclusionMode.Ignore
|
|
WlrLayershell.layer: WlrLayer.Overlay
|
|
WlrLayershell.namespace: "adaptive-notification"
|
|
color: "transparent"
|
|
Connections {
|
|
target: Notifications
|
|
function onPresent(n) {
|
|
toast.notification = n;
|
|
hide.stop();
|
|
const duration = Policy.timeoutMs(n.expireTimeout, n.urgency);
|
|
// Persistent normal notifications stay in the center, but their popup is bounded.
|
|
if (n.urgency !== 2) { hide.interval = duration || 6000; hide.start(); }
|
|
}
|
|
function onRemoved(id) { if (toast.notification?.id === id) toast.notification = null; }
|
|
function onDndChanged() { if (Notifications.dnd) { toast.notification = null; hide.stop(); } }
|
|
}
|
|
Timer { id: hide; onTriggered: toast.notification = null }
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
color: Theme.surfaceHigh
|
|
radius: Theme.radiusLarge
|
|
Column {
|
|
id: labels
|
|
anchors { left: parent.left; right: parent.right; top: parent.top; margins: 16 }
|
|
spacing: 8
|
|
Text { width: parent.width; text: toast.notification?.appName || ""; color: Theme.primary; textFormat: Text.PlainText; elide: Text.ElideRight }
|
|
ActionButton { text: "Убрать"; onClicked: if (toast.notification) Notifications.dismiss(toast.notification.id) }
|
|
Text { width: parent.width; text: toast.notification?.summary || ""; color: Theme.foreground; textFormat: Text.PlainText; wrapMode: Text.Wrap; maximumLineCount: 3; elide: Text.ElideRight }
|
|
}
|
|
}
|
|
}
|