105 lines
2.9 KiB
QML
105 lines
2.9 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
import "." as M
|
|
|
|
M.BarSection {
|
|
id: root
|
|
spacing: M.Theme.moduleSpacing
|
|
tooltip: {
|
|
const parts = [root.count + " notification" + (root.count !== 1 ? "s" : "")];
|
|
if (root.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) {}
|
|
}
|
|
}
|
|
}
|
|
|
|
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";
|
|
}
|
|
color: root.count > 0 ? M.Theme.base0D : (root.dnd ? M.Theme.base04 : M.Theme.base0D)
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
}
|
|
M.BarLabel {
|
|
id: countLabel
|
|
label: root.count > 0 ? String(root.count) : ""
|
|
color: M.Theme.base0D
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
transform: Scale {
|
|
id: countScale
|
|
origin.x: countLabel.width / 2
|
|
origin.y: countLabel.height / 2
|
|
xScale: 1
|
|
yScale: 1
|
|
}
|
|
|
|
SequentialAnimation {
|
|
id: popAnim
|
|
NumberAnimation {
|
|
target: countScale
|
|
properties: "xScale,yScale"
|
|
to: 1.4
|
|
duration: 100
|
|
easing.type: Easing.OutQuad
|
|
}
|
|
NumberAnimation {
|
|
target: countScale
|
|
properties: "xScale,yScale"
|
|
to: 1.0
|
|
duration: 200
|
|
easing.type: Easing.OutElastic
|
|
}
|
|
}
|
|
}
|
|
|
|
onCountChanged: if (count > 0)
|
|
popAnim.start()
|
|
|
|
TapHandler {
|
|
acceptedButtons: Qt.LeftButton
|
|
cursorShape: Qt.PointingHandCursor
|
|
onTapped: {
|
|
clicker.command = ["swaync-client", "--toggle-panel", "--skip-wait"];
|
|
clicker.running = true;
|
|
}
|
|
}
|
|
TapHandler {
|
|
acceptedButtons: Qt.RightButton
|
|
cursorShape: Qt.PointingHandCursor
|
|
onTapped: {
|
|
clicker.command = ["swaync-client", "--toggle-dnd", "--skip-wait"];
|
|
clicker.running = true;
|
|
}
|
|
}
|
|
Process {
|
|
id: clicker
|
|
}
|
|
}
|