Skip to content

Derive power panel charge direction from settled battery state - #13016

Open
jaderfeijo wants to merge 5 commits into
omacom:quattrofrom
jaderfeijo:fix-power-panel-charge-direction
Open

jaderfeijo wants to merge 5 commits into
omacom:quattrofrom
jaderfeijo:fix-power-panel-charge-direction

Conversation

@jaderfeijo

@jaderfeijo jaderfeijo commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes #13015.

  • The power panel treated "charger plugged in" (UPower.onBattery == false) as "charging". When a charger can't cover the machine's draw, UPower reports on-battery: no while the battery reports Discharging, and the panel showed a draining battery as Charging / Time to full with the bolt icon.
  • Adds Model.drawingFromBattery(device, onBattery, states, plugSettling): plug status still wins for 30 s after any onBattery change (the battery's state lags behind a plug/unplug, which the existing tests cover), then the battery's own state decides. discharging and charging in Panel.qml are built from it; the onBattery argument passed into batteryIcon / modeLabel / chargeThresholdActive is unchanged in meaning, so those stay as they are.

Observed on a MacBook Pro 15" 2018 (T2) on a weak USB-C source:

$ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E "state|time to|energy-rate"
    state:               discharging
    energy-rate:         11.2602 W
    time to empty:       4.6 hours
$ cat /sys/class/power_supply/ADP1/online /sys/class/power_supply/BAT0/status
1
Discharging

Stock panel in that state: "Time to full 3h" (the value is actually time-to-empty from omarchy-battery-status) and "Charging 19.1W".

Test plan

  • bash test/shell.d/power-test.sh — new drawingFromBattery cases (unplugged, settling after plug/unplug, settled draining on external power, charging, no battery) plus source checks for the settle window; the existing "external power is newer than stale discharging state" assertions still pass
  • ./test/all — only pre-existing failures that need an omarchy-pkgs checkout (config, snapper, unowned-system-paths), the locate Python traceback, and the live-session runtime-smoke test; identical on a clean quattro tree
  • Same change running in the shell on the affected machine: labels follow the battery state after the settle window, no QML errors on reload
  • Plug in a charger that supplies less than the machine draws; after ~30 s the panel should read "Time left" / "Discharging" with the regular battery icon

🤖 Generated with Claude Code

Fixes #12005

The panel treated "charger plugged in" as "charging". When a charger
can't cover the machine's draw, UPower reports on-battery: no while the
battery reports Discharging, and the panel showed a draining battery as
"Charging" / "Time to full" with the bolt icon.

Keep trusting plug status for 30s after a plug change, since the battery
state lags behind it, then follow the battery's own state.

Fixes omacom#13015

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@llstrk

llstrk commented Sep 24, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: in source, the charge-direction fix matches how UPower defines its signals. UPower sets OnBattery only when the battery is discharging and no line power is online, so "charger online, battery Discharging" is exactly the weak-charger state from #13015. Once the 30 s settle window ends, drawingFromBattery returns true in that state. The panel then shows the regular battery icon, "Time left" and "Discharging", and the time value matches the time-to-empty that omarchy-battery-status already reports. The onOnBatteryChanged handler name matches the Quickshell onBattery notify signal. The battery service already uses the same pattern.

One side effect was found: the change moves where profile choices are saved.

Profile choices made in the panel on a weak charger are saved as the battery preset

setProfile still uses root.discharging to choose the storage key, and this PR changes what that property means:

// shell/plugins/panels/power/Panel.qml:170 (unchanged by this PR)
actionProc.command = ["omarchy-powerprofiles-set", root.discharging ? "battery" : "ac", profile]
State: charger online (OnBattery = false), battery Discharging, settle window over
User picks a profile in the power panel

             root.discharging   command                                   saved to
base         false              omarchy-powerprofiles-set ac <profile>    ac preset
this PR      true               omarchy-powerprofiles-set battery <prof>  battery preset

omarchy-powerprofiles-set writes the requested profile to $state_dir/$action. Its autodetect branch documents that every entry point should use UPower.onBattery "so every entry point saves and restores the profile under the same ac/battery key". The menu's autodetect path and the battery service's applyPowerProfile still key on UPower.onBattery.

Impact: on a weak charger, choosing a profile in the panel applies it right away, but the choice overwrites the battery preset and leaves the AC preset untouched. After unplugging, the battery service applies that profile (for example Performance) on battery. Choosing the same profile from the menu in the same state saves it to ac instead, so the two entry points disagree.

Suggested change: keep the storage key on the power source, UPower.onBattery ? "battery" : "ac", and keep root.discharging for presentation only. A source assertion in test/shell.d/power-test.sh for the setProfile key would catch a repeat. The current tests do not cover this path.

Related, pre-existing: the low-battery warning in shell/plugins/services/battery/ still requires onBattery, so a battery draining on a weak charger gets no low-battery warning. battery-test.sh asserts this as intended behavior. This PR does not change it, and a follow-up could.


Review information

Test scope: Source review of head 39470b1 against its parent, with Quickshell at the packaged commit 28771c7 and upstream UPower source (v1.90.10 and v1.91.4) used for signal semantics. Nothing was executed: no test suite, QML runtime, UPower daemon or hardware. The 30 s timing, rendered labels and real-device state lag were not observed. The profile-key issue was found by source inspection and was not reproduced at runtime.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

setProfile picked the ac/battery state key from root.discharging, which now follows the battery's own state. On a charger too weak to cover the load it saved the choice as the battery preset, so the battery service applied it after unplugging, and the menu's autodetect path saved the same choice under ac. omarchy-powerprofiles-set documents UPower.onBattery as the key every entry point uses, so the panel uses it too and root.discharging stays presentation only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5.5, with Codex Medium as a second opinion. The fix is right, and I pushed one follow-up commit to your branch (5b3c6b4).

Pushed: profile choices are saved under the power source again. setProfile picks the ac/battery state key from root.discharging (shell/plugins/panels/power/Panel.qml:170), and with this change that property follows the battery's own state. On a charger too weak to cover the load, picking a profile in the panel would overwrite the battery preset, and the battery service would apply it after unplugging. The menu would save the same choice under ac. omarchy-powerprofiles-set documents UPower.onBattery as the key every entry point uses, and the battery service's applyPowerProfile uses it, so the panel now does too, and root.discharging only affects what the panel shows. A source assertion in test/shell.d/power-test.sh covers it. @llstrk's review above raised the same point.

What ran, on a disposable Omarchy worker VM:

  • I evaluated the panel's discharging binding with UPower reporting the state from Power panel labels a draining battery as charging whenever a charger is plugged in #13015: charger online, battery Discharging, after the settle window. On quattro and with the fix reverted, the panel says Charging. On this head, and on this head merged with current quattro, it says On battery. UPower's values were injected, not read from a physical weak charger, so the 30-second settle timing was not observed on hardware.
  • test/shell.d/power-test.sh and battery-test.sh pass on the head and on the merge. ./test/cli passes on the head. On the merge, one test fails (vscode generated theme references current theme file), and it fails the same way on quattro alone.
  • The shell was started from the merged tree. The power panel registered its IPC target and the log has no QML errors.

Second opinion: Codex Medium agreed the change is proportionate and correct across unplugged, just-plugged, just-unplugged, settled weak charger, charging, full, threshold-held and no-battery states. It also agreed with the profile-key fix (it read this review, so independence isn't guaranteed). It noted that the new QML assertions match source text, so they would not catch a broken timer or handler. The existing power tests use the same convention, so I didn't change that.

Next: this waits on the maintainer. No CI checks ran on this pull request, so it is marked verified but not ready.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the earlier brief status error after a widget reload remains non-blocking.

Findings

  1. P2 Reload loses the settle window ▶

Summary

The power panel now uses the battery’s reported direction after a 30-second plug settle window.

  • The power panel shows battery drain after plug status settles.

No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Battery present?] -->|No| B[Not discharging]
  A -->|Yes| C[UPower.onBattery?]
  C -->|Yes| D[Discharging]
  C -->|No| E[Plug change within 30 seconds?]
  E -->|Yes| B
  E -->|No| F[Battery reports Discharging?]
  F -->|Yes| D
  F -->|No| B
Loading

Reviews (3) · Last reviewed commit: "Reset the charge-rate grace period only ..." · Reviewed by Greptile

return device && device.isPresent && device.state === UPowerDeviceState.FullyCharged && !root.chargeThresholdActive
}
// True while a plug change settles; see Model.drawingFromBattery.
property bool plugSettling: false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reload loses the settle window

plugSettling resets to false whenever the widget is rebuilt. If plugins reload just after a charger is connected, the new widget misses the earlier onBattery change. While the battery still reports Discharging, the panel briefly shows “Discharging” and “Time left” instead of preserving the remaining settle window.

Keep the last plug-change time outside the widget and use it when the widget loads.

Knowledge Base Used: Shell UI and desktop interactions

Resolves the conflict in test/shell.d/power-test.sh by taking quattro's side of the source-text assertions, which omacom#16334 removed on purpose, including the three this branch added. The drawingFromBattery model tests stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro moved and this stopped merging cleanly, so I merged current quattro into your branch (5345ef6) and checked it again. Claude Opus 5.5 did the work, and Codex Medium and muse-wonder (thinking high) were the second opinion.

The merge. The only conflict was in test/shell.d/power-test.sh. #16334 removed every assertion there that reads Panel.qml as text, including the three this branch added. The resolution follows #16334 and keeps your six drawingFromBattery model tests. Model.js and Panel.qml merged without conflicts. The settle timer and its Connections sit on the panel root rather than in the content that is now built on first open, so they track plug changes before the panel has ever been opened.

What ran, on a disposable Omarchy worker VM serving the merged tree:

  • I evaluated the panel's discharging binding with UPower reporting the state from Power panel labels a draining battery as charging whenever a charger is plugged in #13015 (charger online, battery Discharging, after the settle window). On quattro, and with the fix reverted, the panel says Charging. On 5345ef6 it says On battery. UPower's values were injected, because the worker has no battery, so the 30-second settle timing was not observed on hardware.
  • power-test.sh (26 assertions), battery-test.sh (12) and ./test/cli pass.
  • The shell ran from the merged tree, and opening the power panel over IPC logged no QML errors.

The bar icon and the hero label follow the fix too. batteryIcon() and modeLabel() at Panel.qml:53 and :58 are passed root.discharging, which now comes from drawingFromBattery. So the model test that still expects "Charging" for onBattery=false plus Discharging describes the input, not what the panel shows once the state has settled.

Competing fixes. #12259 (older) and #16265 (newer) fix the same symptom in other ways. #15539 and #16855 change the same files for different bugs: the charge limit misread while the rate is re-measured, and noisy gauge readings. Both reviewers, asked without my answer, chose this one:

Both reviewers found no defects in the merge or in the change. They read this review's context, so their agreement isn't guaranteed to be independent.

Next: this waits on the maintainer. One choice is theirs: for the first 30 seconds after any plug change the panel trusts the plug state, so a charger too weak for the load still reads "Charging" until the window ends.

omarchybot and others added 2 commits November 17, 2026 04:02
Resolves the conflict in shell/plugins/panels/power/Model.js, where omacom#19046 added a rateFresh argument to batteryIcon beside this branch's new drawingFromBattery helper: both are kept. Panel.qml merged on its own, so omacom#19046's chargeRateFresh reset now follows the settled discharging state rather than UPower.onBattery alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omacom#19046 reset chargeRateFresh from onDischargingChanged, which on quattro followed UPower.onBattery. Here discharging also follows the settled battery state, so every Charging/Discharging flip on a weak charger restarted the 90 s window and kept a stalled-rate charge limit from being recognised for as long as the flips continued. Drive the reset from onOnBatteryChanged instead, so it still runs only when external power arrives or leaves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: muse-wonder via pi, thinking high <noreply@pi.dev>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 17, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

quattro moved again and this stopped merging cleanly, so I merged current quattro (3b36b9e) into your branch and checked it again. It is now at 6c539e8. Claude Opus 5.5 did the work, and Codex Medium and muse-wonder (thinking high) were the second opinion.

The merge (e55e739). #19046 added a rateFresh argument to chargeThresholdActive, batteryIcon and modeLabel, plus a 90-second chargeRateFresh grace period after a charger is plugged in. The conflict in Model.js was only drawingFromBattery sitting beside that new signature, so I kept both.

One fix on top (6c539e8). Both reviewers found that the merge changed what #19046's reset does. It ran from onDischargingChanged, and on quattro, discharging follows UPower.onBattery. On this branch, discharging also follows the settled battery state. So on a weak charger, every Charging/Discharging flip restarted the 90-second window, and a charge limit detected from a stalled charge rate showed as "Charging" for as long as the flips continued. The reset now runs from your onOnBatteryChanged handler (Panel.qml:262), so it fires only when external power arrives or leaves, as #19046 intended. A worker probe ran the panel's real bindings and handlers through that sequence. On e55e739 the battery back on hold reads "Charging". On 6c539e8 it reads "Threshold". The plug-in grace period behaves exactly as on quattro.

What ran, on a disposable Omarchy worker VM serving 6c539e8:

  • The weak-charger reproduction from Power panel labels a draining battery as charging whenever a charger is plugged in #13015 (charger online, battery Discharging, after the settle window). On quattro, and with your change reverted, the panel says Charging. On 6c539e8 it says On battery. UPower's values were injected, because the worker has no battery, so the timing was not observed on hardware.
  • power-test.sh (31 assertions), battery-test.sh (12) and ./test/cli pass.
  • The shell ran from the branch, and opening the power panel over IPC logged no QML errors.

Second opinion. Both reviewers found the grace-period problem above, and neither found anything else. Their second round on 6c539e8 was clean. They could read this review's context, so their agreement isn't guaranteed to be independent.

Linked #12005. It is the same state, reached a different way: on an M2 MacBook Air, a stale USB-C source keeps on-battery: no while the battery discharges. The bar icon (Panel.qml:318) and the label read the same discharging, so both show the battery after the settle window.

Competing fixes. #17881 opened since the last review and also targets #13015. Like #12259, it trusts the battery state from the moment of plug-in. That means "On battery" for the first seconds after plugging into a working charger, and "Charging" after unplugging while the state lags. quattro deliberately prevents both, and #17881 flips the test that guards it. So this PR still wins. #16265 changes only the low-battery warning. #17881 and #16265 both fix something this PR doesn't: shell/plugins/services/battery/BatteryModel.js still requires onBattery, so the low-battery warning never fires on a weak charger (#10939). That's worth its own pull request.

For you, if you want: the description's test plan still lists source checks for the settle window. #16334 removed those, and the six drawingFromBattery model tests are what remain. The unchecked weak-charger item is the one check a worker can't do.

Next: this waits on the maintainer, who has one choice to make: for 30 seconds after any plug change, the panel trusts the plug state, so a charger too weak for the load reads "Charging" until the window ends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

3 participants