quickshell: mouse battery in quick settings, not bar

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-19 09:47:34 +01:00
parent 2b40217cdd
commit 434db62cd6

View file

@ -4105,65 +4105,6 @@ in
} }
''} ''}
${lib.optionalString (!isMacbook) ''
// Wireless mouse battery — polled off the Keychron
// receiver via the mouse-battery script. Hidden while the
// mouse is off/asleep or the receiver is unplugged.
Item {
id: mouseBatWidget
visible: level > 0
width: Theme.barWidth
height: mouseBatCol.height
property int level: 0
property bool charging: false
property color tint: charging ? Theme.accent
: level <= 15 ? Theme.err
: level <= 30 ? Theme.warn
: Theme.base05
Process {
id: mouseBatProc
command: [Commands.mouseBattery]
stdout: StdioCollector {
onStreamFinished: {
const f = text.trim().split(" ");
mouseBatWidget.level = parseInt(f[0]) || 0;
mouseBatWidget.charging = f[1] === "charging";
}
}
}
Timer {
interval: 60000
repeat: true
running: true
triggeredOnStart: true
onTriggered: mouseBatProc.running = true
}
Column {
id: mouseBatCol
anchors.horizontalCenter: parent.horizontalCenter
spacing: 0
SIcon {
anchors.horizontalCenter: parent.horizontalCenter
text: "mouse"
color: mouseBatWidget.tint
font.pixelSize: 16
}
SText {
anchors.horizontalCenter: parent.horizontalCenter
text: mouseBatWidget.level
color: mouseBatWidget.tint
font.pixelSize: 10
}
}
}
''}
// Quick settings — present on every host, so the shared // Quick settings — present on every host, so the shared
// controls sit in the same place on all of them. // controls sit in the same place on all of them.
Item { Item {
@ -5533,6 +5474,87 @@ in
width: 240 width: 240
spacing: 8 spacing: 8
${lib.optionalString (!isMacbook) ''
// Wireless mouse battery, read off the Keychron
// receiver by the mouse-battery script. Polls only
// while the panel is up; hidden while the mouse is
// off/asleep or the receiver is unplugged.
Card {
id: mouseBatCard
visible: level > 0
width: parent.width
property int level: 0
property bool charging: false
property color tint: charging ? Theme.accent
: level <= 15 ? Theme.err
: level <= 30 ? Theme.warn
: Theme.base05
Process {
id: mouseBatProc
command: [Commands.mouseBattery]
stdout: StdioCollector {
onStreamFinished: {
const f = text.trim().split(" ");
mouseBatCard.level = parseInt(f[0]) || 0;
mouseBatCard.charging = f[1] === "charging";
}
}
}
Timer {
interval: 30000
repeat: true
triggeredOnStart: true
running: qsDropdown.visible
onTriggered: mouseBatProc.running = true
}
Item {
width: parent.width
height: 20
Row {
spacing: 6
anchors.verticalCenter: parent.verticalCenter
SIcon {
anchors.verticalCenter: parent.verticalCenter
text: "mouse"
font.pixelSize: 15
}
SText {
anchors.verticalCenter: parent.verticalCenter
text: "Mouse"
font.weight: Font.Medium
}
}
Row {
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: 4
SIcon {
anchors.verticalCenter: parent.verticalCenter
text: mouseBatCard.charging ? "battery-charging"
: mouseBatCard.level >= 75 ? "battery-full"
: mouseBatCard.level >= 50 ? "battery-medium"
: mouseBatCard.level >= 20 ? "battery-low"
: "battery"
color: mouseBatCard.tint
font.pixelSize: 15
}
SText {
anchors.verticalCenter: parent.verticalCenter
text: mouseBatCard.level + "%"
color: mouseBatCard.tint
font.pixelSize: 11
}
}
}
}
''}
// Screen recorder. wf-recorder is held as a live // Screen recorder. wf-recorder is held as a live
// Process (not execDetached) so Stop can SIGINT it; // Process (not execDetached) so Stop can SIGINT it;
// slurp's region pick happens inside the script, // slurp's region pick happens inside the script,