From 0b20e8eb855d68c207db571283ab3c8585ea9b33 Mon Sep 17 00:00:00 2001 From: Hannes Date: Tue, 25 Aug 2026 01:00:52 +0200 Subject: [PATCH] feat: add notification module with functionality to display notifications on focused monitor with a NotificationServer as Singleton --- modules/notification/Notification.qml | 72 +++++++++++++++++++ modules/notification/NotificationBody.qml | 69 ++++++++++++++++++ modules/notification/NotificationLoader.qml | 19 +++++ .../notificationServer/NotificationServer.qml | 50 +++++++++++++ .../notification/notificationServer/qmldir | 1 + shell.qml | 4 ++ 6 files changed, 215 insertions(+) create mode 100644 modules/notification/Notification.qml create mode 100644 modules/notification/NotificationBody.qml create mode 100644 modules/notification/NotificationLoader.qml create mode 100644 modules/notification/notificationServer/NotificationServer.qml create mode 100644 modules/notification/notificationServer/qmldir diff --git a/modules/notification/Notification.qml b/modules/notification/Notification.qml new file mode 100644 index 0000000..b018305 --- /dev/null +++ b/modules/notification/Notification.qml @@ -0,0 +1,72 @@ +import QtQuick +import Quickshell +import Quickshell.Services.Notifications +import "../../config" +import "./notificationServer" + +PanelWindow { + mask: Region {} + + id: notificationWindow + + anchors.top: true + anchors.left: true + + implicitHeight: screen.height/6 + implicitWidth: screen.width/6 + + color: "transparent" + + Connections { + target: NotificationS + + function onNotificationReceived(notification) { + if (!NotificationS.correctMonitor(screen)) + return + if (NotificationS.correctMonitor(screen)) { + console.log("[Notification]: This notification belongs to me!", screen.x, screen.y) + // currentNotifications.push(notification) + // currentNotifications = currentNotifications + currentNotification = notification + currentNotifications = currentNotifications.concat([notification]) + } + } + } + + property var currentNotification: null + property var currentNotifications: [] + + Rectangle { + anchors.fill: parent + + border.width: Config.border_width + border.color: Colors.primary + color: "transparent" + + Column { + anchors.fill: parent + anchors.margins: 10 + spacing: 5 + + Repeater { + model: currentNotifications + + delegate: NotificationBody { + required property int index + + notification: currentNotifications[index] + width: notificationWindow.width + } + } + } + } + Component.onCompleted: { + console.log( + "[Notification]:", + NotificationS, + "notification:", + NotificationS.newestNotification + + ) + } +} \ No newline at end of file diff --git a/modules/notification/NotificationBody.qml b/modules/notification/NotificationBody.qml new file mode 100644 index 0000000..00f9d5a --- /dev/null +++ b/modules/notification/NotificationBody.qml @@ -0,0 +1,69 @@ +import QtQuick +import Quickshell +import "../../config" + +Rectangle { + id: root + + required property var notification + + + Component.onCompleted: { + console.log( + "[NotificationBody]:", + notification, + "notification:", + notification.appName + ) + } + + implicitWidth: parent ? parent.width : 300 + implicitHeight: content.implicitHeight + 20 + + color: "transparent" + + border.width: Config.border_width + border.color: Colors.primary + + Column { + id: content + + anchors.fill: parent + anchors.margins: 10 + + spacing: 5 + + Text { + width: parent.width + + text: root.notification?.appName ?? "" + font.family: Config.font + font.pixelSize: 18 + color: Colors.primary + + elide: Text.ElideRight + } + + Text { + width: parent.width + + text: root.notification?.summary ?? "" + font.family: Config.font + font.pixelSize: 22 + color: Colors.primary + + wrapMode: Text.Wrap + } + + Text { + width: parent.width + + text: root.notification?.body ?? "" + font.family: Config.font + font.pixelSize: 16 + color: Colors.primary + + wrapMode: Text.Wrap + } + } +} \ No newline at end of file diff --git a/modules/notification/NotificationLoader.qml b/modules/notification/NotificationLoader.qml new file mode 100644 index 0000000..da5686e --- /dev/null +++ b/modules/notification/NotificationLoader.qml @@ -0,0 +1,19 @@ +import QtQuick +import Quickshell +import "./notificationServer" + + +Item { + id: notification_root + Repeater { // Bars + model: Quickshell.screens + delegate: Loader { + active: true // loads object + sourceComponent: Notification {screen: modelData} // creates instance of bar component + } + } + + Component.onCompleted: { + console.log("[NotificationLoader]:", NotificationS) + } +} \ No newline at end of file diff --git a/modules/notification/notificationServer/NotificationServer.qml b/modules/notification/notificationServer/NotificationServer.qml new file mode 100644 index 0000000..2e678ba --- /dev/null +++ b/modules/notification/notificationServer/NotificationServer.qml @@ -0,0 +1,50 @@ +pragma Singleton + +import QtQuick +import Quickshell +import Quickshell.Hyprland +import Quickshell.Services.Notifications + +Item { + id: notificationServerState + + property var focusedMonitor: null + property var newestNotification: null + property var trackedNotifications: [] // TODO + + signal notificationReceived(var notification) + + function correctMonitor(screen) { + return (Hyprland.monitorFor(screen) === focusedMonitor) + } + + NotificationServer { + id: notificationServer + onNotification: function(notification) { + if(notification.lastGeneration){ + console.log( + "[NotificationServer] Closing Notification:", + notification.appName, notification.id, notification.summary, notification.body + ) + notification.dismiss() + return + } + notification.tracked = true + console.log( + "[NotificationServer] Notification received:", + notification.appName, notification.id, notification.summary, notification.body + ) + notificationReceived(notification) + Hyprland.refreshMonitors() + waitTimer.start() + } + } + + Timer { + id: waitTimer + interval: 2000 + repeat: false + onTriggered: focusedMonitor = Hyprland.focusedMonitor + } + +} \ No newline at end of file diff --git a/modules/notification/notificationServer/qmldir b/modules/notification/notificationServer/qmldir new file mode 100644 index 0000000..b161e7b --- /dev/null +++ b/modules/notification/notificationServer/qmldir @@ -0,0 +1 @@ +singleton NotificationS NotificationServer.qml \ No newline at end of file diff --git a/shell.qml b/shell.qml index bb5c675..23232ca 100644 --- a/shell.qml +++ b/shell.qml @@ -4,6 +4,7 @@ import Quickshell //for PanelWindow import Quickshell.Hyprland import QtQuick //for Text import "./modules/bar" +import "./modules/notification" import "./modules/wp" import "./modules/wlogout" import "./modules/jl" @@ -16,6 +17,9 @@ ShellRoot { // Bar BarLoader {} + // Notifications + NotificationLoader {} + //Wallpaper picker WallpaperPickerLoader {}