integrated notification center: replace swaync with built-in NotificationServer

This commit is contained in:
Damocles 2026-04-12 23:52:49 +02:00
parent 4276434cd2
commit c973bd8163
7 changed files with 643 additions and 43 deletions

View file

@ -1,55 +1,31 @@
import QtQuick
import Quickshell.Io
import Quickshell
import "." as M
M.BarSection {
id: root
spacing: M.Theme.moduleSpacing
tooltip: {
const parts = [root.count + " notification" + (root.count !== 1 ? "s" : "")];
if (root.dnd)
const parts = [M.NotifService.count + " notification" + (M.NotifService.count !== 1 ? "s" : "")];
if (M.NotifService.dnd)
parts.push("Do not disturb");
if (root.inhibited)
parts.push("Inhibited");
return parts.join("\n");
}
property int count: 0
property bool dnd: false
property bool inhibited: false
Process {
id: sub
running: true
command: ["swaync-client", "--subscribe-waybar"]
stdout: SplitParser {
splitMarker: "\n"
onRead: line => {
try {
const d = JSON.parse(line);
const alt = d.alt ?? "";
root.count = parseInt(d.text) || 0;
root.dnd = alt.startsWith("dnd");
root.inhibited = alt.includes("inhibited");
} catch (e) {}
}
}
}
required property var bar
M.BarIcon {
icon: {
if (root.inhibited)
return root.count > 0 ? "\uDB80\uDC9B" : "\uDB82\uDE91";
if (root.dnd)
return root.count > 0 ? "\uDB80\uDCA0" : "\uDB82\uDE93";
return root.count > 0 ? "\uDB84\uDD6B" : "\uDB80\uDC9C";
if (M.NotifService.dnd)
return M.NotifService.count > 0 ? "\uDB80\uDCA0" : "\uDB82\uDE93";
return M.NotifService.count > 0 ? "\uDB84\uDD6B" : "\uDB80\uDC9C";
}
color: root.dnd ? M.Theme.base04 : root.accentColor
color: M.NotifService.dnd ? M.Theme.base04 : root.accentColor
anchors.verticalCenter: parent.verticalCenter
}
M.BarLabel {
id: countLabel
label: root.count > 0 ? String(root.count) : ""
label: M.NotifService.count > 0 ? String(M.NotifService.count) : ""
anchors.verticalCenter: parent.verticalCenter
transform: Scale {
@ -79,26 +55,35 @@ M.BarSection {
}
}
onCountChanged: if (count > 0)
popAnim.start()
Connections {
target: M.NotifService
function onCountChanged() {
if (M.NotifService.count > 0)
popAnim.start();
}
}
TapHandler {
acceptedButtons: Qt.LeftButton
cursorShape: Qt.PointingHandCursor
onTapped: {
clicker.command = ["swaync-client", "--toggle-panel", "--skip-wait"];
clicker.running = true;
centerLoader.active = !centerLoader.active;
M.FlyoutState.visible = false;
}
}
TapHandler {
acceptedButtons: Qt.RightButton
cursorShape: Qt.PointingHandCursor
onTapped: {
clicker.command = ["swaync-client", "--toggle-dnd", "--skip-wait"];
clicker.running = true;
onTapped: M.NotifService.toggleDnd()
}
Loader {
id: centerLoader
active: false
sourceComponent: M.NotifCenter {
screen: root.bar.screen
anchorX: root.mapToGlobal(root.width / 2, 0).x - (QsWindow.window?.screen?.x ?? 0)
onDismissed: centerLoader.active = false
}
}
Process {
id: clicker
}
}