Skip to content

Add a battery charge limit to the power panel - #15431

Open
jamolweb wants to merge 2 commits into
omacom:quattrofrom
jamolweb:battery-charge-limit
Open

jamolweb wants to merge 2 commits into
omacom:quattrofrom
jamolweb:battery-charge-limit

Conversation

@jamolweb

Copy link
Copy Markdown
Contributor

Laptops that live on the charger wear their battery fastest sitting at 100%. This adds a charge limit switch to the power panel and a matching command.

What it does

  • omarchy battery charge-limit <on|off|toggle|status> turns UPower's charge threshold on or off for every battery that supports one.
  • Power panel: a new Charge limit row under the power profiles with Limit 80% / Full 100%. It works with mouse and keyboard (up/down moves between the profile row and this row) and only appears when the battery supports a limit.
  • Manual: a short section under Power profiles, and a mention on the top bar page.

Why UPower

UPower's EnableChargeThreshold already handles the vendor differences:

  • It writes charge_control_start/end_threshold, or switches charge_types to Long_Life on laptops that only offer a charging mode.
  • It uses the model's hwdb CHARGE_LIMIT, or the 75–80% default.
  • It saves the choice under /var/lib/upower and reapplies it at boot.
  • Its polkit action lets the active session change it without a password.

Omarchy doesn't touch sysfs or need root.

Behaviour by hardware

  • Percentage thresholds (ThinkPad, ASUS, Framework, …): the buttons show the real stopping point read from UPower, e.g. Limit 80%.
  • Charging-mode laptops (charge_types only, e.g. many Dells): the buttons say Limit / Full without a number, since the firmware picks the stopping point.
  • Two batteries: both get the same setting, and the panel only reports the limit as on when every battery has it.
  • No support / no battery: the row is hidden and the command exits non-zero with a message.
  • A refused change (firmware or polkit): the command exits non-zero and the panel re-reads the real state instead of assuming.

The panel reads the state when it opens and after each change. It is not added to the 5s refresh tick, so it starts no extra processes.

Testing

  • New tests: test/shell.d/battery-charge-limit-test.sh fakes upower/busctl for each case above. New Model.js tests are in power-test.sh.
  • ./test/cli: passes.
  • ./test/shell: the only failures (background-instant-reload, background-intro-clone, default-apps, elsewhen-migration, launch-browser, screenshot-sanity) fail the same way on an untouched quattro checkout on this machine. shell-idle-spawn passes with the change.
  • Hardware: tested on an ASUS laptop (asus-nb-wmi, end threshold only), running this branch's shell in an isolated instance against the real battery.
    • Toggling from the panel by keyboard changed charge_control_end_threshold 80 → 100 → 80.
    • The limit survived a reboot.
  • Not tested: real hardware from other vendors. Those paths go through UPower and are covered by the faked cases above.

🤖 Generated with Claude Code

jamolweb and others added 2 commits October 14, 2026 10:15
Turns UPower's charge threshold on or off for every battery that supports
one. UPower writes the vendor thresholds (or switches charge_types to
Long_Life), persists the choice across reboots, and allows the active
session to change it without a password.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Shows a Limit/Full row under the power profiles when the battery supports a
charge limit, reachable by mouse and keyboard. The percentage is only shown
when the laptop really stops at one, not on charging-mode laptops.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@edneymatias

Copy link
Copy Markdown

Tested on a Lenovo LOQ 15IAX9E (83ME), Intel + NVIDIA hybrid, Omarchy 4.0.6-1. I ported the script and the panel row into a cloned omarchy.power plugin (the script unchanged) and ran it on the real hardware.

Hardware

  • BAT0 has no charge_control_start/end_threshold, only charge_types (Fast Standard Long_Life).
  • UPower reports ChargeThresholdSupported: true, ChargeThresholdSettingsSupported: 4, so no end percentage is exposed. The panel correctly falls back to plain "Limit" / "Full" labels.

Result

  • Before: ChargeThresholdEnabled: false, charge_types=[Fast], ideapad_acpi conservation_mode=0.
  • After omarchy-battery-charge-limit on (UPower EnableChargeThreshold true): ChargeThresholdEnabled: true, charge_types=[Long_Life], and conservation_mode flips to 1, so UPower drives the Lenovo conservation mode here.
  • Charging stops at 80% on this model (status=Not charging, capacity=80) with the charger plugged in. I discharged to ~50%, plugged in, and watched it stop.
  • The choice is saved under /var/lib/upower/charging-threshold-status. No root or sudo was needed, and the button worked from the panel as the active session user.
  • "Full" switches charge_types to [Standard] and conservation_mode back to 0; "Limit" restores Long_Life. Note it returns to Standard, not the original Fast.

Not tested: reboot persistence, the two-battery path, and the keyboard cursor between the two rows.

One unrelated thing I noticed: on this machine the panel header showed "Threshold", "Charge limit -" and "Holding" while the limit was off (battery at 98%, Not charging), which looks like the fake state tracked in #10193. This PR's row is the reliable indicator.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants