Skip to content

Add sleep drain visibility, battery health, and charge limit to power panel - #20379

Merged
dhh merged 5 commits into
quattrofrom
feat/power-panel-sleep-health-limit
Nov 27, 2026
Merged

dhh merged 5 commits into
quattrofrom
feat/power-panel-sleep-health-limit

Conversation

@dhh

@dhh dhh commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Brings three laptop battery essentials to omarchy.power and the omarchy battery CLI with zero idle polling:

1. Sleep drain visibility (Last sleep)

  • Adds a lightweight (<10 ms, pure bash) default/systemd/system-sleep/omarchy-sleep-stats hook (packaged into /usr/lib/systemd/system-sleep/ alongside unmount-fuse) that records pre/post battery energy and S0ix residency across suspend/hibernate into /run/omarchy/last-sleep and a capped 50-entry /var/lib/omarchy/sleep-history.tsv.
  • Handles both energy-based (energy_now) and charge-based (charge_now * voltage_min_design) batteries, uses CLOCK_BOOTTIME (/proc/uptime) to avoid NTP jumps, clamps 32-bit PMC S0ix counter wraps (hw_us <= wall_us * 1.05), ignores AC-plugged sleeps, and suppresses noisy rates on sleeps under 5 minutes.
  • Surfaces compact Last sleep (0.4%/h) in row 3 of the right stats column (balancing the 3×3 grid) with the full breakdown (8h 12m · −3.3% · 0.4%/h · 0.3W · S0ix 97%) in a PanelToolTip on hover, and shows a dedicated warning line (Last sleep stayed shallow (S0ix XX%)) only when s2idle S0ix residency drops below 80%. Also includes recent sleep history in omarchy-debug.

2. Battery health & UPower disabled-threshold bugfix

  • Emits health (energy_full / energy_full_design, clamped to 100%) in omarchy-battery-status --shell and displays Battery health in the power panel stats grid.
  • Fixes omarchy-battery-status treating UPower 1.91+'s hwdb charge-start/end-threshold defaults (75%/80%) as an active charge limit when ChargeThresholdEnabled is false and sysfs charge_control_end_threshold is 100.

3. Compact hardware charge limit (CHARGE LIMIT · 80% + one-time top-up)

  • Adds bin/omarchy-battery-limit (status [--shell]|on|off|once|toggle) backed by UPower's org.freedesktop.UPower.Device.EnableChargeThreshold D-Bus method (already passwordless for active local desktop sessions via upstream org.freedesktop.upower.policy, covering Framework, ThinkPad, ASUS, Lenovo firmware conservation mode, Dell, and Apple Silicon).
  • Adds a compact header-scale ToggleSwitch row (CHARGE LIMIT · 80%) matching the Wi-Fi band Automatic toggle, plus a 2px threshold tick mark directly on the battery progress bar when active (RTL-mirrored, fades out while topping up to 100% once).
  • When the limit is enabled, smoothly slides open (Style.easeOut) a second switch row directly underneath (Top up to 100% once when idle → bold Next charge goes to 100% on battery / Charging to 100% once on AC when toggled on), keeping CHARGE LIMIT · 80% ON and aligned on both edges with zero layout shift.
  • Wires event-driven 100% once re-arming in shell/plugins/services/battery/Service.qml (WatchedFile + existing UPower.displayDevice / UPower.onBattery signals, zero polling): automatically re-enables the charge limit once the battery reaches 100% (including if already full when armed) or after unplugging (2s debounce against USB-C PD renegotiation), and refreshes activeChargeLimit in Panel.qml even when closed so the bar icon stays in sync with CLI changes.

4. Compact ToggleSwitch centering fix

  • Fixes shell/Ui/ToggleSwitch.qml so knobSize is derived from trackHeight - knobInset * 2 with y: root.knobInset, preventing odd-parity anchors.verticalCenter flooring from letting the knob touch the top track border at compact 12–14px header heights (fixes both the Power panel Charge Limit switch and the Wi-Fi panel Automatic switch).

Screenshots

Before

Before

After (charge limit off / on / one-time 100% override)

Charge limit off

Tests

  • test/shell.d/battery-status-test.sh — pass
  • test/shell.d/power-test.sh — pass
  • test/shell.d/battery-test.sh — pass
  • test/shell.d/i18n-test.sh — pass
  • test/shell.d/motion-test.sh — pass
  • test/shell.d/unowned-system-paths-test.sh — pass
  • ./test/cli — pass

Filed by Gemini via Antigravity.

power-v9-idle-crop

power-v9-once-crop

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; the previous stale-icon issue is fixed and no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous stale-icon issue is fixed and no new actionable issues were found.

Summary

Adds sleep-drain readings, battery health, and hardware charge-limit controls to the power panel and CLI.

  • The power panel shows how much battery sleep used.
  • Supported batteries can charge to a limit or top up once.
  • Battery stats show battery health and active charge limits.
  • Compact switches keep the knob inside the track border.

Diagram

sequenceDiagram
  participant User
  participant Panel
  participant CLI as omarchy-battery-limit
  participant UPower
  participant Service as Battery service
  User->>Panel: Toggle limit or top-up
  Panel->>CLI: on / off / once
  CLI->>UPower: Change charge threshold
  CLI->>Service: Refresh charge-limit state
  Service-->>Panel: chargeLimitSignals changed
  Panel->>Panel: Read battery data, even while closed
  UPower-->>Service: Battery full or power unplugged
  Service->>CLI: Restore charge limit
Loading

Reviews (4) · Last reviewed commit: "Turn one-time top-up into a switch row a..." · Reviewed by Greptile

Comment thread shell/plugins/panels/power/Panel.qml Resolved
Comment thread shell/plugins/panels/power/Model.js Resolved
Comment thread bin/omarchy-battery-status Resolved
@omarchybot omarchybot added the enhancement New feature or request label Nov 27, 2026
@dhh

dhh commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Updated screenshots after design polish (compact header-scale ToggleSwitch matching Wi-Fi band, 80% progress-bar tick mark, balanced 3×3 stats grid, and fixed ToggleSwitch knob centering).

Updated Power panel (charge limit off)

Updated Power panel (charge limit on with one-time 100% override)

Comment thread shell/plugins/panels/power/Panel.qml Resolved
Comment thread shell/plugins/panels/power/Panel.qml Resolved
Comment thread shell/plugins/panels/power/Panel.qml Resolved
@dhh
dhh merged commit f7bdd83 into quattro Nov 27, 2026
6 checks passed
@dhh
dhh deleted the feat/power-panel-sleep-health-limit branch November 27, 2026 11:02
cursor Bot pushed a commit to mark-groves/omarchy that referenced this pull request Nov 27, 2026
… panel (omacom#20379)

* Add sleep drain, battery health, and charge limit to power panel

* Fix ToggleSwitch knob centering at compact header heights

* Refine power panel with compact charge limit toggle, bar tick, and 3x3 stats

* Address Greptile review: RTL marker, Style.easeOut, semantic colors, and re-arm check

* Turn one-time top-up into a switch row and refresh charge limit when closed
BrahimiMehdi added a commit to BrahimiMehdi/omarchy that referenced this pull request Dec 2, 2026
Resolves the conflicts with omacom#19046 (stale charge rate) and omacom#20379
(charge limit state): the settled charge-limit verdict is now a trailing
argument after rateFresh and limitState, and the detail refresh uses the
queued battery read quattro added instead of a separate process wrapper.

Review fixes:
- Picking a power profile while an unplug is held back saved it as the AC
  preference. setProfile now reads the power source UPower reports, not the
  one the panel shows.
- A widget created on AC treated its own creation as the plug-in, so a real
  charge limit read as charging for a minute. The battery service now
  records when power last arrived, and a widget settles from that; one
  created long after a plug-in shows the limit at once.
- The 90 s charge-rate guard follows the reported power source, so a held
  dropout still restarts it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants