Repository navigation
feat(battery): show charge/discharge rate in the bar widget - #3210
Conversation
The battery popout already surfaces the UPower energy rate, but the bar widget could only show percentage and remaining time, so telling how fast the battery is charging or draining meant opening the popout (or running a third-party plugin that polls /sys/class/power_supply). Add two independent, opt-in toggles to the battery widget - "Show Charge Rate" and "Show Discharge Rate" - that render the signed rate next to the existing text, e.g. "+28W" while charging and "77% (2h 11m) -19W" while draining. Both default to off, and follow the established pattern: a global default in SettingsData plus a per-widget-instance override. The value comes from BatteryService.changeRate, so there is no extra process or polling. It hides itself when the rate is below 0.05W (idle, fully charged, or sitting at a charge limit) so it costs no bar space unless it has something to say. Precision adapts to keep the pill narrow: one decimal below 10W, whole watts above; vertical bars get a whole-watt line.
|
/claude review |
Claude reviewNo issues found. Checked: string-composition refactor in |
Description
The battery popout already shows the UPower energy rate, but the bar widget could only show percentage and remaining time. Telling how fast the battery is charging or draining meant opening the popout, or running a third-party plugin that shells out to
/sys/class/power_supply/BAT*/power_nowon a timer.This adds two independent, opt-in toggles to the battery widget — Show Charge Rate and Show Discharge Rate — which render the signed rate alongside the existing text.
Design notes
BatteryService.changeRate, the same aggregate the popout already renders.0.05W— idle, fully charged, or parked at a charge limit — the text is empty and the widget collapses back to its previous width.10W(-8.4W), whole watts above (+28W); vertical bars get a whole-watt line so the value fits the bar thickness.SettingsData/SettingsSpec.jsplus a per-widget-instance override plumbed throughLists.qml/WidgetsTab.qml/WidgetsTabSection.qml. Both default tofalse, so nothing changes for existing users until they opt in.The string composition in
Battery.qmlwas refactored from stacked early-returns to a parts array so a third element could be added without a combinatorial explosion; the output is byte-identical tomasterfor every existing combination of percentage/time toggles.BatteryServicegains two small reusable pieces:signedChangeRate(positive charging, negative draining, zero idle) andformatPowerRate(compact). Happy to follow up by pointingBatteryPopoutat them too — it currently derives the sign fromisCharging || isPluggedIn, which mislabels a plugged-in-but-draining machine as+. Left out here to keep the diff focused.Type of change
Related issues
None.
Screenshots / video
Above. Both captured on a live session: charging at
28.3Wreported byupowerrenders+28W; discharging at15.4Wrenders-15W.Checklist
I18n.tr()with translator context, reusing existing terms where possiblemake fmt, added/updated tests,make testpasses, andgo mod tidyis clean — n/a, no Go changesmake lint-qmlwith no new warningsTesting done: ran the branch against a live niri session and exercised charging, discharging, and the charge-limit/idle case (verified the readout disappears at
0Wrather than showing+0W); toggled both settings from the widget context menu and confirmed the per-widget override persists;make lint-qmlpasses;check_term_variants.pyandextract_settings_index.pyare clean (the new strings live in a widget context menu, so the settings search index is unchanged); catalogs left alone per CONTRIBUTING.On the last checkbox — glad to open a dlx-docs PR for the two new toggles if you'd like them documented; just say where they belong.