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:
1 parent
d7f0498ba0
commit
395de70b26
17 files changed
+1132
-13
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user