aboutsummaryrefslogtreecommitdiffstats
path: root/home/quickshell/bar/blocks/Battery.qml
diff options
context:
space:
mode:
authorPetri Hienonen <petri.hienonen@gmail.com>2024-05-23 13:56:00 +0300
committerPetri Hienonen <petri.hienonen@gmail.com>2025-11-30 12:29:57 +0200
commit08297376a85a1719518507e54fca9de954d2376a (patch)
tree3b9c58304b40248533bbb2bb5b7bad2da9da1ff0 /home/quickshell/bar/blocks/Battery.qml
parent75c2af4aedd2ac5c2cfc74b346625fa4b265541d (diff)
downloadnixos-08297376a85a1719518507e54fca9de954d2376a.tar.zst
Agenix configuration
Diffstat (limited to 'home/quickshell/bar/blocks/Battery.qml')
-rw-r--r--home/quickshell/bar/blocks/Battery.qml50
1 files changed, 50 insertions, 0 deletions
diff --git a/home/quickshell/bar/blocks/Battery.qml b/home/quickshell/bar/blocks/Battery.qml
new file mode 100644
index 0000000..dd52f7f
--- /dev/null
+++ b/home/quickshell/bar/blocks/Battery.qml
@@ -0,0 +1,50 @@
+import QtQuick
+import Quickshell.Io
+import "../"
+
+BarBlock {
+ property string battery
+ property bool hasBattery: false
+ visible: hasBattery
+
+ content: BarText {
+ symbolText: battery
+ }
+
+ Process {
+ id: batteryCheck
+ command: ["sh", "-c", "test -d /sys/class/power_supply/BAT*"]
+ running: true
+ onExited: function(exitCode) { hasBattery = exitCode === 0 }
+ }
+
+ Process {
+ id: batteryProc
+ // Modify command to get both capacity and status in one call
+ command: ["sh", "-c", "echo $(cat /sys/class/power_supply/BAT*/capacity),$(cat /sys/class/power_supply/BAT*/status)"]
+ running: hasBattery
+
+ stdout: SplitParser {
+ onRead: function(data) {
+ const [capacityStr, status] = data.trim().split(',')
+ const capacity = parseInt(capacityStr)
+ let batteryIcon = "󰂂"
+ if (capacity <= 20) batteryIcon = "󰁺"
+ else if (capacity <= 40) batteryIcon = "󰁽"
+ else if (capacity <= 60) batteryIcon = "󰁿"
+ else if (capacity <= 80) batteryIcon = "󰂁"
+ else batteryIcon = "󰂂"
+
+ const symbol = status === "Charging" ? "🔌" : batteryIcon
+ battery = `${symbol} ${capacity}%`
+ }
+ }
+ }
+
+ Timer {
+ interval: 1000
+ running: hasBattery
+ repeat: true
+ onTriggered: batteryProc.running = true
+ }
+}