From 65b4762c90f6e6a1c8dff9e28bd20f7b4a1aa1fe Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Thu, 24 Jul 2025 14:02:11 -0400 Subject: [PATCH] notification button --- config/Dimensions.qml | 8 +++++ constants/Icons.qml | 2 ++ modules/bar/Bar.qml | 10 ++++-- modules/bar/components/Notifications.qml | 44 ++++++++++++++++++++++++ services/Notifications.qml | 25 ++++++++++++++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 modules/bar/components/Notifications.qml create mode 100644 services/Notifications.qml diff --git a/config/Dimensions.qml b/config/Dimensions.qml index ff30181..afaa224 100644 --- a/config/Dimensions.qml +++ b/config/Dimensions.qml @@ -18,6 +18,7 @@ Singleton { property Cpu cpu: Cpu {} property Gpu gpu: Gpu {} property Caffeine caffeine: Caffeine {} + property Notifications notifications: Notifications {} property Workspace workspace: Workspace {} property Tray tray: Tray {} property TrayMenu trayMenu: TrayMenu {} @@ -100,6 +101,13 @@ Singleton { property int verticalPadding: 6 } + component Notifications: QtObject { + property int fontSize: 16 + property int height: 30 + property int horizontalPadding: 8 + property int verticalPadding: 6 + } + component Workspace: QtObject { property int spacing: 5 property int iconSize: 16 diff --git a/constants/Icons.qml b/constants/Icons.qml index c58b16c..f484252 100644 --- a/constants/Icons.qml +++ b/constants/Icons.qml @@ -3,6 +3,8 @@ pragma Singleton import Quickshell Singleton { + property string bell: "\u{E05d}" + property string bellRing: "\u{E224}" property string brickWall: "\u{E586}" property string coffee: "\u{E09a}" property string cpu: "\u{E0ad}" diff --git a/modules/bar/Bar.qml b/modules/bar/Bar.qml index f4ec4e0..5577879 100644 --- a/modules/bar/Bar.qml +++ b/modules/bar/Bar.qml @@ -59,9 +59,9 @@ Scope { anchors.verticalCenter: parent.verticalCenter } - Tray { - anchors.verticalCenter: parent.verticalCenter - } + // Tray { + // anchors.verticalCenter: parent.verticalCenter + // } } Row { @@ -127,6 +127,10 @@ Scope { Clock { anchors.verticalCenter: parent.verticalCenter } + + Notifications { + anchors.verticalCenter: parent.verticalCenter + } } } } diff --git a/modules/bar/components/Notifications.qml b/modules/bar/components/Notifications.qml new file mode 100644 index 0000000..c9c2b27 --- /dev/null +++ b/modules/bar/components/Notifications.qml @@ -0,0 +1,44 @@ +import QtQuick +import Quickshell.Io +import "../../../config/" +import "../../../constants/" +import "../../../services/" +import "../../../styled/" + +Clickable { + id: clickable + + implicitWidth: text.width + implicitHeight: Dimensions.notifications.height + + onClicked: { + Notifications.clear(); + } + + StyledText { + id: text + + font.family: Theme.lucide.font.family + font.pixelSize: Dimensions.notifications.fontSize + font.bold: true + text: Icons.bell + + color: clickable.containsMouse ? Theme.palette.base300 : Theme.palette.basecontent + + anchors.verticalCenter: parent.verticalCenter + topPadding: Dimensions.notifications.verticalPadding + bottomPadding: Dimensions.notifications.verticalPadding + leftPadding: Dimensions.notifications.horizontalPadding + rightPadding: Dimensions.notifications.horizontalPadding + + states: State { + when: Notifications.hasNotifications + PropertyChanges { + text { + text: Icons.bellRing + color: clickable.containsMouse ? Theme.palette.base300 : Theme.palette.secondary + } + } + } + } +} diff --git a/services/Notifications.qml b/services/Notifications.qml new file mode 100644 index 0000000..d860b2a --- /dev/null +++ b/services/Notifications.qml @@ -0,0 +1,25 @@ +pragma Singleton + +import Quickshell +import Quickshell.Services.Notifications + +Singleton { + id: root + + property bool hasNotifications: notifications.length > 0 + property list notifications: [] + + function clear() { + notifications.forEach(notification => { + notification.dismiss(); + }); + notifications = []; + } + + NotificationServer { + onNotification: event => { + event.tracked = true; + root.notifications.push(event); + } + } +}