From f2ed2e7a4e3ea912f37d1c001bc8fcd1eb68aa48 Mon Sep 17 00:00:00 2001 From: voidarc Date: Sun, 9 Aug 2026 12:48:34 +0100 Subject: [PATCH] notifications working --- Bar/Time.qml | 93 +++++++++++++++++++++++++++++++- Services/NotificationManager.qml | 3 ++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/Bar/Time.qml b/Bar/Time.qml index 777a090..6108dca 100644 --- a/Bar/Time.qml +++ b/Bar/Time.qml @@ -1,7 +1,9 @@ +pragma ComponentBehavior: Bound import QtQuick import QtQuick.Controls import Quickshell import Quickshell.Hyprland +import Quickshell.Services.Notifications import "../Color.js" as Colors import "../Components/" @@ -10,32 +12,121 @@ import "../Services/" Container { id: root + property Notification latestNotif + property double latestNotifId: latestNotif.id || 0 required property HyprlandMonitor monitor + property bool notified: false + property bool overriden: false boxColor: Colors.mauve defaultItem: time exclusiveMonitor: root.monitor states: [ + State { + name: "closed" + when: root.hovered == false && root.overriden == false + + PropertyChanges { + root.boxHeight: 28 + root.boxRadius: 9 + root.boxWidth: 100 + } + + StateChangeScript { + script: { + if (root.stack.currentItem.component != "time") { + root.stack.replace(time); + } + } + } + }, State { name: "hovered" - when: root.hovered == true + when: root.hovered == true && root.overriden == false PropertyChanges { root.boxHeight: 32 root.boxRadius: 12 root.boxWidth: 107 } + + StateChangeScript { + script: { + root.stack.replace(time); + } + } + }, + State { + name: "notified" + when: root.notified == true + + PropertyChanges { + root.boxHeight: 32 + root.boxRadius: 12 + root.boxWidth: 200 + } + + StateChangeScript { + script: { + root.stack.replace(notification); + console.log("notification"); + notificationTimer.restart(); + } + } } ] + Connections { + function onNewNotification() { + notification => { + if (notification != root.latestNotif) { + root.latestNotif = notification; + root.overriden = true; + root.notified = true; + } else { + console.log("notif already called"); + } + }; + } + + target: NotificationManager + } + + Timer { + id: notificationTimer + + interval: 2000 + repeat: false + running: false + + onTriggered: { + root.notified = false; + root.overriden = false; + } + } + Component { id: time StyledText { + property string component: "time" + horizontalAlignment: Qt.AlignCenter text: Time.time verticalAlignment: Qt.AlignVCenter } } + + Component { + id: notification + + StyledText { + property string component: "notification" + + horizontalAlignment: Qt.AlignCenter + text: root.latestNotif.summary + verticalAlignment: Qt.AlignVCenter + } + } } diff --git a/Services/NotificationManager.qml b/Services/NotificationManager.qml index 02981e3..62677ea 100644 --- a/Services/NotificationManager.qml +++ b/Services/NotificationManager.qml @@ -8,6 +8,8 @@ Singleton { property alias notif: server + signal newNotification(notificiation: Notification) + function getLatestNotification() { let notificationList = server.trackedNotifications.values; let len = notificationList.length; @@ -27,6 +29,7 @@ Singleton { onNotification: notification => { notification.tracked = true; + root.newNotification(notification); } } }