feat(quickshell): move notifications into HyprChrome
The notification daemon and popup stack now live under HyprChrome/Widgets/Notifications and are owned by HyprChromeShell, so popups land on the rail's monitor below its exclusive zone. Replaces widgets/notifications; NotificationCard renders headless for tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import Quickshell.Widgets
|
||||
import qs.HyprChrome.Theme
|
||||
|
||||
// Headlessly renderable visual core of one notification. Every field arrives as
|
||||
// a plain property and every action leaves as a signal; Notifications.qml maps
|
||||
// the server's Notification onto it.
|
||||
//
|
||||
// Owns its own expiry: the drain meter IS the timer, so hovering pauses both.
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property string appName: ""
|
||||
property string summary: ""
|
||||
property string body: ""
|
||||
// Icon name, path or URL; `image` (avatar, album art) wins over it.
|
||||
property string appIcon: ""
|
||||
property string image: ""
|
||||
// 0 low, 1 normal, 2 critical — NotificationUrgency's values.
|
||||
property int urgency: 1
|
||||
property string time: ""
|
||||
|
||||
// Read structurally ({ identifier, text }). The "default" action is the
|
||||
// card's own click, not a chip.
|
||||
property var actions: []
|
||||
|
||||
// Milliseconds; 0 never expires.
|
||||
property int timeout: 0
|
||||
// Off for headless renders, which set `remaining` directly.
|
||||
property bool countdown: true
|
||||
property real remaining: 1
|
||||
|
||||
signal dismissed
|
||||
signal expired
|
||||
signal actionInvoked(string identifier)
|
||||
|
||||
readonly property bool critical: root.urgency === 2
|
||||
readonly property color tint: root.critical ? Theme.hot : root.urgency === 0 ? Theme.muted : Theme.accent
|
||||
|
||||
readonly property var chipActions: {
|
||||
const out = [];
|
||||
for (let i = 0; i < root.actions.length; i++) {
|
||||
if (root.actions[i].identifier !== "default")
|
||||
out.push(root.actions[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
readonly property bool hasDefault: root.chipActions.length !== root.actions.length
|
||||
|
||||
readonly property string iconSource: {
|
||||
const s = root.image !== "" ? root.image : root.appIcon;
|
||||
if (s === "")
|
||||
return "";
|
||||
if (s.startsWith("/"))
|
||||
return "file://" + s;
|
||||
if (s.includes(":/"))
|
||||
return s;
|
||||
return Quickshell.iconPath(s, true);
|
||||
}
|
||||
|
||||
implicitWidth: 360
|
||||
implicitHeight: panel.implicitHeight
|
||||
|
||||
NumberAnimation on remaining {
|
||||
id: drain
|
||||
|
||||
from: 1
|
||||
to: 0
|
||||
duration: Math.max(1, root.timeout)
|
||||
running: root.countdown && root.timeout > 0
|
||||
paused: running && hover.hovered
|
||||
}
|
||||
|
||||
// Not drain's finished(): a value-source animation need not emit it.
|
||||
onRemainingChanged: {
|
||||
if (root.remaining <= 0 && root.countdown && root.timeout > 0)
|
||||
root.expired();
|
||||
}
|
||||
|
||||
HoverHandler {
|
||||
id: hover
|
||||
}
|
||||
|
||||
// Under the panel, so the close box and chips take their own clicks.
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: root.hasDefault ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||
onClicked: {
|
||||
if (root.hasDefault)
|
||||
root.actionInvoked("default");
|
||||
else
|
||||
root.dismissed();
|
||||
}
|
||||
}
|
||||
|
||||
component MicroText: Text {
|
||||
color: Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 8
|
||||
font.letterSpacing: 0.9
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
NotificationPanel {
|
||||
id: panel
|
||||
|
||||
width: root.width
|
||||
panelId: root.critical ? "CRT" : root.urgency === 0 ? "LOW" : "NTF"
|
||||
title: (root.appName !== "" ? root.appName : "NOTIFICATION").toUpperCase()
|
||||
meta: root.time
|
||||
accentColor: root.tint
|
||||
|
||||
onCloseRequested: root.dismissed()
|
||||
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
spacing: 8
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 10
|
||||
|
||||
// Framed, so a transparent icon still reads as a tile.
|
||||
Rectangle {
|
||||
Layout.alignment: Qt.AlignTop
|
||||
visible: root.iconSource !== ""
|
||||
implicitWidth: 40
|
||||
implicitHeight: 40
|
||||
color: Theme.selection
|
||||
border.width: 1
|
||||
border.color: Theme.hair
|
||||
|
||||
IconImage {
|
||||
anchors.centerIn: parent
|
||||
implicitSize: root.image !== "" ? 38 : 28
|
||||
source: root.iconSource
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignTop
|
||||
spacing: 3
|
||||
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
visible: root.summary !== ""
|
||||
text: root.summary
|
||||
textFormat: Text.PlainText
|
||||
wrapMode: Text.Wrap
|
||||
maximumLineCount: 2
|
||||
elide: Text.ElideRight
|
||||
color: Theme.text
|
||||
font.family: Theme.displayFont
|
||||
font.pixelSize: 13
|
||||
font.bold: true
|
||||
font.letterSpacing: 0.4
|
||||
}
|
||||
|
||||
// Body markup is advertised, so StyledText, never RichText.
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
visible: root.body !== ""
|
||||
text: root.body
|
||||
textFormat: Text.StyledText
|
||||
wrapMode: Text.Wrap
|
||||
maximumLineCount: 5
|
||||
elide: Text.ElideRight
|
||||
color: Theme.textAlpha(0.72)
|
||||
linkColor: root.tint
|
||||
font.family: Theme.displayFont
|
||||
font.pixelSize: 11
|
||||
font.letterSpacing: 0.3
|
||||
onLinkActivated: link => Qt.openUrlExternally(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Flow {
|
||||
Layout.fillWidth: true
|
||||
visible: root.chipActions.length > 0
|
||||
spacing: 6
|
||||
|
||||
Repeater {
|
||||
model: root.chipActions
|
||||
|
||||
Rectangle {
|
||||
id: chip
|
||||
|
||||
required property var modelData
|
||||
|
||||
width: chipLabel.implicitWidth + 16
|
||||
height: chipLabel.implicitHeight + 10
|
||||
color: chipArea.containsMouse ? root.tint : "transparent"
|
||||
border.width: 1
|
||||
border.color: chipArea.containsMouse ? root.tint : Theme.disabled
|
||||
|
||||
Text {
|
||||
id: chipLabel
|
||||
|
||||
anchors.centerIn: parent
|
||||
text: chip.modelData.text.toUpperCase()
|
||||
color: chipArea.containsMouse ? Theme.surface : Theme.text
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 9
|
||||
font.letterSpacing: 0.8
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: chipArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.actionInvoked(chip.modelData.identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Expiry drain; a sticky card states it instead.
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 8
|
||||
|
||||
Row {
|
||||
id: meter
|
||||
|
||||
readonly property int segments: 24
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 4
|
||||
visible: root.timeout > 0
|
||||
spacing: 2
|
||||
|
||||
Repeater {
|
||||
model: meter.segments
|
||||
|
||||
Rectangle {
|
||||
required property int index
|
||||
|
||||
readonly property bool lit: index < Math.ceil(root.remaining * meter.segments)
|
||||
|
||||
width: Math.max(2, (meter.width - (meter.segments - 1) * meter.spacing) / meter.segments)
|
||||
height: meter.height
|
||||
color: lit ? root.tint : Theme.textAlpha(0.06)
|
||||
border.width: 1
|
||||
border.color: lit ? root.tint : Theme.textAlpha(0.18)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MicroText {
|
||||
visible: root.timeout > 0
|
||||
text: hover.hovered ? "HOLD" : Math.ceil(root.remaining * root.timeout / 1000) + "S"
|
||||
color: hover.hovered ? root.tint : Theme.muted
|
||||
}
|
||||
|
||||
MicroText {
|
||||
Layout.fillWidth: true
|
||||
visible: root.timeout <= 0
|
||||
text: root.critical ? "CRITICAL · STICKY" : "STICKY"
|
||||
color: root.critical ? Theme.hot : Theme.muted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Shapes
|
||||
import qs.HyprChrome.Theme
|
||||
|
||||
// Chamfered chrome for one notification card: PolkitPanel's silhouette, tighter
|
||||
// metrics, a tintable accent (urgency) and a close box in the header.
|
||||
//
|
||||
// Not PolkitPanel itself: that file is the prompt's alone to restyle.
|
||||
Item {
|
||||
id: panel
|
||||
|
||||
property string panelId: ""
|
||||
property string title: ""
|
||||
property string meta: ""
|
||||
property color accentColor: Theme.accent
|
||||
|
||||
property int chamfer: 12
|
||||
property int padding: 12
|
||||
property int outlineWidth: 1
|
||||
property int accentLineThickness: 3
|
||||
|
||||
readonly property int headerHeight: 26
|
||||
property int headerGap: 10
|
||||
readonly property int headerPadding: 8
|
||||
|
||||
property real capGap: 4
|
||||
readonly property real capOffset: panel.capGap / Math.SQRT2
|
||||
readonly property real activeChamfer: Math.max(2, Math.min(panel.chamfer, panel.height / 2 - 1))
|
||||
readonly property real accentLineWidth: Math.min(panel.width, slugChip.width + panel.headerPadding * 2)
|
||||
|
||||
default property alias content: body.data
|
||||
|
||||
signal closeRequested
|
||||
|
||||
implicitHeight: Math.round(body.y + body.height + panel.padding)
|
||||
|
||||
Shape {
|
||||
id: panelShape
|
||||
|
||||
anchors.fill: parent
|
||||
preferredRendererType: Shape.CurveRenderer
|
||||
|
||||
ShapePath {
|
||||
fillColor: Theme.surface
|
||||
strokeColor: Theme.hair
|
||||
strokeWidth: panel.outlineWidth
|
||||
|
||||
startX: 0; startY: 0
|
||||
PathLine { x: panelShape.width - panel.activeChamfer; y: 0 }
|
||||
PathLine { x: panelShape.width; y: panel.activeChamfer }
|
||||
PathLine { x: panelShape.width; y: panelShape.height }
|
||||
PathLine { x: panel.activeChamfer; y: panelShape.height }
|
||||
PathLine { x: 0; y: panelShape.height - panel.activeChamfer }
|
||||
PathLine { x: 0; y: 0 }
|
||||
}
|
||||
|
||||
ShapePath {
|
||||
fillColor: panel.accentColor
|
||||
strokeWidth: 0
|
||||
|
||||
startX: panelShape.width - panel.activeChamfer + panel.capOffset
|
||||
startY: -panel.capOffset
|
||||
PathLine { x: panelShape.width + panel.capOffset; y: panel.activeChamfer - panel.capOffset }
|
||||
PathLine { x: panelShape.width + panel.capOffset; y: -panel.capOffset }
|
||||
PathLine { x: panelShape.width - panel.activeChamfer + panel.capOffset; y: -panel.capOffset }
|
||||
}
|
||||
|
||||
ShapePath {
|
||||
fillColor: panel.accentColor
|
||||
strokeWidth: 0
|
||||
|
||||
startX: panel.activeChamfer - panel.capOffset
|
||||
startY: panelShape.height + panel.capOffset
|
||||
PathLine { x: -panel.capOffset; y: panelShape.height - panel.activeChamfer + panel.capOffset }
|
||||
PathLine { x: -panel.capOffset; y: panelShape.height + panel.capOffset }
|
||||
PathLine { x: panel.activeChamfer - panel.capOffset; y: panelShape.height + panel.capOffset }
|
||||
}
|
||||
|
||||
ShapePath {
|
||||
fillColor: panel.accentColor
|
||||
strokeWidth: 0
|
||||
|
||||
startX: 0; startY: 0
|
||||
PathLine { x: panel.accentLineWidth; y: 0 }
|
||||
PathLine { x: panel.accentLineWidth; y: panel.accentLineThickness }
|
||||
PathLine { x: 0; y: panel.accentLineThickness }
|
||||
PathLine { x: 0; y: 0 }
|
||||
}
|
||||
|
||||
ShapePath {
|
||||
fillColor: panel.accentColor
|
||||
strokeWidth: 0
|
||||
|
||||
startX: panelShape.width; startY: panelShape.height
|
||||
PathLine { x: panelShape.width - panel.accentLineWidth; y: panelShape.height }
|
||||
PathLine { x: panelShape.width - panel.accentLineWidth; y: panelShape.height - panel.accentLineThickness }
|
||||
PathLine { x: panelShape.width; y: panelShape.height - panel.accentLineThickness }
|
||||
PathLine { x: panelShape.width; y: panelShape.height }
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: headerRow
|
||||
|
||||
x: panel.headerPadding
|
||||
y: Math.round((panel.headerHeight - height) / 2)
|
||||
width: headerEnd.x - x - 8
|
||||
spacing: panel.headerPadding + 6
|
||||
|
||||
Rectangle {
|
||||
id: slugChip
|
||||
|
||||
width: slugText.implicitWidth + 8
|
||||
height: slugText.implicitHeight + 4
|
||||
color: panel.accentColor
|
||||
|
||||
Text {
|
||||
id: slugText
|
||||
|
||||
anchors.centerIn: parent
|
||||
text: panel.panelId
|
||||
color: Theme.surface
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 10
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: slugChip.verticalCenter
|
||||
width: Math.max(0, headerRow.width - slugChip.width - headerRow.spacing)
|
||||
text: panel.title
|
||||
color: Theme.text
|
||||
font.family: Theme.displayFont
|
||||
font.pixelSize: 11
|
||||
font.bold: true
|
||||
font.letterSpacing: 1.1
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: headerEnd
|
||||
|
||||
// Clear of the top-right chamfer.
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: panel.activeChamfer + 2
|
||||
y: Math.round((panel.headerHeight - height) / 2)
|
||||
spacing: 8
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: panel.meta.length > 0
|
||||
text: panel.meta
|
||||
color: Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 8
|
||||
font.letterSpacing: 0.7
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: closeBox
|
||||
|
||||
width: 16
|
||||
height: 16
|
||||
color: closeArea.containsMouse ? panel.accentColor : "transparent"
|
||||
border.width: 1
|
||||
border.color: closeArea.containsMouse ? panel.accentColor : Theme.disabled
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "✕"
|
||||
color: closeArea.containsMouse ? Theme.surface : Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 9
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: closeArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: panel.closeRequested()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
x: 1
|
||||
y: panel.headerHeight
|
||||
width: parent.width - 2
|
||||
height: 1
|
||||
color: Theme.text
|
||||
opacity: 0.12
|
||||
}
|
||||
|
||||
// Measured by childrenRect: children carry their own size, no anchoring.
|
||||
Item {
|
||||
id: body
|
||||
|
||||
x: panel.padding
|
||||
y: panel.headerHeight + panel.headerGap
|
||||
width: Math.max(0, panel.width - panel.padding * 2)
|
||||
height: childrenRect.height
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Services.Notifications
|
||||
import Quickshell.Wayland
|
||||
import QtQuick
|
||||
|
||||
// Notification daemon and its popup stack, migrated from widgets/notifications.
|
||||
// Owns the server and the surface; NotificationCard is the visual core.
|
||||
Scope {
|
||||
id: root
|
||||
|
||||
// Driven by the shell: the rail's monitor.
|
||||
property var screen: null
|
||||
|
||||
// Arrival time per notification id; the server keeps none.
|
||||
property var arrived: ({})
|
||||
|
||||
// expireTimeout is in ms (verified); -1 means "server default".
|
||||
function timeoutFor(n) {
|
||||
if (n.expireTimeout > 0)
|
||||
return n.expireTimeout;
|
||||
if (n.expireTimeout === 0 || n.urgency === NotificationUrgency.Critical)
|
||||
return 0;
|
||||
return 5000;
|
||||
}
|
||||
|
||||
NotificationServer {
|
||||
id: server
|
||||
|
||||
keepOnReload: true
|
||||
bodySupported: true
|
||||
bodyMarkupSupported: true
|
||||
bodyHyperlinksSupported: true
|
||||
imageSupported: true
|
||||
actionsSupported: true
|
||||
|
||||
onNotification: notification => {
|
||||
const id = notification.id;
|
||||
root.arrived[id] = Qt.formatTime(new Date(), "hh:mm");
|
||||
notification.closed.connect(() => delete root.arrived[id]);
|
||||
notification.tracked = true;
|
||||
}
|
||||
}
|
||||
|
||||
PanelWindow {
|
||||
id: win
|
||||
|
||||
screen: root.screen
|
||||
visible: server.trackedNotifications.values.length > 0
|
||||
|
||||
WlrLayershell.namespace: "hyprchrome-notifications"
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
// Normal with no zone of its own: sits below the rail's exclusive zone.
|
||||
exclusionMode: ExclusionMode.Normal
|
||||
color: "transparent"
|
||||
|
||||
anchors {
|
||||
top: true
|
||||
right: true
|
||||
}
|
||||
|
||||
margins.top: 12
|
||||
margins.right: 16
|
||||
|
||||
// Slack on every side for the corner caps, which sit outside each card.
|
||||
implicitWidth: 360 + 8
|
||||
implicitHeight: Math.max(1, stack.implicitHeight + 8)
|
||||
|
||||
mask: Region {
|
||||
item: stack
|
||||
}
|
||||
|
||||
Column {
|
||||
id: stack
|
||||
|
||||
x: 4
|
||||
y: 4
|
||||
width: 360
|
||||
spacing: 14
|
||||
|
||||
Repeater {
|
||||
model: server.trackedNotifications
|
||||
|
||||
NotificationCard {
|
||||
id: card
|
||||
|
||||
required property Notification modelData
|
||||
|
||||
width: stack.width
|
||||
|
||||
appName: card.modelData.appName
|
||||
summary: card.modelData.summary
|
||||
body: card.modelData.body
|
||||
appIcon: card.modelData.appIcon
|
||||
image: card.modelData.image
|
||||
urgency: card.modelData.urgency
|
||||
time: root.arrived[card.modelData.id] ?? ""
|
||||
actions: card.modelData.actions
|
||||
timeout: root.timeoutFor(card.modelData)
|
||||
|
||||
onDismissed: card.modelData.dismiss()
|
||||
onExpired: card.modelData.expire()
|
||||
|
||||
// invoke() closes a non-resident notification itself.
|
||||
onActionInvoked: identifier => {
|
||||
const actions = card.modelData.actions;
|
||||
for (let i = 0; i < actions.length; i++) {
|
||||
if (actions[i].identifier === identifier) {
|
||||
actions[i].invoke();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Slides in from the right edge.
|
||||
opacity: 0
|
||||
transform: Translate { id: slide; x: 40 }
|
||||
Component.onCompleted: enter.start()
|
||||
|
||||
ParallelAnimation {
|
||||
id: enter
|
||||
|
||||
NumberAnimation { target: card; property: "opacity"; to: 1; duration: 160; easing.type: Easing.OutCubic }
|
||||
NumberAnimation { target: slide; property: "x"; to: 0; duration: 200; easing.type: Easing.OutCubic }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user