diff --git a/modules/notifications/Notification.qml b/modules/notifications/Notification.qml index ceeef006..70f58af0 100644 --- a/modules/notifications/Notification.qml +++ b/modules/notifications/Notification.qml @@ -4,7 +4,6 @@ import QtQuick import QtQuick.Layouts import QtQuick.Shapes import Quickshell -import Quickshell.Widgets import Quickshell.Services.Notifications import Caelestia.Config import qs.components @@ -117,8 +116,9 @@ StyledRect { height: TokenConfig.sizes.notifs.image visible: root.hasImage || root.hasAppIcon - sourceComponent: ClippingRectangle { + sourceComponent: StyledClippingRect { radius: Tokens.rounding.full + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3error : root.modelData.urgency === NotificationUrgency.Low ? Colours.layer(Colours.palette.m3surfaceContainerHighest, 2) : Colours.palette.m3secondaryContainer implicitWidth: TokenConfig.sizes.notifs.image implicitHeight: TokenConfig.sizes.notifs.image diff --git a/modules/sidebar/NotifGroup.qml b/modules/sidebar/NotifGroup.qml index 25f531ec..57ee06b4 100644 --- a/modules/sidebar/NotifGroup.qml +++ b/modules/sidebar/NotifGroup.qml @@ -19,36 +19,17 @@ StyledRect { required property DrawerVisibilities visibilities readonly property list notifs: Notifs.list.filter(n => n.appName === modelData) - readonly property var groupProps: { - let count = 0; - let img = ""; - let icon = ""; - let hasCritical = false; - let hasNormal = false; - for (const n of notifs) { - if (!n.closed) { - count++; - if (!img && n.image.length > 0) - img = n.image; - if (!icon && n.appIcon.length > 0) - icon = n.appIcon; - if (n.urgency === NotificationUrgency.Critical) - hasCritical = true; - else if (n.urgency === NotificationUrgency.Normal) - hasNormal = true; - } - } - return { - count, - img, - icon, - urgency: hasCritical ? NotificationUrgency.Critical : hasNormal ? NotificationUrgency.Normal : NotificationUrgency.Low - }; + readonly property list activeNotifs: notifs.filter(n => !n.closed) + readonly property int notifCount: activeNotifs.length + readonly property string image: activeNotifs.find(n => n.image.length > 0)?.image ?? "" + readonly property string appIcon: activeNotifs.find(n => n.appIcon.length > 0)?.appIcon ?? "" + readonly property int urgency: { + if (activeNotifs.find(n => n.urgency === NotificationUrgency.Critical)) + return NotificationUrgency.Critical; + if (activeNotifs.find(n => n.urgency === NotificationUrgency.Normal)) + return NotificationUrgency.Normal; + return NotificationUrgency.Low; } - readonly property int notifCount: groupProps.count - readonly property string image: groupProps.img - readonly property string appIcon: groupProps.icon - readonly property int urgency: groupProps.urgency readonly property int nonAnimHeight: { const headerHeight = header.implicitHeight + (root.expanded ? Math.round(Tokens.spacing.small / 2) : 0); @@ -130,7 +111,7 @@ StyledRect { id: materialIconComp MaterialIcon { - text: Icons.getNotifIcon(root.notifs[0]?.summary, root.urgency) + text: Icons.getNotifIcon(root.activeNotifs[0]?.summary, root.urgency) color: root.urgency === NotificationUrgency.Critical ? Colours.palette.m3onError : root.urgency === NotificationUrgency.Low ? Colours.palette.m3onSurface : Colours.palette.m3onSecondaryContainer font.pointSize: Tokens.font.size.large } @@ -199,7 +180,7 @@ StyledRect { StyledText { animate: true - text: root.notifs.find(n => !n.closed)?.timeStr ?? "" + text: root.activeNotifs[0]?.timeStr ?? "" color: Colours.palette.m3outline font.pointSize: Tokens.font.size.small } diff --git a/services/NotifData.qml b/services/NotifData.qml index 6f470038..33794243 100644 --- a/services/NotifData.qml +++ b/services/NotifData.qml @@ -64,7 +64,7 @@ QtObject { if (status !== Image.Ready || width != TokenConfig.sizes.notifs.image || height != TokenConfig.sizes.notifs.image) return; - const cacheKey = notif.appName + notif.summary + notif.id; + const cacheKey = notif.appName + notif.summary + notif.id + notif.image; let h1 = 0xdeadbeef, h2 = 0x41c6ce57, ch; for (let i = 0; i < cacheKey.length; i++) { ch = cacheKey.charCodeAt(i); @@ -77,7 +77,6 @@ QtObject { h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909); const hash = (h2 >>> 0).toString(16).padStart(8, 0) + (h1 >>> 0).toString(16).padStart(8, 0); - Paths; // Screw you qmlls const cache = `${Paths.notifimagecache}/${hash}.png`; CUtils.saveItem(this, Qt.resolvedUrl(cache), () => { notif.image = cache; @@ -122,8 +121,7 @@ QtObject { function onImageChanged(): void { notif.image = notif.notification.image; - if (notif.notification?.image) - notif.dummyImageLoader.active = true; + notif.maybeTriggerDummyImageLoader(); } function onExpireTimeoutChanged(): void { @@ -183,6 +181,11 @@ QtObject { } } + function maybeTriggerDummyImageLoader(): void { + if (image && !image.startsWith("image://icon/") && !image.startsWith(Paths.notifimagecache)) + dummyImageLoader.active = true; + } + function lock(item: Item): void { locks.add(item); } @@ -212,8 +215,7 @@ QtObject { appIcon = notification.appIcon; appName = notification.appName; image = notification.image; - if (notification?.image) - dummyImageLoader.active = true; + maybeTriggerDummyImageLoader(); expireTimeout = notification.expireTimeout; hints = notification.hints; urgency = notification.urgency;