Repository navigation
Show the power panel's battery state from the battery, not OnBattery - #21152
AbdSattout wants to merge 6 commits into
Conversation
[Medium impact] The PR appears safe to merge, with the previous fallback issue fixed. SummaryThe PR makes the power panel and profile autodetection follow the battery's reported state.
Reviews (2) · Last reviewed commit: "Fall back to OnBattery when the display ..." · Reviewed by Greptile |
An unknown display state always picked AC, so a missed AC uevent could save the battery preference under the AC key. Match the power panel's fallback and cover both directions in the command test.
|
#13016 covers the incorrect charging display while preserving immediate plug and unplug feedback when the battery reading lags. In this PR, picking a profile from the panel or menu while a weak charger is online can overwrite the battery preset, while the automatic switcher still uses the AC key. #21226 was closed without merging, so this PR stays open for the maintainer’s decision on the competing fixes. Codex 6.2 Sol High, Opus 5.5 High and muse-wonder via pi, thinking high compared the source. Both second reviewers favored #13016. Their independence from the driver is not guaranteed. The comparison was source-only. |
What changes
Fixes the power widget drawing a charging bolt while the battery is discharging, and
omarchy-powerprofiles-set autodetectrestoring the AC profile on battery.UPower.OnBatteryis not a reliable power-source signal. upowerd computes it as "the composite battery state is discharging and no AC supply is online" (up_daemon_update_warning_level_idle()in upower'ssrc/up-daemon.c). When upowerd misses an AC uevent, its cached line-poweronlineproperty staystrue, soOnBatterystaysfalseeven though the battery reportsDischarging. The display device'sStateis computed from the batteries alone (up_daemon_update_display_battery()), so it keeps followingBAT0/status.shell/plugins/panels/power/:dischargingandchargingnow come from the display device'sState, falling back toUPower.onBatteryonly when the device reportsUnknownor no state at all. The derivation lives inModel.isDischarging/Model.isChargingso it can be unit-tested. The icon, mode label, status phrases, panel profile buttons and charge-threshold checks all consume the existingroot.discharging, so they follow the corrected state.bin/omarchy-powerprofiles-set autodetect: reads the display deviceStateover D-Bus instead ofUPower.OnBattery, so boot and manual autodetection choose the same ac/battery key as the panel.isPresent, so neither state is reported and the panel stays hidden.Hardware and reproduction
ASUS TUF FX505GT (BAT0 + AC0), kernel 7.3.6, upower 1.91.5. After unplugging, or around suspend:
The widget drew the charging bolt and
omarchy-powerprofiles-set autodetectrestored the AC profile from that state.udevadm trigger --subsystem-match=power_supplyclears it, which points at upowerd's cached AC state rather than the kernel or ACPI.Verification
test/shell.d/power-test.sh(node): addedisDischarging/isChargingcases, including the staleOnBattery=false+ batteryDischargingpair, the unknown-state fallback and a missing battery. The icon and mode-label assertions now feed the derived flag. All pass.test/shell.d/powerprofiles-set-test.sh(bash with mockedbusctlandpowerprofilesctl): the mock now answers the display deviceStateandOnBatteryseparately, and the staleOnBattery=false+Statedischarging case is covered. All pass.Screenshots
No screenshot of the stale state: it needs upowerd to miss an AC uevent, which cannot be triggered on demand. Before/after is the bar icon and the panel's status line moving from the charging bolt and "CHARGING" back to the battery glyph and "ON BATTERY" while
BAT0/statusreadsDischarging; no other part of the widget renders differently.