Conversation
… global onBattery
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the Power panel widget getting stuck showing the charging icon/label after AC unplug events by switching charge detection from the global UPower.onBattery flag to the per-device UPower.displayDevice.state, and by moving icon/label computation into readonly property bindings to improve QML reactivity.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Changes:
- Replace
batteryIcon()/modeLabel()QML functions withreadonly propertybindings (batteryIconText,modeLabelText). - Compute
dischargingfromUPower.displayDevice.stateinstead ofUPower.onBattery. - Update consumers to use the new bound properties for icon/label rendering.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
53
to
56
| readonly property bool discharging: { | ||
| var device = UPower.displayDevice | ||
| return !!(device && device.isPresent && UPower.onBattery) | ||
| return !!(device && device.isPresent && device.state === UPowerDeviceState.Discharging) | ||
| } |
Comment on lines
70
to
73
| readonly property bool charging: { | ||
| var d = UPower.displayDevice | ||
| return d && d.isPresent && !UPower.onBattery && !root.batteryFlowIdle | ||
| return d && d.isPresent && !root.discharging && !root.batteryFlowIdle | ||
| } |
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.
Fix: Power widget charging icon/label stuck after unplugging AC
Problem
In the Power bar-widget, when the charger cable was unplugged, the
battery icon and the status label (
Charging) would not update —they stayed stuck in the charging state indefinitely, even though the
system itself (
upower --monitor) correctly reported the AC-unplugevent instantly.
Root cause
Two separate issues, found and fixed in sequence:
Unreliable reactivity source. The icon/label were originally
read via plain JS functions (
batteryIcon(),modeLabel()) calleddirectly inside QML
Textbindings. This made their re-evaluationdepend on QML's automatic dependency tracking working transitively
across function calls into an imported
.jsmodule — a patternthat isn't guaranteed to be as reliable as a plain
readonly propertybinding.Wrong UPower source property (the real cause). Charging state
was derived from
UPower.onBattery— a global, aggregate propertyon the UPower daemon. This property is known to lag or fail to
notify promptly on some hardware. This is a well-documented pitfall
in other UPower consumers (e.g. an equivalent bug was reported and
fixed in
cosmic-applets, where the fix was to switch from theglobal
on_batteryflag to the per-devicestateproperty).The correct, reliable source is the per-device state
(
UPowerDevice.state, e.g.UPowerDeviceState.Discharging/Charging/FullyCharged/PendingCharge), which is whatupower --monitoritself reads and reports instantly.Fix
readonly propertybindings(
batteryIconText,modeLabelText) so the icon/label areguaranteed to re-evaluate on every relevant property change.
discharging(and by extensioncharging) to be computedfrom
UPowerDevice.state === UPowerDeviceState.Discharginginsteadof the global
UPower.onBatteryflag.Known remaining behavior (not a bug)
There can still be a short delay (typically a couple of seconds)
between the physical plug/unplug event and the widget updating. This
comes from the underlying kernel → upowerd → DBus signal chain
(embedded-controller/ACPI reporting latency), which is outside the
widget's control and is consistent with the delay seen in
upower --monitoritself and in other desktop environments (GNOME,KDE, etc.).
Testing
udevadm monitor --udev --subsystem-match=power_supplyand
upower -i <device> --monitorthat the underlying systemreports the state change, and confirmed the widget now reflects it
(icon + label) without requiring the panel to be open.