Files
quickshell/modules/notification/notificationServer/NotificationServer.qml
T

112 lines
3.7 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Hyprland
import Quickshell.Services.Notifications
import "../../../config"
Item {
id: notificationServerState
property var focusedMonitor: null
property var newestNotification: null
property bool notificationPopupEnabled: true
property alias trackedNotifications: notificationServer.trackedNotifications
property int notificationNum: trackedNotifications.values.length
signal notificationReceived(var notification)
// ── Hover state for history auto-close ──
// Updated by NotificationHistory.qml (PanelWindow hover) and NotificationButton.qml (bar button hover)
property bool historyHovered: false
property bool buttonHovered: false
property int historyAutoCloseDelay: 1000
signal closeHistoryRequested()
// Debug logging for hover transitions
onHistoryHoveredChanged: Config.debug == "Notification" && console.log("[NotificationServer] historyHovered:", historyHovered)
onButtonHoveredChanged: Config.debug == "Notification" && console.log("[NotificationServer] buttonHovered:", buttonHovered)
function correctMonitor(screen) {
return (Hyprland.monitorFor(screen) === focusedMonitor)
}
Process {
id: notificationSound
command: ["pw-play", "--volume", "0.25", Config.configDir + "/modules/notification/assets/notification.ogg"]
function play() {
if (running)
return
Config.debug == "Notification" && console.log(
"[NotificationSound] Playing:", Config.configDir + "/modules/notification/assets/notification.ogg"
)
notificationSound.startDetached()
}
}
NotificationServer {
id: notificationServer
actionsSupported: true
bodyHyperlinksSupported: true
bodyImagesSupported: true
actionIconsSupported: true
imageSupported: true
persistenceSupported: true
bodyMarkupSupported: true
inlineReplySupported: true
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
!notification.lastGeneration && Config.debug == "Notification" && console.log(
"[NotificationServer] Notification received:",
notification.appName, notification.id, notification.summary, notification.body
)
let timer = notificationTimerComponent.createObject(
notificationServerState,
{ notification: notification }
)
Hyprland.refreshMonitors()
timer.start()
}
}
Component {
id: notificationTimerComponent
Timer {
required property var notification
interval: 2000
repeat: false
onTriggered: {
if((!notification.lastGeneration && notificationServerState.notificationPopupEnabled) || Config.debug == "Notification"){
focusedMonitor = Hyprland.focusedMonitor
notificationReceived(notification)
notificationSound.play()
}
destroy()
}
}
}
Component.onCompleted: {
focusedMonitor = Hyprland.focusedMonitor
Config.debug == "Notification" && console.log("[NotificationServer]: Component completed")
}
}