This repository has been archived on 2026-07-13. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
nova-shell/modules/Battery.qml
2026-04-12 00:38:50 +02:00

29 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
M.BarIcon {
icon: {
if (root.charging) return "\uDB80\uDC84";
const icons = ["\uDB80\uDC8E", "\uDB80\uDC7A", "\uDB80\uDC7B", "\uDB80\uDC7C", "\uDB80\uDC7D", "\uDB80\uDC7E", "\uDB80\uDC7F", "\uDB80\uDC80", "\uDB80\uDC81", "\uDB80\uDC82", "\uDB85\uDFE2"];
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
anchors.verticalCenter: parent.verticalCenter
}
M.BarLabel {
label: Math.round(root.pct) + "%"
color: root.pct < 15 ? M.Theme.base08 : M.Theme.base05
anchors.verticalCenter: parent.verticalCenter
}
}