| 1 | import QtQuick |
| 2 | import QtQuick.Layouts |
| 3 | import Quickshell.Services.UPower |
| 4 | |
| 5 | // battery block: charge bar, time left / to full, power draw, health (SysPage, settings app > Power) |
| 6 | ColumnLayout { |
| 7 | id: root |
| 8 | readonly property var bat: UPower.displayDevice |
| 9 | readonly property bool hasBat: bat !== null && bat.isPresent |
| 10 | readonly property real batPct: hasBat ? (bat.percentage > 1 ? bat.percentage / 100 : bat.percentage) : 0 |
| 11 | readonly property bool charging: hasBat && bat.state === UPowerDeviceState.Charging |
| 12 | function stateText() { |
| 13 | if (!hasBat) return "" |
| 14 | switch (bat.state) { |
| 15 | case UPowerDeviceState.Charging: return "charging" |
| 16 | case UPowerDeviceState.Discharging: return "discharging" |
| 17 | case UPowerDeviceState.FullyCharged: return "full" |
| 18 | default: return "idle" |
| 19 | } |
| 20 | } |
| 21 | visible: hasBat |
| 22 | Layout.fillWidth: true |
| 23 | spacing: 8 |
| 24 | SectionLabel { text: "battery" } |
| 25 | StatBar { |
| 26 | label: "charge" |
| 27 | frac: root.batPct |
| 28 | fill: root.batPct <= 0.15 && !root.charging ? Theme.err : Theme.accent |
| 29 | valueText: Math.round(root.batPct * 100) + "% " + root.stateText() |
| 30 | } |
| 31 | Text { |
| 32 | Layout.fillWidth: true |
| 33 | wrapMode: Text.Wrap |
| 34 | color: Theme.dim |
| 35 | font.family: Theme.font |
| 36 | font.pixelSize: Theme.fontSize - 1 |
| 37 | lineHeight: 1.3 |
| 38 | text: { |
| 39 | if (!root.hasBat) return "" |
| 40 | var lines = [] |
| 41 | var t = root.charging ? root.bat.timeToFull : root.bat.timeToEmpty |
| 42 | lines.push((root.charging ? "time to full " : "time left ") + Theme.fmtTime(t)) |
| 43 | if (root.bat.changeRate !== undefined) |
| 44 | lines.push("power draw " + Math.abs(root.bat.changeRate).toFixed(1) + " W") |
| 45 | if (Settings.chargeMode !== "off" && Battery.supported) |
| 46 | lines.push("charge limit conservation" + (Battery.held ? ", holding" : "")) |
| 47 | if (root.bat.healthSupported) |
| 48 | lines.push("health " + Math.round(root.bat.healthPercentage) + "%") |
| 49 | return lines.join("\n") |
| 50 | } |
| 51 | } |
| 52 | } |