eww better battery

This commit is contained in:
2026-09-11 15:07:27 +02:00
parent 07b7e2bb05
commit bd109dceee
4 changed files with 124 additions and 33 deletions
@@ -173,20 +173,46 @@
; --- Battery ---
(defwidget bat-sys-win []
(defwidget bat-stat [value label]
(box :orientation "v" :halign "center" :valign "center" :space-evenly false
(label :class "bat-stat-value" :text value)
(label :class "bat-stat-label" :text label)))
; left: draw while on battery, charge rate while charging; right: time left / to full
(defwidget bat-sys-win []
(box :orientation "v" :space-evenly false :class "sys-section" :visible {battery.visible}
(section-header :title "Battery" :accent "bat-accent")
(overlay
(circular-progress
:width 60 :height 60
:value {battery.percentage}
:start-at 0
:clockwise true
:thickness 6
:class "bat-ring bat-${battery.state}"
:tooltip "Battery ${round(battery.percentage, 0)}%\n${battery.status} @ ${battery.wattage}")
(label :class "bat-ring-label"
:text "${round(battery.percentage, 0)}%"))
(box :orientation "h" :space-evenly true :valign "center"
(bat-stat
:value {battery.state == "charging"
? (battery.rate == "" ? "—" : "${battery.rate} %/h")
: (battery.state == "discharging" || battery.state == "low" || battery.state == "critical"
? battery.wattage : "—")}
:label {battery.state == "charging" ? "charging" : "draw"})
(overlay
(circular-progress
:width 72 :height 72
:value {battery.percentage}
:start-at 0
:clockwise true
:thickness 7
:class "bat-ring bat-${battery.state}"
:tooltip "Battery ${round(battery.percentage, 0)}%\n${battery.status} @ ${battery.wattage}")
(label :class "bat-ring-label"
:text "${round(battery.percentage, 0)}%"))
(bat-stat
:value {battery.time == "" ? "—" : battery.time}
:label {battery.state == "charging" ? "to full" : "left"}))
; 6 h history, one bar per 15 min bucket, coloured like the ring
(box :orientation "h" :space-evenly true :class "bat-hist"
(for b in {battery.history}
(progress :orientation "v" :flipped true
:value {b.p < 0 ? 0 : b.p}
:class "bat-hist-bar hist-${b.s}"
:tooltip {b.p < 0 ? b.t : "${b.t} ${round(b.p, 0)}%"})))
(box :orientation "h" :space-evenly false
(label :class "gpu-stat-label" :halign "start" :hexpand true :text "-6h")
(label :class "gpu-stat-label" :halign "end" :text "now"))
)
)