37 lines
1.5 KiB
QML
37 lines
1.5 KiB
QML
import QtQuick
|
|
import Quickshell.Services.UPower
|
|
import "." as M
|
|
|
|
M.BarSection {
|
|
id: root
|
|
spacing: M.Theme.moduleSpacing
|
|
visible: UPower.displayDevice?.isLaptopBattery ?? false
|
|
tooltip: {
|
|
const state = root.charging ? "Charging" : "Discharging";
|
|
const t = root.charging ? root.dev?.timeToFull : root.dev?.timeToEmpty;
|
|
const mins = t ? Math.round(t / 60) : 0;
|
|
const timeStr = mins > 0 ? "\n" + Math.floor(mins / 60) + "h " + (mins % 60) + "m " + (root.charging ? "until full" : "remaining") : "";
|
|
return state + " \u2014 " + Math.round(root.pct) + "%" + timeStr;
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|