Skip to content

Prefer logind's LidClosed over raw ACPI for lid detection - #9754

Closed
bbishdotdev wants to merge 1 commit into
omacom:quattrofrom
bbishdotdev:fix/hw-laptop-closed-logind
Closed

bbishdotdev wants to merge 1 commit into
omacom:quattrofrom
bbishdotdev:fix/hw-laptop-closed-logind

Conversation

@bbishdotdev

Copy link
Copy Markdown

Fixes #9753.

omarchy-hw-laptop-closed trusted /proc/acpi/button/lid/*/state alone. Firmware _LID methods can report stale state. On my Razer Blade Stealth 13 (Late 2019), ACPI reported closed for over an hour of lid-open use, so every external-monitor hotplug entered clamshell mode and blanked the internal panel, while logind had the correct answer the whole time from the evdev lid switch:

$ cat /proc/acpi/button/lid/LID0/state
state:      closed                                # lid physically open

$ busctl get-property org.freedesktop.login1 /org/freedesktop/login1 \
    org.freedesktop.login1.Manager LidClosed
b false                                           # logind, correct

This asks logind first and keeps the ACPI loop as the fallback:

  • busctl get-property ... org.freedesktop.login1.Manager LidClosed, parsed as b true/b false.
  • Empty busctl output (no running logind, e.g. install chroots) falls through to the ACPI read, now behind an OMARCHY_ACPI_LID_PATH seam matching the other hw- probes (OMARCHY_DRM_PATH, OMARCHY_USB_DEVICES_PATH, ...).

No new dependencies; busctl ships with systemd.

test/shell.d/hw-laptop-closed-test.sh pins five behaviors from fixtures: logind-closed, logind-open despite stale ACPI (the bug), and the three ACPI fallback states (closed, open, no lid device). Against the old script the stale-ACPI scenario fails; against this change all five pass:

not ok - a lid logind reports closed is closed          # old script
ok - a lid logind reports closed is closed              # fixed
ok - a lid logind reports open is open despite stale ACPI
ok - without logind a closed ACPI lid is closed
ok - without logind an open ACPI lid is open
ok - no lid device at all means open

The source pin in monitor-recovery-test.sh is updated to match the new mechanism.

Callers affected beyond clamshell: the PAM fingerprint gate in /etc/pam.d/sudo and /etc/pam.d/polkit-1 runs this as root at auth time (busctl uses the system bus by default; unreachable D-Bus falls back to ACPI as today), and PolkitAgent.qml samples it per auth request. The stale-ACPI failure mode mis-answers those consumers too, so they are corrected together.

Verified on the affected hardware: with ACPI stuck on closed and the lid open, the old script reported closed and the clamshell path disabled eDP-1 on hotplug; the new script follows logind and the panel stays up. ./test/cli passes; ./test/shell matches the base commit (the four failures on my machine fail identically on a clean checkout of the base and want a live Omarchy runtime).

logind reads the lid switch through evdev with hardware quirk handling;
raw ACPI _LID can report stale state, observed on a Razer Blade Stealth
13 (Late 2019) reporting closed for over an hour of lid-open use. Every
external-monitor hotplug then entered clamshell mode and blanked the
internal panel, and the stale answer also skipped the PAM fingerprint
gate on an open laptop.

Keep the ACPI loop as the fallback for contexts without a running
logind, such as install chroots, behind an OMARCHY_ACPI_LID_PATH seam
matching the other hw- probes, so the new test drives both branches
from fixtures.
@cristim

cristim commented Sep 20, 2026

Copy link
Copy Markdown

Confirming this on real Apple Silicon hardware, since the failure it fixes is invisible without a lid to close.

Machine: MacBookPro17,1 (M1), Asahi, aarch64. No /proc/acpi at all, so the pre-fix helper's glob matches nothing and it reports the lid open permanently.

logind's property is present and live here:

$ busctl get-property org.freedesktop.login1 /org/freedesktop/login1 \
    org.freedesktop.login1.Manager LidClosed
b false

It is declared emits-change, and HandleLidSwitch=suspend / HandleLidSwitchDocked=ignore are both set as this PR's approach assumes.

Closed case, against a real lid close rather than a stub. Polling the property and the helper together at 5 Hz across an actual close-and-reopen:

  1 CLOSED helper=0     <- 20:27:56
126 open   helper=1     <- control samples either side

The helper=0 line is the helper reporting the lid closed, which on this hardware it has never been able to do.

The underlying source, for the record: the lid is input0, "Apple SMC power/lid events" on macsmc-input, with B: SW=1 (SW_LID). Reading it directly is not an option for these callers because /dev/input/event0 is root:input and they run as the user, which is what makes going through a bus property the right call.

Preferring logind over ACPI rather than the other way round also looks correct to me beyond the no-ACPI case: I wrote the inverse first and it is weaker, since it cannot address the stale _LID behaviour in #9753.

One optional suggestion for the test, take it or leave it: two cases that fall out of this shape and are cheap to add are logind outranks ACPI when both answer and disagree (pins the precedence this PR establishes), and neither source answers (asserts it reports not-closed and stays quiet, which matters because omarchy-setup-security-fingerprint runs this helper from a PAM stack on every sudo).

@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #7951, which covers the same lid detection via logind. I keep that one open and close this one to consolidate review.

If you feel this is the wrong decision, please open the PR again with a note on the difference.

@bjarneo bjarneo closed this Sep 21, 2026
@bbishdotdev

Copy link
Copy Markdown
Author

This needs to be re-opened. This got closed as a dupe comparing to an Apple Silicon issue and then that one got closed as being a wrong assessment.

I'm still running my forked Omarchy with this change in place. It has nothing to do with Apple Silicon.

@ryanrhughes @dhh

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale ACPI lid state turns external-monitor hotplug into clamshell mode, blanking the internal panel

3 participants