Skip to content

Add a lid awake toggle to keep laptops running with the lid closed - #14273

Open
benredrew wants to merge 11 commits into
omacom:quattrofrom
benredrew:lid-awake-indicator
Open

benredrew wants to merge 11 commits into
omacom:quattrofrom
benredrew:lid-awake-indicator

Conversation

@benredrew

@benredrew benredrew commented Oct 4, 2026 •

Copy link
Copy Markdown

Why

Closing a laptop's lid suspends it unless an external monitor is attached. Stay awake only covers the idle timer, so there's currently no way to leave a build, download, SSH session or remote agent session running with the lid shut, short of editing logind.conf.

What

  • omarchy toggle lid awake (bin/omarchy-toggle-lid-awake, [toggle|on|off|status]) holds a logind handle-lid-switch inhibitor in a transient user unit, omarchy-lid-awake.
    • No root. Logind grants this inhibitor to the active local session without a password, so no system files change.
    • It resets on reboot, so a laptop can't be left stuck awake in a bag.
    • Closing the lid still runs omarchy-system-lid-close, so the session locks and the panel blanks. Only the suspend is skipped.
    • on waits for logind to list the unit's own inhibitor (matched by MainPID, since other Omarchy commands hold lid-switch inhibitors under the same name) and fails if it never appears. Failed starts and stops exit non-zero.
    • The unit restarts after an unexpected helper failure (Restart=on-failure, RestartSec=1); an explicit stop still wins.
  • Battery floor. While discharging, the battery service turns lid awake off at 10%, restoring lid-close suspend, and sends a critical notification plus an audible alarm, since the lid may be closed. lidAwake.batteryFloor in shell.json takes 1–100, or 0 to disable it. The toggle runs the check immediately on enable, so a laptop already below the floor doesn't stay awake for a poll interval.
  • LidAwake indicator next to Stay Awake, using the laptop glyph (󰌢). It's hidden on machines without a lid (omarchy-hw-laptop) and listed in the indicators manifest options. Its tooltip says when the battery floor turned it off.
    • It follows the unit's journal (journalctl --user --follow --unit=omarchy-lid-awake), the way Dictation follows voxtype status --follow, and re-checks the unit on each entry. A failure, restart, floor stop or manual systemctl --user stop reaches the bar without polling, and entries queue in the pipe if the shell is busy. The follower starts the first time an indicator sees lid awake on, so a laptop that never uses it runs none, and setpriv --pdeathsig ends it with the shell.
  • Trigger > Toggle > Lid Awake menu entry, guarded by omarchy-hw-laptop.
  • Manual: a "Keep running with the lid closed" section in system sleep (including the battery floor), plus mentions in the toggles table, the indicators sections, and a note that stay awake doesn't cover the lid.

Related PRs

Two open PRs take a different shape for the same need, so this needs a maintainer call on one manual-toggle UI rather than landing parallel toggles:

This PR is the transient, per-task form: an independent unit that survives shell restarts, resets on reboot, disarms at the battery floor, and shows its state in the indicators.

Testing

  • test/shell.d/lid-awake-test.sh stubs systemctl, systemd-run and systemd-inhibit. It covers on, off, toggle, status, idempotence, the restart policy, the immediate floor check, the indicator refresh and journal follower, and bad arguments, plus a non-zero exit when the unit can't start, when logind never lists the unit's own inhibitor (even with another Omarchy lid-switch inhibitor present), and when the unit can't be stopped. It also checks that off still stops the unit when the status query fails.
  • test/shell.d/battery-test.sh covers floor parsing, the discharging-only floor, disabling it, the immediate-check IPC and the alert on every floor stop. The indicator contract fixture covers the tooltips.
  • ./test/shell: the lid awake, battery, indicator contract and manifest entrypoint tests pass. Seven test files fail, and the same seven fail on unmodified quattro on this machine. They need the omarchy-pkgs checkout, omasnap, or a live browser: config, elsewhen-migration, launch-browser, passwordless-grant-lifecycle, screenshot-sanity, snapper, unowned-system-paths.
  • Live checks against the user manager: the inhibitor appears in systemd-inhibit --list, the unit re-acquires it after its helper is killed, and a Quickshell instance running the follower received every start, failure, restart and stop entry, including ones logged while it was frozen. Killing that shell with -9 took the follower down with it.

Why an indicator, not a plugin

This belongs with Stay Awake in the indicators group: it's the lid-closed half of the same question, it's a mode you flip on for a while and off again, and it should stay out of the way until you hover. Third-party plugins can't add to the indicators group, so the standalone widget at https://github.com/benredrew/omarchy-lid-awake is a stopgap: a permanent bar icon, until this lands.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NBknZQb4Lb41uWc7Ne2mET

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds a laptop lid-close suspend toggle feature.

This PR appears safe to merge based on the reviewed changes.

Summary

Adds a transient Lid Awake toggle that inhibits lid-close suspend while retaining lid-close locking and screen blanking.

  • Adds a battery-floor disarm and alert, a bar indicator, menu entry, documentation, and focused tests.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Toggle[Lid Awake toggle] --> Unit[Transient user unit]
  Unit --> Logind[Logind lid-switch inhibitor]
  Unit --> Journal[Unit journal]
  Journal --> Indicator[Bar indicator]
  Battery[Battery floor check] -->|Disarm below floor| Toggle
Loading

Reviews (11) · Last reviewed commit: "Back off restarting the Lid Awake follow..." · Reviewed by Greptile

Comment thread bin/omarchy-toggle-lid-awake Resolved
Comment thread bin/omarchy-toggle-lid-awake Resolved
Comment thread bin/omarchy-toggle-lid-awake Resolved

@chessing234 chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head faf754cb43203056e885e180b50e0923d9da0ef3.

Reviewed inhibitor identity matching against MainPID, bounded acquisition confirmation, failed-start cleanup, stop error propagation, and indicator refresh. The isolated lid-awake test passed. No actionable defect found. Actual logind authorization and laptop lid behavior still require a Linux session.

@cad0p

cad0p commented Oct 6, 2026

Copy link
Copy Markdown

enable_lid_awake starts the transient unit without a restart policy, so anything that kills sleep infinity silently disarms Lid Awake: systemd-inhibit exits 1, the unit fails, and nothing re-arms it — worse, LidAwake.qml refreshes only on construction, bar change, or IPC, so the bar keeps showing it on until the next refresh. That is the same silent-disarm class the battery floor exists to prevent, from a different trigger.

Not hypothetical: an unrelated pkill -x sleep from a test harness on my machine killed the helper of a transient unit started the same way, and the units that recover from a swept helper are the ones carrying a restart policy — in this repo, omarchy-crash-watch.service (Restart=always / RestartSec=5).

Repro on a scratch unit (verified):

systemd-run --user --collect --quiet --unit=lid-awake-restarttest \
  -p Restart=on-failure -p RestartSec=1 \
  systemd-inhibit --what=handle-lid-switch --mode=block \
  --who="Restart Test" --why="verify auto-recovery" sleep infinity
kill -TERM "$(pgrep -P "$(systemctl --user show -p MainPID --value lid-awake-restarttest)")"
systemctl --user is-active lid-awake-restarttest   # active again, new MainPID, inhibitor re-held
systemctl --user stop lid-awake-restarttest        # stays inactive — the off path still wins

Suggestion: add --property=Restart=on-failure --property=RestartSec=1 to the systemd-run call at bin/omarchy-toggle-lid-awake#L36-L39.

Restart=on-failure is enough — a killed helper makes systemd-inhibit exit 1 — and RestartSec=1 rather than the 5 s omarchy-crash-watch.service uses, because every second without the inhibitor is a second a lid close still suspends; an explicit systemctl --user stop still wins, so off and the battery floor are unaffected, and the default start limit (5 starts / 10 s) bounds a permanently failing start. (The existing lid-awake-test.sh stubs systemd-run and asserts only the --unit= / --what= flags and idempotency, so the extra properties are transparent to it.)

@jandrusk

jandrusk commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for this. The transient-unit inhibitor is a nice, root-free approach. Just a heads-up: there are already two open PRs for the same feature with different designs, so it probably needs a maintainer call on which shape to take:

It might help to note in the description how this one differs (no persistence across reboot, an indicator instead of the power panel, the battery floor). Greptile's point about checking the battery floor right when it's enabled also still seems open.

@benredrew

benredrew commented Oct 6, 2026 •

Copy link
Copy Markdown
Author

Thanks for the related PRs. #12882 is the closest overlap: its Power-panel home is a strong fit for a persistent policy, but it needs an always-visible state indicator. This PR is intentionally the transient, per-task form: it resets on reboot and shows the indicator. I do not think #11525's agent-driven guard belongs in this PR; sometimes the desired action is to close the laptop and let it suspend. A maintainer should choose one coherent manual-toggle UI rather than land parallel toggles.

Comment thread bin/omarchy-toggle-lid-awake Resolved
@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for spelling out how this differs from #12882 and #11525. I agree a maintainer needs to pick one manual-toggle design rather than land parallel ones. The branch has merge conflicts with quattro now, so it'll need a rebase whichever way that goes.

benredrew and others added 11 commits October 7, 2026 08:50
Closing the lid suspends a laptop unless an external monitor is attached,
and stay awake only covers the idle timer, so there is no way to leave a
build, SSH session, or remote agent running with the lid shut.

omarchy-toggle-lid-awake holds a logind handle-lid-switch inhibitor in a
transient user unit. Logind grants it to the active session without a
password, and it is gone after a reboot. Closing the lid still runs
omarchy-system-lid-close, so the session locks and the panel blanks. It
gets a laptop-only indicator next to stay awake and a Trigger > Toggle
entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed start or stop now exits non-zero instead of reading as success,
and turning it on waits for logind to list the inhibitor, stopping the
unit if it never appears. The indicator runs one more status check when
a refresh arrives mid-check, instead of dropping it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the inhibitor to the unit's MainPID, since shutdown holds a
lid-switch inhibitor under the same Omarchy name. Turning it off now
stops the unit without asking first, so a failed is-active query can't
pass for an already-stopped unit; only "not loaded" counts as off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBknZQb4Lb41uWc7Ne2mET
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBknZQb4Lb41uWc7Ne2mET
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBknZQb4Lb41uWc7Ne2mET
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBknZQb4Lb41uWc7Ne2mET
@benredrew
benredrew force-pushed the lid-awake-indicator branch from 7f57116 to 381c46d Compare October 7, 2026 15:51
@benredrew

Copy link
Copy Markdown
Author

@cad0p Thanks — adopted as suggested: the unit now runs with Restart=on-failure and RestartSec=1, so a killed helper re-arms within a second, while off and the battery floor still stop it for good.

@benredrew

Copy link
Copy Markdown
Author

@jandrusk Rebased onto current quattro; the only conflict was the default indicator list, which now keeps both PasswordlessSudo and LidAwake.

@greptile-apps

greptile-apps Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

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.

5 participants