nova-shell/modules/Battery.qml
2026-04-10 10:49:48 +02:00

32 lines
1 KiB
QML

import QtQuick
import Quickshell.Services.UPower
import "." as M
Row {
id: root
spacing: 4
visible: UPower.displayDevice?.isLaptopBattery ?? false
readonly property var dev: UPower.displayDevice
readonly property real pct: (dev?.percentage ?? 0) * 100
readonly property bool charging: dev?.state === UPowerDeviceState.Charging
Text {
text: {
if (root.charging) return "";
const icons = ["󰂎","󰁺","󰁻","󰁼","󰁽","󰁾","󰁿","󰂀","󰂁","󰂂","󱟢"];
return icons[Math.min(10, Math.floor(root.pct / 10))];
}
color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05
font.pixelSize: M.Theme.fontSize + 2
font.family: M.Theme.fontFamily
anchors.verticalCenter: parent.verticalCenter
}
Text {
text: Math.round(root.pct) + "%"
color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily
anchors.verticalCenter: parent.verticalCenter
}
}