feat(battery): show charge/discharge rate in the bar widget - #3210
Open
SpyrosPsarras wants to merge 1 commit into
Open
feat(battery): show charge/discharge rate in the bar widget#3210SpyrosPsarras wants to merge 1 commit into
SpyrosPsarras wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.