Skip to content

Show the power panel's battery state from the battery, not OnBattery - #21152

Open
AbdSattout wants to merge 6 commits into
omacom:quattrofrom
AbdSattout:fix/power-battery-state
Open

AbdSattout wants to merge 6 commits into
omacom:quattrofrom
AbdSattout:fix/power-battery-state

Conversation

@AbdSattout

Copy link
Copy Markdown

What changes

Fixes the power widget drawing a charging bolt while the battery is discharging, and omarchy-powerprofiles-set autodetect restoring the AC profile on battery.

UPower.OnBattery is 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's src/up-daemon.c). When upowerd misses an AC uevent, its cached line-power online property stays true, so OnBattery stays false even though the battery reports Discharging. The display device's State is computed from the batteries alone (up_daemon_update_display_battery()), so it keeps following BAT0/status.

  • shell/plugins/panels/power/: discharging and charging now come from the display device's State, falling back to UPower.onBattery only when the device reports Unknown or no state at all. The derivation lives in Model.isDischarging / Model.isCharging so it can be unit-tested. The icon, mode label, status phrases, panel profile buttons and charge-threshold checks all consume the existing root.discharging, so they follow the corrected state.
  • bin/omarchy-powerprofiles-set autodetect: reads the display device State over D-Bus instead of UPower.OnBattery, so boot and manual autodetection choose the same ac/battery key as the panel.
  • Machines without a battery are unchanged: both helpers require 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:

/sys/class/power_supply/AC0/online    0
/sys/class/power_supply/BAT0/status   Discharging
busctl get-property org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower OnBattery
  -> b false                                  (stale)
busctl get-property org.freedesktop.UPower /org/freedesktop/UPower/devices/line_power_AC0 org.freedesktop.UPower.Device Online
  -> b true                                   (stale, `updated` hours old)
busctl get-property org.freedesktop.UPower /org/freedesktop/UPower/devices/DisplayDevice org.freedesktop.UPower.Device State
  -> u 2                                      (discharging, correct)

The widget drew the charging bolt and omarchy-powerprofiles-set autodetect restored the AC profile from that state. udevadm trigger --subsystem-match=power_supply clears it, which points at upowerd's cached AC state rather than the kernel or ACPI.

Verification

  • test/shell.d/power-test.sh (node): added isDischarging / isCharging cases, including the stale OnBattery=false + battery Discharging pair, 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 mocked busctl and powerprofilesctl): the mock now answers the display device State and OnBattery separately, and the stale OnBattery=false + State discharging case is covered. All pass.
  • Not checked on hardware: the QML binding while upowerd is in the stale state. Reproducing it needs upowerd to miss an AC uevent, which is a race on this machine, so the panel itself was not run against the wedge. The full shell and acceptance suites were not run.

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/status reads Discharging; no other part of the widget renders differently.

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with the previous fallback issue fixed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous fallback issue fixed.

Summary

The PR makes the power panel and profile autodetection follow the battery's reported state.

  • The power panel follows the battery's reported charge direction.
  • Power profile autodetection follows the display battery's state.

Reviews (2) · Last reviewed commit: "Fall back to OnBattery when the display ..." · Reviewed by Greptile

Comment thread bin/omarchy-powerprofiles-set Resolved
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.
@chessing234

Copy link
Copy Markdown
Contributor

thanks. profile autodetect and the panel follow the battery state, and fall back to OnBattery only when that state is unknown. the panel bolt uses the same helper as the charger section, in #21226. Please close this PR as superseded by #21226.

@omarchybot omarchybot added the bug Something isn't working label Dec 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

#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.

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

Development

Successfully merging this pull request may close these issues.

3 participants