Files
mxandClaude Opus 5.5 395de70b26 Add native notifications with OSD-style banners and a Control Center module
glassMxrph now owns org.freedesktop.Notifications. Banners drop out of the
bar like the OSD; Control Center stacks history per app like macOS
Notification Center. Do Not Disturb lives in the shell and falls back to
SwayNC while another daemon holds the bus name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 14:47:40 +02:00

267 lines
10 KiB
QML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import "../components"
import "../services"
import "../theme"
// One notification: app icon, app and age, summary, body, image and action
// buttons. Clicking runs the default action; the corner button dismisses it.
// Shared by the popup drawer (unframed) and the Control Center (framed card).
Item {
id: root
required property var notification
property bool framed: true
// Body lines before eliding.
property int bodyLines: 3
// A popup swipes away to the Control Center instead of being dismissed.
property bool swipeable: false
signal swiped
// Top card of a collapsed stack: a click expands it and the dismiss
// button clears the whole app group.
property string stackKey: ""
property int stackCount: 1
signal expand
readonly property bool hovered: hover.hovered
readonly property var n: notification
readonly property bool critical: NotificationService.critical(n)
readonly property string icon: NotificationService.iconFor(n)
readonly property string image: NotificationService.imageFor(n)
readonly property var buttons: NotificationService.buttons(n)
implicitWidth: 360
implicitHeight: layout.implicitHeight + 24
Accessible.role: Accessible.Button
Accessible.name: n ? NotificationService.appLabel(n) + ": " + n.summary : ""
HoverHandler {
id: hover
}
// Drag sideways to hide a popup into the Control Center.
property real swipe: 0
DragHandler {
id: drag
enabled: root.swipeable
target: null
xAxis.enabled: true
yAxis.enabled: false
onTranslationChanged: root.swipe = Math.max(0, translation.x)
onActiveChanged: if (!active) {
if (root.swipe > root.width * 0.3)
root.swiped();
else
root.swipe = 0;
}
}
Behavior on swipe {
enabled: !drag.active
NumberAnimation {
duration: Theme.duration
easing.type: Easing.OutCubic
}
}
Item {
id: face
width: root.width
height: root.height
x: root.swipe
opacity: 1 - Math.min(1, root.swipe / root.width)
Rectangle {
anchors.fill: parent
visible: root.framed
radius: Math.max(12, Theme.radius * 0.75)
color: area.containsMouse ? Theme.hover : Theme.fill
border.width: 1
border.color: root.critical ? Qt.alpha(Theme.urgent, 0.6) : Theme.hairline
}
Rectangle {
anchors.fill: parent
visible: !root.framed && area.containsMouse
radius: Math.max(10, Theme.radius * 0.6)
color: Theme.hover
}
MouseArea {
id: area
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
cursorShape: Qt.PointingHandCursor
onClicked: mouse => {
if (mouse.button === Qt.LeftButton && root.stackKey)
root.expand();
else if (mouse.button === Qt.LeftButton)
NotificationService.activate(root.n);
else if (root.stackKey)
NotificationService.dismissGroup(root.stackKey);
else if (mouse.button === Qt.MiddleButton || !root.swipeable)
NotificationService.dismiss(root.n);
else
root.swiped();
}
}
RowLayout {
id: layout
anchors {
left: parent.left
right: parent.right
top: parent.top
margins: 12
}
spacing: 12
Rectangle {
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: 38
Layout.preferredHeight: 38
radius: 10
color: appIcon.status === Image.Ready ? Theme.transparent : Theme.surfaceVariant
border.width: root.critical ? 1.5 : 0
border.color: Theme.urgent
Text {
anchors.centerIn: parent
visible: appIcon.status !== Image.Ready
text: Icons.available ? "󰂚" : "!"
color: Theme.text
font.pixelSize: 18
}
Image {
id: appIcon
anchors.fill: parent
anchors.margins: 2
// Without an app icon the image (often an avatar) takes its place.
source: root.icon || root.image
sourceSize: Qt.size(76, 76)
fillMode: Image.PreserveAspectFit
asynchronous: true
smooth: true
mipmap: true
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
spacing: 2
RowLayout {
Layout.fillWidth: true
spacing: 6
Text {
text: root.n ? NotificationService.appLabel(root.n) + (root.stackCount > 1 ? " · " + root.stackCount : "") : ""
color: Theme.textSecondary
font.pixelSize: 11
font.weight: Font.Medium
elide: Text.ElideRight
Layout.fillWidth: true
}
// The age gives way to a dismiss button while hovered.
Item {
implicitWidth: Math.max(age.implicitWidth, 18)
implicitHeight: 16
Text {
id: age
objectName: "notificationAge"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
visible: !root.hovered
text: root.n ? NotificationService.since(root.n) : ""
color: Theme.textSecondary
font.pixelSize: 11
}
Rectangle {
objectName: "notificationClose"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: 18
height: 18
radius: 9
visible: root.hovered
color: closeArea.containsMouse ? Theme.hover : Theme.surfaceVariant
border.width: 1
border.color: Theme.hairline
Accessible.role: Accessible.Button
Accessible.name: root.stackKey ? "Clear notifications" : "Dismiss notification"
Text {
anchors.centerIn: parent
text: "×"
color: Theme.text
font.pixelSize: 12
}
MouseArea {
id: closeArea
anchors.fill: parent
anchors.margins: -3
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.stackKey ? NotificationService.dismissGroup(root.stackKey) : NotificationService.dismiss(root.n)
}
}
}
}
Text {
objectName: "notificationSummary"
text: root.n ? root.n.summary : ""
visible: text !== ""
color: root.critical ? Theme.urgent : Theme.text
font.pixelSize: 13
font.weight: Font.DemiBold
textFormat: Text.PlainText
wrapMode: Text.Wrap
maximumLineCount: 2
elide: Text.ElideRight
Layout.fillWidth: true
}
Text {
text: root.n ? root.n.body : ""
visible: text !== ""
color: Theme.textSecondary
linkColor: Theme.accentVivid
font.pixelSize: 12
// Spec markup subset (b, i, u, a); StyledText never loads remote images.
textFormat: Text.StyledText
wrapMode: Text.Wrap
maximumLineCount: root.bodyLines
elide: Text.ElideRight
Layout.fillWidth: true
onLinkActivated: link => Qt.openUrlExternally(link)
HoverHandler {
enabled: parent.hoveredLink !== ""
cursorShape: Qt.PointingHandCursor
}
}
Flow {
visible: root.buttons.length > 0
Layout.fillWidth: true
Layout.topMargin: 6
spacing: 6
Repeater {
model: root.buttons
GlassButton {
required property var modelData
implicitHeight: 28
text: modelData.text
font.pixelSize: 11
onClicked: NotificationService.invoke(root.n, modelData)
}
}
}
}
Rectangle {
visible: root.icon !== "" && root.image !== "" && thumb.status !== Image.Error
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: 46
Layout.preferredHeight: 46
radius: 8
color: Theme.surfaceVariant
clip: true
Image {
id: thumb
anchors.fill: parent
source: root.icon !== "" ? root.image : ""
sourceSize: Qt.size(92, 92)
fillMode: Image.PreserveAspectCrop
asynchronous: true
}
}
}
}
}