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>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-10-15 14:47:40 +02:00
1 parent d7f0498ba0
commit 395de70b26
17 files changed
+1132 -13

No files matched your search

@@ -0,0 +1,266 @@
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
}
}
}
}
}
@@ -0,0 +1,164 @@
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Wayland
import "../components"
import "../services"
import "../core"
import "../theme"
// Notification banners in a glass drawer that drops out of the bar, styled
// like the OSD. Banners stack newest first; hovering pauses their timers,
// swiping or right-clicking hides one into the Control Center.
// qmllint disable uncreatable-type
PanelWindow {
id: root
readonly property var options: NotificationService.options
readonly property var items: NotificationService.popups
property var targetScreen: null
screen: ScreenService.current(targetScreen)
readonly property int screenWidth: screen ? screen.width : 1920
// The OSD capsule takes this spot while it is up; banners wait behind it.
readonly property var osd: ShellState.osdWindow
readonly property bool yielding: !!osd && osd.shown && osd.options.position === options.position
readonly property bool shown: NotificationService.active && items.length > 0 && !yielding && !ShellState.controlCenterOpen
onItemsChanged: if (items.length > 0 && !drawer.shown)
targetScreen = ScreenService.active
// Control Center lists everything; banners would cover it.
Connections {
target: ShellState
function onControlCenterOpenChanged() {
if (ShellState.controlCenterOpen)
NotificationService.clearPopups();
}
}
anchors {
top: true
right: root.options.position === "top-right"
}
// Margins is present at runtime but unresolved in 0.3.1 qmltypes.
// qmllint disable unqualified unresolved-type
margins {
right: BarDrawers.margin + BarDrawers.radius
}
// qmllint enable unqualified unresolved-type
implicitWidth: Math.round(drawer.width)
implicitHeight: Math.round(BarDrawers.bottom + drawer.contentHeight)
mask: Region {
item: drawer.body
}
visible: shown || drawer.shown
color: Theme.transparent
exclusionMode: ExclusionMode.Ignore
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.namespace: "glassMxrph-notifications"
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
BarDrawer {
id: drawer
objectName: "notificationSurface"
y: BarDrawers.bottom
open: root.shown
style: root.options.animation
contentWidth: 380
// Keeps the last height while the drawer closes around its final banner.
property real lastHeight: 80
readonly property real wanted: list.contentHeight + 12
onWantedChanged: if (list.count > 0)
lastHeight = wanted
contentHeight: list.count > 0 ? wanted : lastHeight
Behavior on contentHeight {
enabled: drawer.settled
NumberAnimation {
duration: Theme.duration
easing.type: Easing.OutCubic
}
}
drawerId: "notifications"
screenName: root.screen ? root.screen.name : ""
screenX: root.options.position === "top-right" ? root.screenWidth - BarDrawers.margin - BarDrawers.radius - width : (root.screenWidth - width) / 2
ListView {
id: list
objectName: "notificationPopupList"
anchors.fill: parent
anchors.margins: 6
interactive: false
spacing: 0
model: ScriptModel {
values: root.items
}
add: Transition {
NumberAnimation {
property: "opacity"
from: 0
to: 1
duration: Theme.duration
}
}
remove: Transition {
NumberAnimation {
property: "opacity"
to: 0
duration: Theme.duration / 2
}
}
// Also finishes an add interrupted by a newer banner; otherwise the
// displaced delegate keeps its partial opacity.
displaced: Transition {
NumberAnimation {
property: "y"
duration: Theme.duration
easing.type: Easing.OutCubic
}
NumberAnimation {
property: "opacity"
to: 1
duration: Theme.duration
}
}
delegate: Item {
id: banner
required property var modelData
required property int index
width: list.width
height: card.implicitHeight
Rectangle {
visible: banner.index > 0
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 12
height: 1
color: Theme.hairline
}
NotificationCard {
id: card
objectName: "notificationPopup"
width: parent.width
notification: banner.modelData
framed: false
swipeable: true
onSwiped: NotificationService.hidePopup(banner.modelData)
}
// 0 (critical) stays until dismissed. Not read from the Timer's own
// interval: that is still the 1000 ms default when running first binds.
readonly property int lifetime: NotificationService.timeoutFor(modelData)
Timer {
id: life
interval: Math.max(1, banner.lifetime)
// Restarts from the full time after a hover, like macOS banners.
running: banner.lifetime > 0 && root.shown && !drawer.hovered
onTriggered: NotificationService.hidePopup(banner.modelData)
}
Connections {
target: NotificationService
function onPopupShown(n) {
if (n === banner.modelData && banner.lifetime > 0)
life.restart();
}
}
}
}
}
}