omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Power widget shows "Charging" while battery is discharging: icon/label trust UPower.onBattery and ignore device.state

Open DerAlbertCom opened this issue 2 months ago • 11 comments

System

  • Omarchy 4.0.3-mac.1
  • Apple MacBook Air M2 (Asahi Linux, kernel 7.1.13-3-1-ARCH)
  • Quickshell 0.3.0, UPower 1.91.4

What happened

After charging to 100% and unplugging the charger, the bar's power widget keeps showing the charging icon / "Charging" label while the battery is actually discharging.

Cause

The widget derives everything from the daemon-wide UPower.onBattery flag and never checks displayDevice.state. On this machine, the tps6598x USB-C PD port (/sys/class/power_supply/tps6598x-source-psy-0-0038) keeps reporting online: 1 after unplug (stale source state; filed separately against Asahi Linux). UPower therefore sets on-battery: no even though its own battery device reports state: discharging:

upower -d  →  DisplayDevice: state: discharging ...  Daemon: on-battery: no

With onBattery == false, Panel.qml (discharging binding, lines 68–71) is false, so Model.batteryIcon() hits if (!onBattery) return chargingIcons[index] (Model.js:77) and modeLabel() falls through to "Charging" since percentage < 1 (Model.js:89).

Expected

When displayDevice.state === UPowerDeviceState.Discharging, show the discharging icon / "On battery" regardless of the onBattery flag.

Suggested fix

In Model.js, gate the charging icon on the device state, e.g.

if (!onBattery && d.state === states.Charging) return chargingIcons[index]

and apply the same guard in modeLabel(). This also hardens the widget against driver-level inconsistencies of this kind (see also #10939, same trust-the-flag pattern).

Steps to reproduce

Charge to 100%, unplug the charger. On Asahi machines with a stale tps6598x-source-psy online=1, the widget stays on "Charging" as the battery drains.

DerAlbertCom avatar Sep 15 '26 20:09 DerAlbertCom

https://github.com/AsahiLinux/linux/issues/626

DerAlbertCom avatar Sep 15 '26 20:09 DerAlbertCom

Same root cause, different trigger — reproduces on a Dell with a BIOS charge threshold set, where onBattery: no is correct (the adapter really is online) and the widget still claims "Charging".

With a charge limit configured (Dell XPS 13 DX13260, BIOS Custom 75/80) and the battery above the limit, the EC discharges the battery down to 80% while AC stays plugged in. UPower and the kernel both report the discharge, but the daemon-wide flag stays no:

$ cat /sys/class/power_supply/BAT0/status   # Discharging
$ cat /sys/class/power_supply/ADP1/online   # 1
$ upower -i /org/freedesktop/UPower/devices/battery_BAT0
    state:        discharging
    energy-rate:  7.219 W
$ omarchy-battery-status --shell
state	discharging
rate	7.3W

The panel at that moment: charging phrase ("HOARDING JOULES"), Time to full 11h 48m, Charging 7.5W, charging battery icon. Note omarchy-battery-status --shell already gets it right (state discharging) — the Panel.qml bindings just don't use it.

I fixed it locally on 4.0.4-1 (panel files identical on main @ 0260d2accb) in a cloned widget:

// Panel.qml
readonly property bool discharging: {
  var device = UPower.displayDevice
  return !!(device && device.isPresent && device.state === UPowerDeviceState.Discharging)
}

readonly property bool charging: {
  var d = UPower.displayDevice
  return !!(d && d.isPresent && d.state === UPowerDeviceState.Charging && !root.batteryFlowIdle)
}

plus pass that same flow state into Model.chargeThresholdActive()/batteryIcon()/modeLabel() instead of onBattery, leaving UPower.onBattery only for picking the AC/battery slot sent to omarchy-powerprofiles-set (whose autodetect uses the same flag).

Verified on the Dell:

  • draining to the limit on AC → "Time left / Discharging", plain battery icon, on-battery phrase
  • parked at 80% (Not charging) → "Charge limit / Holding"
  • actually charging → "Charging / Time to full" as before

One thing worth keeping in mind for whoever picks this up: the guard is needed in Panel.qml, not only in Model.js. If charging stays !UPower.onBattery && !batteryFlowIdle, the hero phrase, the Time to full row and the Charging row remain wrong even after the icon/label fix — which is exactly what I hit locally before changing both.

Debug log (expires in 24h): https://logs.omarchy.org/ZblXak

lloydsun avatar Sep 17 '26 09:09 lloydsun

The cause is still on quattro (9480d1b6a), and the code shows it. In shell/plugins/panels/power/Panel.qml, discharging (line 71) is UPower.onBattery alone, and charging (line 88) is !UPower.onBattery. displayDevice.state is never checked. Whenever UPower reports on-battery: no while the battery reports discharging, every direction-dependent part of the panel picks the charging side:

  • the bar and hero icon, through Model.batteryIcon (Model.js:77)
  • the mode label, through Model.modeLabel (Model.js:87-89)
  • the hero phrase (Panel.qml:124)
  • "Time to full" (Panel.qml:444) and the "Charging" rate label (Panel.qml:448)

The values under those labels come from omarchy-battery-status, which already reads the battery's own state, so the panel shows a correct time-to-empty and a correct discharge rate under charging labels. The behaviour is deliberate in one respect: 924254ed made the panel trust onBattery so it reacts at once to plugging in or unplugging, before UPower refreshes the battery state, and test/shell.d/power-test.sh enforces that. That reasoning covers a mismatch lasting a few seconds. It does not cover one that persists. A stale tps6598x online=1 on Asahi, @lloydsun's Dell discharging to a BIOS limit on AC, and #13015's charger too weak for the draw all leave the battery discharging with on-battery: no for as long as that state lasts. I did not reproduce this on a worker, because a worker VM has no battery; this is established from the source alone.

The fix is already open. #12259 makes the battery's own state decide the panel's direction, and it declares that it fixes this issue and #13015. #13016, which is newer, fixes #13015 the same way but keeps trusting onBattery for 30 seconds after it changes. The two compete, and the maintainer decides between them on the pull requests themselves. A related symptom is also already covered: in this same state the low-battery warning is suppressed, because shell/plugins/services/battery/BatteryModel.js:7 also requires onBattery. #15009 removes that requirement (it fixes #10939, which you cited).

Two models checked this: Claude Opus 5.5 read the code, and Codex Medium reviewed it independently. Codex agreed on the mechanism, though its independence is not guaranteed. It found the low-battery gate above on its own. This issue now waits on the maintainer's decision on #12259 and #13016.

omarchybot avatar Oct 12 '26 02:10 omarchybot

Still true on quattro: power panel direction trusts UPower.onBattery and ignores device state. Competing fixes: #12259 (prefer device state) and #13016 (settle window). Product call on which approach; either should close this.

jandrusk avatar Oct 13 '26 16:10 jandrusk

Same here on Omarchy 4.0.4 (Dell XPS 14). With a USB-C charger that doesn't negotiate PD (sysfs shows 5 V / 0.1 A), UPower.onBattery is false, but the battery's own state is discharging and the charge keeps falling. The power panel still shows "Charging · 8 W" (the 8 W is the drain) and the header says "Charging".

What works well in a local copy of omarchy.power: drive the labels from the battery's own state instead of the plug status.

readonly property bool batteryDraining: {
  var device = UPower.displayDevice
  return !!(device && device.isPresent && device.state === UPowerDeviceState.Discharging)
}

Then use batteryDraining for the "Charging / Discharging" label, "Time left / Time to full", the header status, and the charging pulse (keep onBattery only for the AC/battery power profile). Result: Charging while charging, Holding at the charge limit, Discharging whenever it drains, even when plugged in.

roehrbacher avatar Oct 17 '26 05:10 roehrbacher

Still present on Omarchy 4.5.0-3, Dell XPS 14 DA14260 (Intel Core Ultra X7 358H, Intel Arc B390).

Same weak-charger case as in my earlier comment: AC can be online (/sys/class/power_supply/AC/online = 1) while the pack is draining (/sys/class/power_supply/BAT0/status = Discharging; rate from current_now × voltage_now). UPower.onBattery is then false, and the stock panel in 4.5.0-3 still binds discharging to UPower.onBattery alone, so it labels that state Charging. omarchy-battery-status --shell already reports state discharging.

roehrbacher avatar Nov 23 '26 14:11 roehrbacher

This is another way into the same bug, on a Dell XPS 14 DA14260, Omarchy 4.5.0-3.

Only the laptop's USB-C charger was used today, nothing else. After it was unplugged, with every port empty, ucsi-source-psy-USBC000:001 stayed online=1 / status=Charging at an advertised 15 V / 5 A. UPower last updated that device at 09:40 CET, when the kernel logged ucsi_acpi USBC000:00: UCSI_GET_PDOS failed (-95). Hours later the ports are still empty, a typec partner is still listed on port 0, the ACPI AC device is offline, and the battery is Discharging (around 42–48 %, 10–17 W).

UPower.OnBattery is therefore false. The stock power widget treats that flag as "charging", so the bar shows the bolt and the word Charging while the pack is draining. omarchy-power-present also returns true, because it counts any Mains or USB supply with online=1, and the machine stays on the AC/performance profile.

omarchy-battery-status already reports state discharging correctly, because it only looks at type Mains for AC.

Idea, without a PR: take charge direction from the battery's own state (and the Mains AC device), not from UPower.onBattery or a USB/UCSI online flag. Show Charging only when the pack is actually charging or holding at a real limit. Treat a lone stuck UCSI online=1 as on battery when Mains AC is off and the battery is discharging. The same rule should apply to omarchy-power-present and the AC/battery power-profile switch, so a leftover port flag can't leave the laptop in Performance while it's draining.

roehrbacher avatar Nov 24 '26 11:11 roehrbacher

The latest unplugged-UCSI report adds a power-profile symptom to the display bug. On current quattro (7427fab86f), automatic profile switching reads UPower.onBattery directly in shell/plugins/services/battery/Service.qml:54-62,135-141. Login and menu selection use omarchy-powerprofiles-set autodetect, which reads the same flag. These paths do not call omarchy-power-present. If the flag stays false after unplugging, the shell gets no source-change signal to restore the battery profile, so the AC profile can remain active.

The linked panel fixes #12259, #13016 and #17881 address the incorrect charging display but retain that automatic profile path. #19843 also leaves automatic switching unchanged; its profile change affects a manual selection in the panel. Changing omarchy-power-present alone would therefore leave the automatic-profile symptom unresolved.

Mains being offline while the battery discharges does not establish that external power is absent on every machine: a real USB-only charger that cannot meet the load can produce those readings too. The current helper explicitly accepts an online USB supply with Mains offline. A replacement source rule needs to account for that case as well as the stale port.

One correction to the October reply: the low-battery warning's onBattery gate has since been removed on quattro by a91badb52c (#11161); it now checks battery state. Also, omarchy-battery-status gets its discharge state from the battery's UPower record; its Mains check controls holding/full handling.

GPT-6 in Codex (driver effort not exposed), Opus 5.5 High, and muse-wonder via pi (thinking high) checked these paths. The reviewers agreed; independence is not guaranteed. No worker tests or hardware reproduction were performed, and the UCSI readings remain reporter-supplied evidence. The display fixes are already linked; this issue remains open for the maintainer, with automatic profile selection still unresolved.

omarchybot avatar Nov 24 '26 12:11 omarchybot

A bit more from the same XPS 14, still without a reboot.

UPower history shows the charger did work this morning: charging from 09:40 to 10:25 CET, up to 80%, then pending-charge at the limit, then unplugged around 10:36. After that, ucsi-source-psy-USBC000:001 stayed online=1, so OnBattery stayed false and the bolt came back while the pack was discharging.

This afternoon, with the pack around 28% (well below the 75–80% limit), plugging the charger into a USB-C port flipped the battery to pending-charge at 0 W for a short spell, and unplugging went straight back to discharging. The widget treats any PendingCharge while OnBattery is false as a charge-limit hold, so plugged in it shows the plain battery icon and "Threshold" / "Holding". Unplugged, the leftover UCSI flag still keeps OnBattery false, so the bolt and "Charging" come back. That's why it looks inverted.

omarchy-power-present and the performance profile still follow that stuck UCSI flag the whole time.

roehrbacher avatar Nov 24 '26 12:11 roehrbacher

The 28% “Threshold / Holding” display follows a separate path on quattro (7427fab86f). In shell/plugins/panels/power/Model.js:58-65, any PendingCharge while UPower.onBattery is false counts as a charge-limit hold, without comparing the percentage with a limit. That return precedes the charge-rate freshness check. The panel uses this predicate for its icon and holding labels, independently of the status script's state, so a brief pending-charge below a 75–80% limit still produces this display.

The missing level check is already reported in #7803. Open #7915 proposes checking the limit band for PendingCharge in both the model and status script; #17616 proposes a limit-band check in the panel model. The direction fixes #12259, #13016, #17881 and #19843 leave this rule unchanged. The hold guards address the false “Holding” label; they still fall back to “Charging” for this pending state rather than adding a distinct “Not charging” state. The readings do not establish why charging briefly paused on this machine.

GPT-6 in Codex (driver effort not exposed), Opus 5.5 High, and muse-wonder via pi (thinking high) checked the source and proposed checks. The reviewers agreed; independence is not guaranteed. No worker tests or hardware reproduction were performed. This issue remains open for the maintainer, with the false hold also tracked under #7803.

omarchybot avatar Nov 24 '26 12:11 omarchybot

Confirming another trigger for this on Omarchy 4.5.0-3 (linux-omarchy 7.2.15-4-omarchy, upower 1.91.5-1) on an Acer Aspire A15-41M using acer-wmi-battery (health_mode=1, 80% charge limit):

When health_mode=1 is active while the battery is above 80% and AC remains connected, the Acer EC actively discharges the battery down toward 80% while ACAD/online stays 1:

/sys/class/power_supply/ACAD/online    = 1
/sys/class/power_supply/BAT0/status    = Discharging
/sys/class/power_supply/BAT0/capacity  = 97
/sys/class/power_supply/BAT0/power_now = 12983000

$ omarchy-battery-status
Battery 97%  ·  3h 56m left  ·   13W / 53Wh

Because UPower.onBattery is false while UPower.displayDevice.state is Discharging, the Power panel shows Charging and Time to full alongside the discharge rate and time-to-empty from omarchy-battery-status --shell, plus the charging icon and pulse animation.

Sebo1411 avatar Dec 01 '26 09:12 Sebo1411