repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

notifications: shared NotificationCard (icon/image/wrap/feedback) + popup header, drop drag rig

6eacd8adce73b46db625fee9d4b2455da2475e04

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Changed files (2)

quickshell/nuguland/NotificationCard.qml

Added
new file mode 100644
1 +import QtQuick
2 +import Quickshell.Widgets
4 +Rectangle {
5 + id: card
7 + required property QtObject theme
8 + required property var modelData
9 + property bool compact: false
10 + signal dismiss(string id)
11 + signal invokeAction(string id, string actionId)
13 + // local text styling, mirrors PopoutHost NuguText variants
14 + component CardText: Text {
15 + required property QtObject theme
16 + property string variant: "body"
17 + color: !theme ? "transparent" : (variant === "title" ? theme.ui.important_global : (variant === "meta" ? theme.ui.normal : theme.content.normal))
18 + font.family: variant === "mono" ? "IBM Plex Mono" : "IBM Plex Sans"
19 + font.pixelSize: variant === "title" ? 15 : (variant === "meta" ? 13 : 14)
20 + font.bold: variant === "title"
21 + elide: Text.ElideRight
22 + }
24 + function urgencyColor() {
25 + const u = String(modelData.urgency || "normal");
26 + if (!theme)
27 + return "transparent";
28 + if (u === "critical")
29 + return theme.error;
30 + if (u === "low")
31 + return theme.ui.minor;
32 + return theme.ui.accent;
33 + }
35 + function relTime(ms) {
36 + const now = Date.now();
37 + const diff = Math.max(0, now - Number(ms || now));
38 + const m = Math.floor(diff / 60000);
39 + if (m < 1)
40 + return "now";
41 + if (m < 60)
42 + return `${m}m`;
43 + const h = Math.floor(m / 60);
44 + if (h < 24)
45 + return `${h}h`;
46 + return `${Math.floor(h / 24)}d`;
47 + }
49 + radius: compact ? 12 : 10
50 + color: theme ? theme.withAlpha(theme.ui.backdrop, 0.92) : "transparent"
51 + implicitHeight: cardBody.implicitHeight + (compact ? 16 : 20)
52 + clip: true
54 + Rectangle {
55 + anchors.left: parent.left
56 + anchors.top: parent.top
57 + anchors.bottom: parent.bottom
58 + width: 3
59 + radius: 2
60 + color: card.urgencyColor()
61 + visible: String(card.modelData.urgency || "normal") !== "low"
62 + }
64 + MouseArea {
65 + anchors.fill: parent
66 + acceptedButtons: Qt.LeftButton
67 + enabled: card.compact
68 + onClicked: card.dismiss(String(card.modelData.id))
69 + }
71 + Row {
72 + id: cardBody
73 + anchors.left: parent.left
74 + anchors.right: parent.right
75 + anchors.verticalCenter: parent.verticalCenter
76 + anchors.leftMargin: 12
77 + anchors.rightMargin: 10
78 + spacing: 10
80 + IconImage {
81 + anchors.verticalCenter: card.compact ? parent.verticalCenter : undefined
82 + width: card.compact ? 20 : 36
83 + height: width
84 + source: card.modelData.appIcon || ""
85 + visible: source.toString().length > 0
86 + }
88 + Column {
89 + width: parent.width - (card.compact ? 30 : 46) - closeCol.width
90 + spacing: card.compact ? 0 : 3
92 + Row {
93 + width: parent.width
94 + spacing: 6
95 + visible: !card.compact
96 + CardText {
97 + theme: card.theme
98 + variant: "meta"
99 + text: card.modelData.appName || "unknown"
100 + width: parent.width - timeText.width - parent.spacing
101 + elide: Text.ElideRight
103 + CardText {
104 + id: timeText
105 + theme: card.theme
106 + variant: "meta"
107 + text: card.relTime(card.modelData.time)
111 + CardText {
112 + theme: card.theme
113 + variant: card.compact ? "body" : "title"
114 + text: card.modelData.summary || "notification"
115 + width: parent.width
116 + elide: Text.ElideRight
119 + CardText {
120 + theme: card.theme
121 + variant: "meta"
122 + text: card.modelData.body || ""
123 + width: parent.width
124 + visible: !card.compact && text.length > 0
125 + wrapMode: Text.WordWrap
126 + maximumLineCount: 3
127 + elide: Text.ElideRight
130 + Image {
131 + source: card.modelData.image || ""
132 + visible: !card.compact && status === Image.Ready
133 + width: Math.min(parent.width, 220)
134 + fillMode: Image.PreserveAspectFit
135 + sourceSize.width: 220
138 + Flow {
139 + width: parent.width
140 + spacing: 6
141 + visible: !card.compact && actionModel.length > 0
142 + property var actionModel: (card.modelData.actionRows || []).filter((a) => a.kind !== "close")
143 + Repeater {
144 + model: parent.actionModel
145 + delegate: Rectangle {
146 + id: actionBtn
147 + required property var modelData
148 + height: 26
149 + width: Math.max(58, actLabel.implicitWidth + 18)
150 + radius: 8
151 + color: {
152 + if (!card.theme)
153 + return "transparent";
154 + if (actArea.pressed)
155 + return card.theme.withAlpha(card.theme.ui.accent, 0.34);
156 + if (actArea.containsMouse)
157 + return card.theme.withAlpha(card.theme.ui.accent, 0.24);
158 + return card.theme.withAlpha(card.theme.ui.accent, 0.14);
160 + CardText {
161 + id: actLabel
162 + anchors.centerIn: parent
163 + theme: card.theme
164 + variant: "meta"
165 + text: actionBtn.modelData.label || "act"
167 + MouseArea {
168 + id: actArea
169 + anchors.fill: parent
170 + hoverEnabled: true
171 + onClicked: card.invokeAction(String(card.modelData.id), String(actionBtn.modelData.id))
173 + Behavior on color {
174 + ColorAnimation { duration: card.theme && card.theme.lowPowerMode ? 0 : 120 }
181 + Item {
182 + id: closeCol
183 + width: card.compact ? 0 : 24
184 + height: card.compact ? 0 : 24
185 + visible: !card.compact
186 + Rectangle {
187 + anchors.fill: parent
188 + radius: 12
189 + color: closeArea.containsMouse && card.theme ? card.theme.withAlpha(card.theme.ui.minor, 0.25) : "transparent"
190 + opacity: cardHover.hovered || closeArea.containsMouse ? 1 : 0
191 + CardText {
192 + anchors.centerIn: parent
193 + theme: card.theme
194 + variant: "mono"
195 + text: "×"
197 + Behavior on opacity { NumberAnimation { duration: 120 } }
199 + MouseArea {
200 + id: closeArea
201 + anchors.fill: parent
202 + hoverEnabled: true
203 + onClicked: card.dismiss(String(card.modelData.id))
208 + HoverHandler { id: cardHover }

quickshell/nuguland/PopoutHost.qml

Modified
1239 1239 required property QtObject theme
1240 1240 required property QtObject notificationService
1241 - property var state: notificationService ? Util.parseJson(notificationService.stateJson(), {
1242 - "groups": [],
1243 - "notificationPanelContract": {
1245 - }) : ({
1246 - "groups": [],
1247 - "notificationPanelContract": {
1249 - })
1241 + property var state: notificationService ? Util.parseJson(notificationService.stateJson(), {"groups": [], "dnd": false, "activeCount": 0}) : ({"groups": [], "dnd": false, "activeCount": 0})
1250 1242 readonly property var groups: state.groups || []
1251 - readonly property var panel: state.notificationPanelContract || ({
1252 - })
1255 - function roleColor(role) {
1256 - if (!theme)
1257 - return "transparent";
1259 - if (role === "critical")
1260 - return theme.error;
1262 - if (role === "normal")
1263 - return theme.ui.accent;
1265 - return theme.ui.minor;
1268 - function runAction(notificationId, actionId) {
1244 + function runAction(id, actionId) {
1269 1245 if (notificationService)
1270 - state = Util.parseJson(notificationService.runAction(notificationId, actionId), state);
1246 + state = Util.parseJson(notificationService.runAction(id, actionId), state);
1274 1248 function toggleGroup(appName) {
1275 1249 if (notificationService)
1276 1250 state = Util.parseJson(notificationService.toggleGroup(appName), state);
1280 - function dragNotification(notificationId, deltaX, rowWidth) {
1252 + function toggleDnd() {
1281 1253 if (notificationService)
1282 - state = Util.parseJson(notificationService.dragNotification(notificationId, deltaX, rowWidth), state);
1254 + state = Util.parseJson(notificationService.toggleDnd(), state);
1286 - function recordPointerEvent(kind, notificationId, x, y, deltaX) {
1287 - if (notificationService && typeof notificationService.recordPointerEvent === "function")
1288 - notificationService.recordPointerEvent(kind, notificationId, x, y, deltaX);
1256 + function clearAll() {
1257 + if (notificationService)
1258 + state = Util.parseJson(notificationService.discardAllNotifications(), state);
1292 1261 spacing: 8
1293 1262 width: parent ? parent.width : 0
1264 + Item {
1265 + width: parent.width
1266 + height: 28
1267 + NuguText {
1268 + anchors.left: parent.left
1269 + anchors.verticalCenter: parent.verticalCenter
1270 + theme: root.theme
1271 + variant: "title"
1272 + text: `Notifications${root.state.activeCount ? " · " + root.state.activeCount : ""}`
1274 + Row {
1275 + anchors.right: parent.right
1276 + anchors.verticalCenter: parent.verticalCenter
1277 + spacing: 8
1278 + Rectangle {
1279 + width: dndLabel.implicitWidth + 18
1280 + height: 24
1281 + radius: 8
1282 + color: root.theme ? root.theme.withAlpha(root.state.dnd ? root.theme.ui.accent : root.theme.ui.minor, root.state.dnd ? 0.3 : 0.12) : "transparent"
1283 + NuguText { id: dndLabel; anchors.centerIn: parent; theme: root.theme; variant: "meta"; text: root.state.dnd ? "DND on" : "DND" }
1284 + MouseArea { anchors.fill: parent; onClicked: root.toggleDnd() }
1286 + Rectangle {
1287 + width: clearLabel.implicitWidth + 18
1288 + height: 24
1289 + radius: 8
1290 + visible: (root.state.activeCount || 0) > 0
1291 + color: clearArea.containsMouse && root.theme ? root.theme.withAlpha(root.theme.error, 0.24) : (root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.12) : "transparent")
1292 + NuguText { id: clearLabel; anchors.centerIn: parent; theme: root.theme; variant: "meta"; text: "Clear all" }
1293 + MouseArea { id: clearArea; anchors.fill: parent; hoverEnabled: true; onClicked: root.clearAll() }
1298 + Item {
1299 + width: parent.width
1300 + height: 220
1301 + visible: root.groups.length === 0
1302 + Column {
1303 + anchors.centerIn: parent
1304 + spacing: 8
1305 + NuguText { anchors.horizontalCenter: parent.horizontalCenter; theme: root.theme; variant: "title"; text: "No notifications" }
1306 + NuguText { anchors.horizontalCenter: parent.horizontalCenter; theme: root.theme; variant: "meta"; text: "You're all caught up" }
1295 1310 Repeater {
1296 1311 model: root.groups
1298 - delegate: Rectangle {
1299 - id: groupCard
1312 + delegate: Column {
1313 + id: groupDelegate
1301 1314 required property var modelData
1302 - property real dragLastX: 0
1303 - property real dragAccumX: 0
1305 1315 width: root.width
1306 - implicitHeight: groupColumn.implicitHeight + 16
1307 - radius: 12
1308 - color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.12) : "transparent"
1309 - border.width: 0
1310 - border.color: root.roleColor(modelData.urgency)
1311 - clip: true
1313 - Column {
1314 - id: groupColumn
1316 - anchors.left: parent.left
1317 - anchors.right: parent.right
1318 - anchors.top: parent.top
1319 - anchors.margins: 8
1320 - spacing: 6
1316 + spacing: 6
1318 + Item {
1319 + width: parent.width
1320 + height: (groupDelegate.modelData.count || 0) > 1 ? 22 : 0
1321 + visible: (groupDelegate.modelData.count || 0) > 1
1323 - width: parent.width
1324 - spacing: 8
1326 - Rectangle {
1327 - objectName: "appMediaSlot"
1328 - width: 28
1329 - height: 28
1330 - radius: 8
1331 - color: root.roleColor(groupCard.modelData.urgency)
1333 - NuguText {
1334 - anchors.centerIn: parent
1335 - theme: root.theme
1336 - variant: "mono"
1337 - selected: true
1338 - text: String(groupCard.modelData.appName || "?").slice(0, 1)
1343 - Column {
1344 - width: parent.width - 92
1345 - spacing: 0
1347 - NuguText {
1348 - theme: root.theme
1349 - text: groupCard.modelData.appName || "unknown"
1350 - width: parent.width
1351 - elide: Text.ElideRight
1354 - NuguText {
1355 - theme: root.theme
1356 - variant: "meta"
1357 - text: `${groupCard.modelData.count || 0} · ${groupCard.modelData.urgency || "normal"} · ${groupCard.modelData.expandCollapseState || "collapsed"}`
1358 - width: parent.width
1359 - elide: Text.ElideRight
1364 - Rectangle {
1365 - objectName: "expandPill"
1366 - width: 48
1367 - height: 24
1368 - radius: 12
1369 - color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.22) : "transparent"
1370 - border.width: 0
1371 - border.color: root.theme ? root.theme.ui.accent : "transparent"
1373 - NuguText {
1374 - anchors.centerIn: parent
1375 - theme: root.theme
1376 - variant: "mono"
1377 - text: `${groupCard.modelData.count || 0}${groupCard.modelData.expanded ? "^" : "v"}`
1380 - MouseArea {
1381 - anchors.fill: parent
1382 - onClicked: root.toggleGroup(groupCard.modelData.appName || "")
1323 + anchors.left: parent.left
1324 + anchors.verticalCenter: parent.verticalCenter
1325 + spacing: 6
1326 + NuguText { theme: root.theme; variant: "meta"; text: groupDelegate.modelData.appName || "" }
1327 + NuguText { theme: root.theme; variant: "meta"; text: `· ${groupDelegate.modelData.count}` }
1389 - Repeater {
1390 - model: groupCard.modelData.visibleNotifications || []
1392 - delegate: Rectangle {
1393 - id: notifCard
1395 - required property var modelData
1396 - property real pressX: 0
1397 - property real lastDragX: 0
1398 - property real dragAccumX: 0
1400 - width: groupColumn.width
1401 - implicitHeight: notifColumn.implicitHeight + 12
1402 - radius: 10
1403 - x: 0
1404 - color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.82) : "transparent"
1405 - border.width: 0
1406 - border.color: root.theme ? root.theme.ui.minor : "transparent"
1407 - clip: true
1409 - MouseArea {
1410 - anchors.fill: parent
1411 - acceptedButtons: Qt.LeftButton | Qt.MiddleButton
1412 - drag.target: notifCard
1413 - drag.axis: Drag.XAxis
1414 - onPressed: (event) => {
1415 - notifCard.pressX = event.x;
1416 - notifCard.lastDragX = event.x;
1417 - notifCard.dragAccumX = 0;
1418 - root.recordPointerEvent("row-press", notifCard.modelData.id, event.x, event.y, 0);
1420 - onPositionChanged: (event) => {
1421 - if (pressed && pressedButtons & Qt.LeftButton) {
1422 - notifCard.dragAccumX = Math.max(0, notifCard.dragAccumX + event.x - notifCard.lastDragX);
1423 - notifCard.lastDragX = event.x;
1424 - notifCard.x = notifCard.dragAccumX;
1425 - root.recordPointerEvent("row-drag", notifCard.modelData.id, event.x, event.y, notifCard.dragAccumX);
1428 - onClicked: (event) => {
1429 - if (event.button === Qt.MiddleButton)
1430 - root.runAction(notifCard.modelData.id, "close");
1433 - onReleased: (event) => {
1434 - const dragged = notifCard.x;
1435 - root.recordPointerEvent("row-release", notifCard.modelData.id, event.x, event.y, dragged);
1436 - root.dragNotification(notifCard.modelData.id, dragged, Math.max(1, notifCard.width));
1437 - notifCard.x = 0;
1441 - Column {
1442 - id: notifColumn
1444 - anchors.left: parent.left
1445 - anchors.right: parent.right
1446 - anchors.top: parent.top
1447 - anchors.margins: 6
1448 - spacing: 6
1450 - NuguText {
1451 - theme: root.theme
1452 - text: notifCard.modelData.summary || "notification"
1453 - width: parent.width
1454 - elide: Text.ElideRight
1457 - NuguText {
1458 - theme: root.theme
1459 - variant: "meta"
1460 - text: notifCard.modelData.body || ""
1461 - width: parent.width
1462 - elide: Text.ElideRight
1465 - Item {
1466 - objectName: "maskedHorizontalActionRail"
1467 - width: parent.width
1468 - height: 24
1469 - clip: true
1471 - Row {
1472 - spacing: 6
1474 - Repeater {
1475 - model: notifCard.modelData.actionRows || []
1477 - delegate: Rectangle {
1478 - id: actionButton
1480 - required property var modelData
1482 - height: 24
1483 - width: Math.max(58, actionText.implicitWidth + 18)
1484 - radius: 8
1485 - color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.16) : "transparent"
1486 - border.width: 0
1487 - border.color: root.theme ? root.theme.ui.accent : "transparent"
1489 - NuguText {
1490 - id: actionText
1492 - anchors.centerIn: parent
1493 - theme: root.theme
1494 - variant: "meta"
1495 - text: actionButton.modelData.label || actionButton.modelData.kind || "act"
1498 - MouseArea {
1499 - anchors.fill: parent
1500 - onClicked: root.runAction(notifCard.modelData.id, actionButton.modelData.id)
1509 - Rectangle {
1510 - anchors.left: parent.left
1511 - anchors.top: parent.top
1512 - anchors.bottom: parent.bottom
1513 - width: 14
1514 - color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.72) : "transparent"
1517 - Rectangle {
1518 - anchors.right: parent.right
1519 - anchors.top: parent.top
1520 - anchors.bottom: parent.bottom
1521 - width: 14
1522 - color: root.theme ? root.theme.withAlpha(root.theme.ui.backdrop, 0.72) : "transparent"
1329 + NuguText {
1330 + anchors.right: parent.right
1331 + anchors.verticalCenter: parent.verticalCenter
1332 + theme: root.theme
1333 + variant: "mono"
1334 + text: groupDelegate.modelData.expanded ? "⌃" : "⌄"
1336 + MouseArea { anchors.fill: parent; onClicked: root.toggleGroup(groupDelegate.modelData.appName || "") }
1535 - MouseArea {
1536 - anchors.fill: parent
1537 - z: 999
1538 - acceptedButtons: Qt.LeftButton
1539 - propagateComposedEvents: true
1540 - onPressed: (event) => {
1541 - groupCard.dragLastX = event.x;
1542 - groupCard.dragAccumX = 0;
1543 - const list = groupCard.modelData.visibleNotifications || [];
1544 - root.recordPointerEvent("group-press", list.length > 0 ? list[0].id : "", event.x, event.y, 0);
1545 - event.accepted = false;
1547 - onPositionChanged: (event) => {
1548 - if (pressed && pressedButtons & Qt.LeftButton) {
1549 - groupCard.dragAccumX = Math.max(0, groupCard.dragAccumX + event.x - groupCard.dragLastX);
1550 - groupCard.dragLastX = event.x;
1551 - const list = groupCard.modelData.visibleNotifications || [];
1552 - root.recordPointerEvent("group-drag", list.length > 0 ? list[0].id : "", event.x, event.y, groupCard.dragAccumX);
1555 - onReleased: (event) => {
1556 - const list = groupCard.modelData.visibleNotifications || [];
1557 - root.recordPointerEvent("group-release", list.length > 0 ? list[0].id : "", event.x, event.y, groupCard.dragAccumX);
1558 - if (list.length > 0 && groupCard.dragAccumX > 0)
1559 - root.dragNotification(list[0].id, groupCard.dragAccumX, Math.max(1, groupCard.width - 16));
1561 - event.accepted = groupCard.dragAccumX > 0;
1562 - groupCard.dragAccumX = 0;
1564 - onClicked: (event) => {
1565 - return event.accepted = false;
1339 + Repeater {
1340 + model: groupDelegate.modelData.visibleNotifications || []
1341 + delegate: NotificationCard {
1342 + width: root.width
1343 + theme: root.theme
1344 + onDismiss: (id) => root.runAction(id, "close")
1345 + onInvokeAction: (id, actionId) => root.runAction(id, actionId)
1569 - Behavior on implicitHeight {
1570 - NumberAnimation {
1571 - duration: root.theme && root.theme.lowPowerMode ? 0 : 180
1572 - easing.type: Easing.OutCubic
1581 - NuguText {
1582 - visible: root.groups.length === 0
1583 - theme: root.theme
1584 - variant: "meta"
1585 - text: "no notifications"
1590 1352 component FailureShake: Item {