This commit is contained in:
Damocles 2026-04-12 15:58:13 +02:00
parent 4df704844e
commit 9e1716aa39
14 changed files with 154 additions and 102 deletions

View file

@ -7,8 +7,10 @@ M.BarSection {
spacing: M.Theme.moduleSpacing
visible: M.Modules.bluetooth && root.state !== "unavailable"
tooltip: {
if (root.state === "off") return "Bluetooth: off";
if (root.state === "connected") return "Bluetooth: " + root.device;
if (root.state === "off")
return "Bluetooth: off";
if (root.state === "connected")
return "Bluetooth: " + root.device;
return "Bluetooth: on";
}
@ -18,20 +20,14 @@ M.BarSection {
function _parse(text) {
const t = text.trim();
const sep = t.indexOf(":");
root.state = sep === -1 ? t : t.slice(0, sep);
root.state = sep === -1 ? t : t.slice(0, sep);
root.device = sep === -1 ? "" : t.slice(sep + 1);
}
Process {
id: proc
running: true
command: ["sh", "-c",
"s=$(bluetoothctl show 2>/dev/null); " +
"[ -z \"$s\" ] && echo unavailable && exit; " +
"echo \"$s\" | grep -q 'Powered: yes' || { echo off:; exit; }; " +
"d=$(bluetoothctl info 2>/dev/null | awk -F': ' '/\\tName:/{n=$2}/Connected: yes/{c=1}END{if(c)print n}'); " +
"[ -n \"$d\" ] && echo \"connected:$d\" || echo on:"
]
command: ["sh", "-c", "s=$(bluetoothctl show 2>/dev/null); " + "[ -z \"$s\" ] && echo unavailable && exit; " + "echo \"$s\" | grep -q 'Powered: yes' || { echo off:; exit; }; " + "d=$(bluetoothctl info 2>/dev/null | awk -F': ' '/\\tName:/{n=$2}/Connected: yes/{c=1}END{if(c)print n}'); " + "[ -n \"$d\" ] && echo \"connected:$d\" || echo on:"]
stdout: StdioCollector {
onStreamFinished: root._parse(text)
}
@ -47,14 +43,13 @@ M.BarSection {
id: toggle
property string cmd: ""
command: ["bluetoothctl", "power", cmd]
onRunningChanged: if (!running && cmd !== "") proc.running = true
onRunningChanged: if (!running && cmd !== "")
proc.running = true
}
M.BarIcon {
icon: "\uF294"
color: root.state === "connected" ? M.Theme.base0D
: root.state === "off" ? M.Theme.base04
: M.Theme.base0D
color: root.state === "connected" ? M.Theme.base0D : root.state === "off" ? M.Theme.base04 : M.Theme.base0D
anchors.verticalCenter: parent.verticalCenter
}
M.BarLabel {