feat: add notification module with functionality to display notifications on focused monitor with a NotificationServer as Singleton

This commit is contained in:
Hannes
2026-08-25 01:00:52 +02:00
parent b9a455347d
commit 0b20e8eb85
6 changed files with 215 additions and 0 deletions
+72
View File
@@ -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
)
}
}
+69
View File
@@ -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
}
}
}
@@ -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)
}
}
@@ -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
}
}
@@ -0,0 +1 @@
singleton NotificationS NotificationServer.qml
+4
View File
@@ -4,6 +4,7 @@ import Quickshell //for PanelWindow
import Quickshell.Hyprland import Quickshell.Hyprland
import QtQuick //for Text import QtQuick //for Text
import "./modules/bar" import "./modules/bar"
import "./modules/notification"
import "./modules/wp" import "./modules/wp"
import "./modules/wlogout" import "./modules/wlogout"
import "./modules/jl" import "./modules/jl"
@@ -16,6 +17,9 @@ ShellRoot {
// Bar // Bar
BarLoader {} BarLoader {}
// Notifications
NotificationLoader {}
//Wallpaper picker //Wallpaper picker
WallpaperPickerLoader {} WallpaperPickerLoader {}