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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user