Files
quickshell/modules/notification/Notification.qml
T

106 lines
3.4 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Hyprland
import Quickshell.Services.Notifications
import "../../config"
import "./notificationServer"
PanelWindow {
// mask: Region {}
id: notificationWindow
focusable: true
anchors.top: true
anchors.left: true
// implicitHeight: screen.height/6
implicitHeight: Math.max(contentHeight+(content.spacing*(notificationListModel.count-1)), 0)
implicitWidth: contentWidth
color: "transparent"
ListModel {
id: notificationListModel
}
Connections {
target: NotificationS
function onNotificationReceived(notification) {
if (!NotificationS.correctMonitor(screen))
return
if (NotificationS.correctMonitor(screen)) {
Config.debug == "Notification" && console.log("[NotificationWindow " + Hyprland.monitorFor(screen).activeWorkspace.id + "]: This notification belongs to me! ")
notificationListModel.append({notificationData: notification})
}
}
}
Rectangle {
anchors.fill: parent
border.width: Config.border_width
border.color: Colors.primary
color: "transparent"
Column {
id: content
anchors.fill: parent
spacing: -2
Repeater {
id: notificationRepeater
model: notificationListModel
delegate: NotificationBody {
required property int index
required property var notificationData
implicitWidth: screen.width/7
screen: notificationWindow.screen
notification: notificationData
onDismissed: function(notification, dismiss) {
const appName = notification.appName
const id = notification.id
const summary = notification.summary
if (dismiss) {
Config.debug == "Notification" && console.log("[NotificationWindow " + Hyprland.monitorFor(screen).activeWorkspace.id + "]: Dissmiss: " + appName + " " + id + " - " + summary)
if (notification.tracked) {notification.dismiss()}
notificationListModel.remove(index)
} else {
Config.debug == "Notification" && console.log("[NotificationWindow " + Hyprland.monitorFor(screen).activeWorkspace.id + "]: Close: " + appName + " " + id + " - " + summary)
notificationListModel.remove(index)
}
}
}
onItemAdded: updateContentSize()
onItemRemoved: updateContentSize()
}
}
}
property real contentWidth: 0
property real contentHeight: 0
function updateContentSize() {
let width = 0
let height = 0
for (let i = 0; i < notificationRepeater.count; ++i) {
let item = notificationRepeater.itemAt(i)
if (item) {
width = Math.max(width, item.width)
height += item.height
}
}
contentWidth = width
contentHeight = height
Config.debug == "Notification" && console.log("[updateContentSize] contentWidth:", contentWidth, "contentHeight:", contentHeight)
}
}