summaryrefslogtreecommitdiffstats
path: root/quickshell/modules/notifications
diff options
context:
space:
mode:
authorcoast <coasteen@proton.me>2026-10-13 05:03:11 +0330
committercoast <coasteen@proton.me>2026-10-13 05:03:11 +0330
commit8c5c2d270fd0f3bbc276e3b1cc28fc1dfae3fa59 (patch)
treea18e4d6016c4df3ca97e017b9f9d351398e950da /quickshell/modules/notifications
downloadcoast-newdot-8c5c2d270fd0f3bbc276e3b1cc28fc1dfae3fa59.tar.gz
coast-newdot-8c5c2d270fd0f3bbc276e3b1cc28fc1dfae3fa59.tar.bz2
coast-newdot-8c5c2d270fd0f3bbc276e3b1cc28fc1dfae3fa59.tar.xz
coast-newdot-8c5c2d270fd0f3bbc276e3b1cc28fc1dfae3fa59.tar.zst
init
Diffstat (limited to 'quickshell/modules/notifications')
-rw-r--r--quickshell/modules/notifications/NotificationCard.qml257
-rw-r--r--quickshell/modules/notifications/NotificationFocus.qml239
-rw-r--r--quickshell/modules/notifications/Notifications.qml125
3 files changed, 621 insertions, 0 deletions
diff --git a/quickshell/modules/notifications/NotificationCard.qml b/quickshell/modules/notifications/NotificationCard.qml
new file mode 100644
index 0000000..983cbd7
--- /dev/null
+++ b/quickshell/modules/notifications/NotificationCard.qml
@@ -0,0 +1,257 @@
+import QtQuick
+import QtQuick.Layouts
+import Quickshell.Services.Notifications
+import "../../config.js" as Config
+
+Rectangle {
+ id: root
+
+ required property var notification
+
+ signal activated()
+
+ property bool dismissing: false
+
+ Layout.fillWidth: true
+
+ implicitHeight: body.implicitHeight + 20
+
+ radius: Config.blockRadius
+
+ color: Config.barBackground
+
+ border.width: 1
+ border.color: Config.notificationBorder
+
+ x: dismissing ? Config.notificationSlideDistance : 0
+ opacity: dismissing ? 0 : 1
+
+ Component.onCompleted: {
+ x = Config.notificationSlideDistance
+ opacity = 0
+
+ enterAnimation.start()
+
+ if (notification.urgency !== NotificationUrgency.Critical)
+ dismissTimer.start()
+ }
+
+ Timer {
+ id: dismissTimer
+
+ interval: Config.notificationTimeout
+ repeat: false
+
+ onTriggered: {
+ dismiss()
+ }
+ }
+
+ function dismiss() {
+ if (dismissing)
+ return
+
+ dismissTimer.stop()
+ dismissing = true
+ exitAnimation.start()
+ }
+
+ SequentialAnimation {
+ id: enterAnimation
+
+ ParallelAnimation {
+ NumberAnimation {
+ target: root
+ property: "x"
+ from: Config.notificationSlideDistance
+ to: 0
+ duration: Config.notificationAnimationDuration
+ easing.type: Easing.OutCubic
+ }
+
+ NumberAnimation {
+ target: root
+ property: "opacity"
+ from: 0
+ to: 1
+ duration: Config.notificationAnimationDuration
+ easing.type: Easing.OutCubic
+ }
+ }
+ }
+
+ SequentialAnimation {
+ id: exitAnimation
+
+ ParallelAnimation {
+ NumberAnimation {
+ target: root
+ property: "x"
+ to: Config.notificationSlideDistance
+ duration: Config.notificationAnimationDuration
+ easing.type: Easing.InCubic
+ }
+
+ NumberAnimation {
+ target: root
+ property: "opacity"
+ to: 0
+ duration: Config.notificationAnimationDuration
+ easing.type: Easing.InCubic
+ }
+ }
+
+ ScriptAction {
+ script: root.notification.expire()
+ }
+ }
+
+ ColumnLayout {
+ id: body
+
+ anchors.fill: parent
+ anchors.margins: 10
+
+ spacing: 6
+
+ RowLayout {
+ Layout.fillWidth: true
+
+ Image {
+ visible: root.notification.appIcon !== ""
+
+ source: root.notification.appIcon
+
+ sourceSize.width: 24
+ sourceSize.height: 24
+
+ Layout.preferredWidth: 24
+ Layout.preferredHeight: 24
+
+ fillMode: Image.PreserveAspectFit
+ asynchronous: true
+ }
+
+ Text {
+ Layout.fillWidth: true
+
+ text: root.notification.appName || "Notification"
+
+ color: Config.textPrimary
+
+ font.family: Config.fontFamily
+ font.pixelSize: 12
+ font.bold: true
+
+ elide: Text.ElideRight
+ }
+
+ Text {
+ text: "×"
+
+ color: "#6c7086"
+
+ font.family: Config.fontFamily
+ font.pixelSize: 18
+ font.bold: true
+
+ MouseArea {
+ anchors.fill: parent
+
+ cursorShape: Qt.PointingHandCursor
+
+ onClicked: {
+ root.dismiss()
+ }
+ }
+ }
+ }
+
+ Text {
+ Layout.fillWidth: true
+
+ text: root.notification.summary
+
+ color: Config.textPrimary
+
+ font.family: Config.fontFamily
+ font.pixelSize: Config.fontSize
+ font.bold: true
+
+ wrapMode: Text.Wrap
+ }
+
+ Text {
+ visible: root.notification.body !== ""
+
+ Layout.fillWidth: true
+
+ text: root.notification.body
+
+ color: Config.textSecondary
+
+ font.family: Config.fontFamily
+ font.pixelSize: 12
+
+ wrapMode: Text.Wrap
+
+ maximumLineCount: 4
+ elide: Text.ElideRight
+ }
+
+ Rectangle {
+ Layout.fillWidth: true
+ Layout.preferredHeight: 3
+
+ radius: 2
+
+ gradient: Gradient {
+ GradientStop {
+ position: 0.0
+ color: Config.accentGreen
+ }
+
+ GradientStop {
+ position: 0.33
+ color: Config.accentYellow
+ }
+
+ GradientStop {
+ position: 0.66
+ color: Config.accentOrange
+ }
+
+ GradientStop {
+ position: 1.0
+ color: Config.accentRed
+ }
+ }
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+
+ cursorShape: Qt.PointingHandCursor
+
+ onClicked: {
+ root.activated()
+ }
+ }
+
+ MouseArea {
+ anchors.right: parent.right
+ anchors.top: parent.top
+
+ width: 36
+ height: 36
+
+ z: 10
+
+ cursorShape: Qt.PointingHandCursor
+
+ onClicked: {
+ root.dismiss()
+ }
+ }
+}
diff --git a/quickshell/modules/notifications/NotificationFocus.qml b/quickshell/modules/notifications/NotificationFocus.qml
new file mode 100644
index 0000000..ce59b2a
--- /dev/null
+++ b/quickshell/modules/notifications/NotificationFocus.qml
@@ -0,0 +1,239 @@
+import QtQuick
+import Quickshell
+import Quickshell.Io
+
+Item {
+ id: root
+
+ property string pendingApp: ""
+
+ function normalize(value) {
+ if (!value)
+ return ""
+
+ var result = String(value).toLowerCase().trim()
+
+ result = result.replace(/^org\./, "")
+ result = result.replace(/^com\./, "")
+ result = result.replace(/^net\./, "")
+ result = result.replace(/^app\./, "")
+
+ result = result.replace(/\.desktop$/, "")
+ result = result.replace(/\.desktop$/i, "")
+
+ result = result.replace(/[^a-z0-9]+/g, "")
+
+ return result
+ }
+
+ function candidates(value) {
+ var result = []
+ var raw = String(value || "").toLowerCase().trim()
+
+ function add(candidate) {
+ if (!candidate)
+ return
+
+ candidate = normalize(candidate)
+
+ if (candidate && result.indexOf(candidate) === -1)
+ result.push(candidate)
+ }
+
+ add(raw)
+
+ if (raw.indexOf(".") !== -1) {
+ var parts = raw.split(".")
+
+ add(parts[parts.length - 1])
+
+ for (var i = 0; i < parts.length; i++)
+ add(parts[i])
+ }
+
+ if (raw.indexOf("/") !== -1)
+ add(raw.split("/").pop())
+
+ if (raw.indexOf("-") !== -1) {
+ var dashParts = raw.split("-")
+
+ for (var j = 0; j < dashParts.length; j++)
+ add(dashParts[j])
+ }
+
+ if (raw.indexOf("_") !== -1) {
+ var underscoreParts = raw.split("_")
+
+ for (var k = 0; k < underscoreParts.length; k++)
+ add(underscoreParts[k])
+ }
+
+ return result
+ }
+
+ function matchScore(notificationApp, windowAppId, windowTitle) {
+ var notificationCandidates = candidates(notificationApp)
+ var windowCandidates = candidates(windowAppId)
+
+ var best = 0
+
+ for (var i = 0; i < notificationCandidates.length; i++) {
+ var notificationCandidate = notificationCandidates[i]
+
+ for (var j = 0; j < windowCandidates.length; j++) {
+ var windowCandidate = windowCandidates[j]
+
+ if (notificationCandidate === windowCandidate)
+ best = Math.max(best, 100)
+
+ else if (
+ notificationCandidate.length >= 4 &&
+ windowCandidate.length >= 4 &&
+ (
+ notificationCandidate.indexOf(windowCandidate) !== -1 ||
+ windowCandidate.indexOf(notificationCandidate) !== -1
+ )
+ ) {
+ best = Math.max(best, 60)
+ }
+ }
+ }
+
+ var titleCandidates = candidates(windowTitle)
+
+ for (var n = 0; n < notificationCandidates.length; n++) {
+ for (var t = 0; t < titleCandidates.length; t++) {
+ if (
+ notificationCandidates[n].length >= 4 &&
+ notificationCandidates[n] === titleCandidates[t]
+ ) {
+ best = Math.max(best, 30)
+ }
+ }
+ }
+
+ return best
+ }
+
+ Process {
+ id: windowsProcess
+
+ command: ["niri", "msg", "-j", "windows"]
+
+ stdout: StdioCollector {
+ id: windowsOutput
+
+ onStreamFinished: {
+ var windows
+
+ try {
+ windows = JSON.parse(this.text)
+ } catch (error) {
+ console.error(
+ "Failed to parse Niri windows:",
+ error
+ )
+
+ root.pendingApp = ""
+ return
+ }
+
+ var notificationApp = root.pendingApp
+ root.pendingApp = ""
+
+ if (!notificationApp) {
+ console.warn("Notification focus: empty app name")
+ return
+ }
+
+ if (!Array.isArray(windows)) {
+ console.error(
+ "Niri windows response is not an array"
+ )
+ return
+ }
+
+ var bestWindow = null
+ var bestScore = 0
+
+ for (var i = 0; i < windows.length; i++) {
+ var window = windows[i]
+
+ if (!window || window.id === undefined)
+ continue
+
+ var appId = window.app_id || ""
+ var title = window.title || ""
+
+ var score = matchScore(
+ notificationApp,
+ appId,
+ title
+ )
+
+ if (score > bestScore) {
+ bestScore = score
+ bestWindow = window
+ }
+ }
+
+ if (!bestWindow) {
+ console.log(
+ "No matching Niri window found:",
+ notificationApp
+ )
+ return
+ }
+
+ console.log(
+ "FOCUSING WINDOW:",
+ bestWindow.id,
+ "notification app:",
+ notificationApp,
+ "app_id:",
+ bestWindow.app_id,
+ "title:",
+ bestWindow.title,
+ "score:",
+ bestScore
+ )
+
+ focusProcess.exec([
+ "niri",
+ "msg",
+ "action",
+ "focus-window",
+ "--id",
+ String(bestWindow.id)
+ ])
+ }
+ }
+ }
+
+ Process {
+ id: focusProcess
+ }
+
+ function focusSource(notification) {
+ if (!notification)
+ return
+
+ var app = notification.appName || ""
+
+ if (!app) {
+ console.warn(
+ "Notification has no application name"
+ )
+ return
+ }
+
+ root.pendingApp = app
+
+ windowsProcess.exec([
+ "niri",
+ "msg",
+ "-j",
+ "windows"
+ ])
+ }
+}
diff --git a/quickshell/modules/notifications/Notifications.qml b/quickshell/modules/notifications/Notifications.qml
new file mode 100644
index 0000000..2965b90
--- /dev/null
+++ b/quickshell/modules/notifications/Notifications.qml
@@ -0,0 +1,125 @@
+import QtQuick
+import QtQuick.Layouts
+import Quickshell
+import Quickshell.Wayland
+import Quickshell.Services.Notifications
+import "../../config.js" as Config
+import "./"
+
+Item {
+ id: root
+
+ NotificationServer {
+ id: server
+
+ bodySupported: true
+ imageSupported: true
+ actionsSupported: true
+ actionIconsSupported: true
+ bodyMarkupSupported: true
+
+ onNotification: function(notification) {
+ console.log("NOTIFICATION")
+ console.log(" app:", notification.appName)
+ console.log(" summary:", notification.summary)
+ console.log(" body:", notification.body)
+ console.log(" actions:", notification.actions.length)
+
+ for (var i = 0; i < notification.actions.length; i++) {
+ console.log(
+ " action:",
+ notification.actions[i].identifier,
+ notification.actions[i].text
+ )
+ }
+
+ notification.tracked = true
+ }
+ }
+
+ NotificationFocus {
+ id: focus
+ }
+
+ function activateNotification(notification) {
+ if (!notification)
+ return
+
+ console.log(
+ "ACTIVATE:",
+ notification.appName,
+ notification.summary
+ )
+
+ focus.focusSource(notification)
+
+ for (var i = 0; i < notification.actions.length; i++) {
+ var action = notification.actions[i]
+
+ if (action.identifier === "default") {
+ console.log(
+ "Invoking default action:",
+ action.text
+ )
+
+ action.invoke()
+ return
+ }
+ }
+
+ console.log("No default action available")
+ notification.dismiss()
+ }
+
+ PanelWindow {
+ id: window
+
+ screen: Quickshell.screens.find(function(screen) {
+ return screen.name === Config.barOutput
+ })
+
+ anchors {
+ top: true
+ right: true
+ }
+
+ margins {
+ top: Config.notificationMarginTop
+ right: Config.notificationMarginRight
+ }
+
+ exclusionMode: ExclusionMode.Ignore
+
+ WlrLayershell.layer: WlrLayer.Overlay
+ WlrLayershell.namespace: "notifications"
+
+ color: "transparent"
+
+ implicitWidth: Config.notificationWidth
+ implicitHeight: list.implicitHeight
+
+ ColumnLayout {
+ id: list
+
+ anchors.top: parent.top
+ anchors.right: parent.right
+
+ width: Config.notificationWidth
+ spacing: Config.notificationSpacing
+
+ Repeater {
+ model: server.trackedNotifications
+
+ delegate: NotificationCard {
+ required property var modelData
+
+ notification: modelData
+
+ onActivated: {
+ root.activateNotification(modelData)
+ }
+ }
+ }
+ }
+ }
+}