Skip to content

Preserve docked lid policy across logout and DPMS - #13778

Open
bitemyapp wants to merge 4 commits into
omacom:quattrofrom
bitemyapp:fix-docked-logout-lid
Open

bitemyapp wants to merge 4 commits into
omacom:quattrofrom
bitemyapp:fix-docked-logout-lid

Conversation

@bitemyapp

@bitemyapp bitemyapp commented Sep 29, 2026 •

Copy link
Copy Markdown

With an external monitor connected and the laptop lid closed, logging out can suspend the machine before SDDM has finished starting. logind counts enabled DRM outputs when deciding whether the laptop is docked, so compositor teardown or DPMS can temporarily defeat HandleLidSwitchDocked=ignore even though the display remains physically connected.

This was observed on an X1 Carbon gen 14 running Omarchy 4.0.4, systemd 261.2, and Intel Panther Lake/xe: logout, SDDM startup, and suspend occurred in the same second, followed by external DisplayPort link-training failures on resume. Related upstream discussion: systemd/systemd#41898.

The system service holds only a handle-lid-switch inhibitor while Omarchy's physical-connector detector finds an external monitor and the configured docked policy is ignore. It survives session teardown, releases on unplug or policy change, and resumes monitoring without restarting. Explicit suspend and idle policy remain available.

  • Type=notify and NotifyAccess=all delay display-manager startup until readiness; docked startup reports readiness only after acquisition succeeds. Undocked and non-ignore-policy startup report readiness promptly. The notification socket is explicitly restored for the inhibited child.
  • Fresh installation and migration share locked, root-scoped setup. A machine-wide completion marker prevents later users' migrations from reversing disable/mask decisions. Failed activation remains retryable.
  • The unit template lives under default/systemd/system/; companion packaging PR Package the docked lid service as an updatable vendor unit omarchy-pkgs#763 is required before this source is packaged. Both settings recipes install the live vendor unit under /usr/lib/systemd/system/, so normal package updates replace its definition. Setup retires only known, unchanged earlier PR copies and repairs their enablement links; administrator units and masks are preserved. Running helpers pick up updates on the next restart or boot.
  • The installed acceptance check verifies both helpers in /usr/bin, package ownership, the vendor fragment, service readiness/activation, and a real inhibitor when an external monitor is connected. The manual documents false connected reports and disable/mask/re-enable workarounds.

Validation for this revision:

  • Focused runtime, setup, external-monitor, lid-close, sleep-monitor, systemd, ownership, style, and privilege regression suites pass; Bash syntax and git diff --check pass.
  • Eight integration checks pass in a disposable KVM guest with real systemd/logind 262, the production helper and service restrictions, synthetic DRM status files, and a simulated display-manager. These cover deliberately delayed acquisition before the greeter, undocked readiness, unplug/replug, stop cleanup, root-owned setup state, disable/mask preservation, old-copy migration, and live vendor-definition replacement. No host services, power policy, or packages were changed.
  • Both actual settings package functions pass with old sources lacking the unit and two successive vendor-unit revisions. Root-only pacman transaction checks were skipped locally.

A fresh Omarchy ISO install, full graphical acceptance, and physical lid-closed logout/login have not been rerun for this revision. The earlier full suite had upstream/headless/companion-fixture failures documented in the previous description; this revision was checked with the focused suites above.

@bitemyapp

Copy link
Copy Markdown
Author
IMG_0092

lmao worked the first time I tried it

@bitemyapp
bitemyapp marked this pull request as ready for review September 29, 2026 19:27
@bitemyapp

Copy link
Copy Markdown
Author

Separately, part of the issue here is the Aquamarine package in Arch and Omarchy doesn't include a newer fix.

  • Omarchy's stable mirror uses 0.15.0-2
  • Arch Linux uses 0.15.1-1

Neither have the fix.

I backported the Aquamarine fix into the version Omarchy uses, named it 0.15.0-2.1. Here's my patch: https://github.com/bitemyapp/aquamarine/tree/fix-null-connector-logout

@jandrusk

jandrusk commented Oct 1, 2026

Copy link
Copy Markdown

Triage (not posted): Clever approach — hold handle-lid-switch while an external DRM connector is physically connected, so logind’s docked policy survives compositor teardown / DPMS.

Two packaging/ops nits before this is merge-ready:

  1. Unit location: other Omarchy system units live under default/systemd/system/ and are installed explicitly (see camlink). This PR places a full unit at etc/systemd/system/omarchy-docked-lid-inhibit.service and the migration only daemon-reload + enable --now — please confirm the pacman package actually installs that path to /etc/systemd/system/ on upgrade (drop-ins under etc/systemd/system/*.service.d/ are the current pattern there).
  2. Service PATH: Environment=PATH=/usr/bin must resolve both omarchy-system-docked-lid-inhibit and omarchy-hw-external-monitors; worth an acceptance check on a fresh update that the unit is active and the inhibit appears in systemd-inhibit --list when an external is plugged.

Also: false “connected” DRM nodes would leave lid-close inert while undocked — please document that risk (or filter known-bad connectors) in the manual section.

@omarchybot omarchybot added the enhancement New feature or request label Oct 1, 2026
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge, though the existing acceptance test still fails for an enabled administrator-customized unit.

Findings

  1. P2 Administrator overrides fail acceptance. ▶

Summary

The PR adds a system service that holds a lid-switch inhibitor while an external monitor is physically connected, plus shared installation and migration setup, acceptance checks, and documentation. No PR-file changes were made since the previous review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Physical connector and docked policy] --> B{Monitor connected and policy ignore?}
  B -- Yes --> C[Acquire lid-switch inhibitor]
  C --> D[Report service ready]
  B -- No --> E[Report service ready without inhibitor]
  C --> F[Release on unplug or policy change]
Loading

Reviews (3) · Last reviewed commit: "Merge quattro into fix-docked-logout-lid" · Reviewed by Greptile

Comment thread migrations/1790703856.sh Resolved
Comment thread install/config/enable-services.sh Resolved

unit=omarchy-docked-lid-inhibit.service
pacman -Qo "/usr/lib/systemd/system/$unit" >/dev/null || fail "docked lid unit is package-owned"
[[ $(systemctl show --property=FragmentPath --value "$unit") == "/usr/lib/systemd/system/$unit" ]] ||

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.

P2 Administrator overrides fail acceptance. If an administrator keeps an enabled, customized unit in /etc/systemd/system, initialization preserves it, but this assertion requires the active unit to come from /usr/lib/systemd/system. The acceptance test fails even when lid protection is enabled and running. Check for the vendor unit only when no administrator override is present.

@bitemyapp

Copy link
Copy Markdown
Author

Thanks @jandrusk!

I've tried to address your notes and the three Greptile findings.

  • The template now lives under default/systemd/system/. [Companion packaging PR #763](Package the docked lid service as an updatable vendor unit omarchy-pkgs#763) installs the live vendor unit under /usr/lib/systemd/system/ for both settings packages, allowing normal package updates to refresh it while preserving administrator overrides and masks.
  • The installed acceptance check verifies both helpers in /usr/bin, package ownership, activation, and an inhibitor when an external monitor is connected.
  • Startup uses Type=notify, with docked readiness sent only after inhibitor acquisition. Undocked/non-ignore-policy startup completes promptly, and the child’s notification socket is restored explicitly.
  • Locked, machine-wide initialization preserves disable/mask choices across later users’ migrations. Failures remain retryable, and cleanup of earlier copies preserves customized definitions and existing opt-outs.
  • The manual documents false “connected” reports and disable/mask/re-enable workarounds.

Focused regression and packaging tests pass, plus eight isolated checks using real systemd/logind, synthetic DRM status, and a simulated greeter.

Since I’m no longer running Omarchy, this revision hasn’t had a fresh ISO/full graphical acceptance run or physical lid-closed logout/login retest. The companion packaging change needs to land before this runtime source ships.

@rdoupe

rdoupe commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Supporting evidence for this PR: the fix here also covers a second trigger I hit, and no separate fix is needed. The trigger is the idle lock's display blank, with no logout involved. Same root cause (DPMS-off makes logind think the laptop is undocked), but without an inhibitor it can turn into a suspend loop.

Setup: ROG Zephyrus G16 (GA605KM): AMD iGPU drives the panel, the RTX 5060 drives HDMI-A-1. Omarchy 4.0.4, systemd 261.2, kernel 7.2.3, NVIDIA 610.57.04, Hyprland 0.56.2 / aquamarine 0.15.0. On AC, lid closed, external monitor on HDMI, idle.

Sequence (from the journal and the Hyprland log):

  1. Lid closed → logind reports docked, no suspend (as intended).
  2. The idle timeout fires the lock. About 5 s later the lock's idleBlankTimer runs omarchy-brightness-display off → hl.dsp.dpms({ action = "disable" }) on every monitor.
  3. aquamarine disables HDMI-A-1 (Connector HDMI-A-1 enabledState changed true -> false). logind no longer counts an external display, so it sees a closed lid → Suspending... about 6 s after the lock.
  4. After every resume, aquamarine logs Buffer unavailable for crtc 200 restore (multi-gpu), requesting re-render and leaves HDMI-A-1 disabled. The lock also re-arms its blank. So logind still sees the lid closed and undocked, and suspends again after HoldoffTimeoutSec (30 s).

Something woke the machine about 5 s into each suspend (I haven't found the wake source), so it looped every ~31 s: 788 suspend/resume cycles over ~7 h, until the lid was opened.

Aftermath: every ALSA card came back on profile off, leaving only "Dummy Output" (fixed by restarting WirePlumber). HDMI-A-1 stayed dead: no picture, replugs never registered, while the kernel and Hyprland both report it connected and enabled.

So beyond logout and display-manager startup, any DPMS-off while docked defeats HandleLidSwitchDocked=ignore. In stock Omarchy the idle lock does exactly that, so with stock timings, docked clamshell use turns into a suspend after about 5 minutes of idle. This PR holds the inhibitor based on physical connector state, so a DPMS blank can't undock the machine and the loop never starts. Happy to test a build on this hardware.

The only conflict was docs/file-layout.md, where this branch and quattro's new Platform root section both added text after the system-sleep paragraph; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at f0a32e3, plus a merge of current quattro that I pushed to this branch as 3fc4455. The branch no longer merged cleanly: the only conflict was docs/file-layout.md, where this branch and quattro's new Platform root section both added text in the same place, and I kept both. Codex Medium reviewed it as a second opinion and reached the same conclusions; independence isn't guaranteed. On the Touch Bar, packaging and polling points below it agreed with me. It found the setup retry problem and the acceptance-check overlap on its own.

The bug is real. logind decides "docked" from the DRM enabled flag, so DPMS off or compositor teardown makes a docked laptop with its lid closed look undocked, and logind suspends it. #15207 reports exactly this from the lock screen's blank, the Zephyrus comment above reports it too, and systemd/systemd#41898 tracks it upstream, with a fix proposed in systemd/systemd#43983. A system service that lives through logout is a reasonable answer: the existing omarchy-system-lid-inhibit is bound to the graphical session, so it can't cover the logout and greeter case.

What ran, on a disposable Omarchy VM with systemd 261.2:

  • The new docked-lid-inhibit and docked-lid-setup tests pass, and so do the existing lid-inhibit, lid-close and hw-external-monitors tests. ./test/cli passes. The full shell suite has 17 failing files, and every one also fails or flakes on quattro.
  • I installed the helper and unit by hand and ran the setup with --start. The service enabled, became ready and took a handle-lid-switch block inhibitor. That inhibitor held through Hyprland DPMS off and through a display-manager restart, with the same helper process both times.
  • The bug itself wasn't reproduced. A VM has no lid, so this still needs a test on a docked laptop with the lid closed.

Problems found:

  1. A MacBook Touch Bar keeps the lid from ever suspending. The service trusts omarchy-hw-external-monitors, which counts any connected connector other than eDP, LVDS or DSI. Don't count the T2 Touch Bar as an external monitor #14994 and Ignore USB Touch Bar DRM when detecting external displays #11516 show T1 and T2 Touch Bars as always-connected USB connectors. On those machines, with nothing plugged in, this service would hold the inhibitor permanently: close the lid, put it in a bag, and it stays awake. Today the same misreading only skips the lock. The existing inhibitor avoids this by asking whether Hyprland has the output enabled. That doesn't work at the greeter, so the connector check needs fixing first, for example by landing Don't count the T2 Touch Bar as an external monitor #14994 and Ignore USB Touch Bar DRM when detecting external displays #11516.
  2. It can't land before Package the docked lid service as an updatable vendor unit omarchy-pkgs#763 ships. install/config/docked-lid-inhibit.sh:10 fails when the vendor unit is missing. enable-services.sh sources it during a fresh install, so the install would abort there, and migrations/1790703856.sh would fail omarchy update and hold up every migration after it. A built settings package with the unit has to ship together with this.
  3. It polls every second, forever, on every machine. That's busctl, sleep and the connector check once a second, including on desktops that have no lid. On the VM that came to about 330 ms of CPU every 30 s. Gating it on omarchy-hw-laptop and reacting to DRM/udev change events would avoid the cost.
  4. The retirement of copies from earlier PR builds is extra scope. The sha256 match, the copied-unit fixture and the reenable path only serve machines that installed an earlier revision of this branch, and no released install has one. It also has a retry bug: setup deletes a recognised, disabled copy before the completion marker is written. If daemon-reload fails or the run is interrupted, the retry no longer sees the copy, so it enables and starts the service the user had turned off. Dropping that path removes both the bug and roughly a third of the setup and its tests.
  5. A behaviour change worth deciding on purpose: a connected display that is switched off in the monitor config now also stops the lid from suspending. The existing inhibitor deliberately doesn't do that.
  6. Minor: the acceptance check matches only who, what and mode. Those are identical for the existing session inhibitor, so a USB display could make the check pass even when this service failed to take its own inhibitor.

What happens next is the maintainer's call. They need to decide whether to carry a second, system-level inhibitor in Omarchy or wait for the logind fix upstream, and if it's carried, whether it should replace omarchy-system-lid-inhibit instead of sitting beside it. Once the approach is settled and the points above are addressed, it still needs someone with a docked laptop to confirm it on real hardware.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants