Skip to content

Read the lid from logind so clamshell works without an ACPI lid button - #7951

Closed
chubuntuarc wants to merge 1 commit into
omacom:quattrofrom
chubuntuarc:hw-laptop-closed-logind
Closed

chubuntuarc wants to merge 1 commit into
omacom:quattrofrom
chubuntuarc:hw-laptop-closed-logind

Conversation

@chubuntuarc

@chubuntuarc chubuntuarc commented Aug 23, 2026 •

Copy link
Copy Markdown

omarchy-hw-laptop-closed reads the lid from /proc/acpi/button/lid/*/state. Hardware without an ACPI lid button has no such file — Apple Silicon has no /proc/acpi at all — so the glob matches nothing and the command reports the lid open forever. logind tracks the lid through evdev's SW_LID, which answers on that hardware, so ask it first and keep the ACPI button as the fallback.

That stale answer is load-bearing in three places:

  • omarchy-hw-clamshell is omarchy-hw-laptop-closed && omarchy-hw-external-monitors, so clamshell mode never engages: omarchy-hyprland-monitor-clamshell takes its enable_internal branch with the lid shut and leaves the internal panel driving while docked.
  • omarchy-system-lid-close gates the lock on it, so a lid close never locks early and always waits for logind's PrepareForSleep instead — the head start its own comment describes cannot happen.
  • The clamshell fingerprint gate misjudges: pam_exec.so quiet /usr/bin/omarchy-hw-laptop-closed in the polkit PAM config and fingerprintMode: … && !laptopClosed in shell/plugins/polkit/PolkitAgent.qml both keep offering the reader when the lid it sits under is closed.

busctl get-property is the same idiom omarchy-powerprofiles-set already uses for UPower's OnBattery, and four commands in bin/ call busctl, so this adds no new dependency. Only the command changes here; #7871's work on the same lid gate touches the PAM config side, so the two diffs don't overlap.

Verified on a MacBook Air M2 (J413) running Asahi Arch, where /proc/acpi does not exist:

$ busctl get-property org.freedesktop.login1 /org/freedesktop/login1 \
    org.freedesktop.login1.Manager LidClosed
b false
$ hyprctl devices | sed -n '/Switches:/,$p'
Switches:
	Switch Device at aaab39e32040:
		Apple SMC power/lid events

test/shell.d/hw-laptop-closed-test.sh stubs logind's two answers, asserts the exit codes the callers branch on, and asserts the ACPI fallback stays. It fails against the current command — the closed lid exits 1 — and passes against this one.

./test/all — 189 of 191 test files pass. bar-icon-geometry-test.sh and snapper-test.sh fail identically on a clean checkout on this machine and are unrelated: a bar icon painted 0.59 px off center, and a missing sibling omarchy-iso checkout. bar-widget-contract-test.sh flaked once during a full run and passes both in isolation and on re-run.

Fixes #9753

Copilot AI balanced review requested due to automatic review settings August 23, 2026 19:10

Copilot AI 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.

Pull request overview

Uses logind’s evdev-backed lid state to support clamshell detection on hardware without ACPI lid files.

Changes:

  • Queries logind before falling back to ACPI.
  • Adds shell tests for open and closed logind responses.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-hw-laptop-closed Adds logind-based lid detection.
test/shell.d/hw-laptop-closed-test.sh Tests logind lid responses and preserves the ACPI fallback.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +41 to +46
# Nothing else in the tree can stand in for logind here, so a machine whose
# logind cannot answer has to keep reaching the ACPI button this command has
# always read.
grep -F '/proc/acpi/button/lid/*/state' "$hw_laptop_closed" >/dev/null ||
fail "the ACPI lid button stays as the fallback"
pass "the ACPI lid button stays as the fallback"
@cristim

cristim commented Sep 20, 2026

Copy link
Copy Markdown

Confirming this on a second Asahi machine, a different model and SoC generation from the M2 Air in the description.

MacBookPro17,1 (M1, 2020), Arch Linux ARM, kernel 7.1.13-2-1-ARCH, omarchy 4.0.3-mac.1.

$ ls /proc/acpi
ls: cannot access '/proc/acpi': No such file or directory

$ cat /sys/class/input/input0/name
Apple SMC power/lid events
$ cat /sys/class/input/input0/capabilities/sw
1                                    # bit 0 = SW_LID

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

$ omarchy-hw-laptop-closed; echo $?
1

/proc/acpi is absent entirely here, not merely the lid button, so the glob in the current command cannot match on this hardware and the exit code is structurally pinned to 1. logind answers the property normally, and as an unprivileged session user, which is the part this PR depends on.

Scope of what I tested: I confirmed the open-lid reading and that logind responds. I did not capture a lid-closed sample on this machine, so I am not independently confirming the b true transition here. I can add that reading if it would help.

One thing worth flagging for whoever merges this

On this hardware the helper is not the only broken half. default/hypr/bindings/utilities.lua binds:

o.bind("switch:on:Lid Switch",  nil, "omarchy-system-lid-close", { locked = true })
o.bind("switch:off:Lid Switch", nil, "omarchy-hyprland-monitor-clamshell", { locked = true })

and hyprctl devices reports:

Switches:
	Switch Device at aaab35433e80:
		Apple SMC power/lid events

Lid Switch never matches, so neither bind fires and omarchy-system-lid-close never runs at all. With this PR applied the helper would return a correct answer that nothing on this machine asks for. Both halves are described in #8418; this PR addresses one of them. That is not an argument against merging it, only that lid behaviour on Apple Silicon needs the bind fix too before the user-visible symptom goes away.

Overlap with #9754

#9754 rewrites the same command and adds the same new test file, so the two conflict and only one can land. The substantive differences, in case it helps pick:

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 0b52b8b9bd11ec5e6983f64af8a73b81982546a4. The logic is right and the change is proportionate. It is waiting on a reading from real hardware, because a VM has no lid to close.

What ran, on a disposable Omarchy VM: a reproduction of my own that stubs logind's reply and fakes an ACPI lid by mounting a tmpfs over /proc/acpi in a private mount namespace. Against quattro (b18ab495) it fails in the three cases this PR is about: logind says closed with no ACPI lid button (the Asahi case, #8418), stale ACPI says closed while logind says open (the Razer case, #9753), and ACPI open while logind says closed. On this head all three pass, and so do the four fallback cases: no logind with ACPI closed, open or absent, and an unparseable logind reply. With the command reverted they fail again, and so does the new hw-laptop-closed-test.sh. Against the VM's real logind the command answers open both as the user and as root with an empty environment, which is how the pam_exec fingerprint gate runs it. ./test/cli, hw-laptop-closed-test.sh, monitor-recovery-test.sh, lid-close-test.sh and polkit-test.sh pass.

Second opinion (Codex Medium): it found two things I had not reasoned about. I checked both against systemd v262's source, and both hold. Neither is a reason to hold this back, and neither has a fix that isn't a design choice, so I have pushed nothing:

  • When every logind button action is set to ignore (HandlePowerKey, HandleSuspendKey, HandleHibernateKey, HandleRebootKey, the three HandleLidSwitch* and the rest, long presses included), manager_enumerate_buttons in logind.c watches no switch at all, and manager_is_lid_closed then answers false for an empty set. On such a laptop, a closed lid reads as open and never reaches the ACPI fallback, which would have got it right. Omarchy's own drop-in ignores only the power key, so a stock install is unaffected. It only bites someone who has ignored every key on purpose.
  • busctl get-property does not honour --timeout: it calls sd_bus_call_method with the default timeout of 25 seconds. If logind holds its bus name but stops answering, the fingerprint gate would stall sudo and polkit for that long before falling back. omarchy-powerprofiles-set already makes the same unbounded call, and a logind in that state breaks lid handling anyway.

The rest of its review agreed with mine, and this agreement shouldn't be counted as independent: it found the test non-vacuous, the fix proportionate, and nothing that regresses on desktops, lidless VMs or ACPI laptops with a working lid.

Linked: this now closes #9753 on merge. It fixes one of the two causes in #8418. The Hyprland bind in default/hypr/bindings/utilities.lua still names Lid Switch, which Apple hardware reports as Apple SMC power/lid events, so that issue stays open. #9754 was closed in favour of this PR, and it covered the same stale-ACPI case.

Waiting on: a confirmation on the affected hardware at this exact commit. @GonzFC (#8418, Asahi) or @bbishdotdev (#9753, stale ACPI), could you run this on your machine?

curl -fsSL https://raw.githubusercontent.com/chubuntuarc/omarchy/0b52b8b9bd11ec5e6983f64af8a73b81982546a4/bin/omarchy-hw-laptop-closed -o /tmp/hw-laptop-closed
bash /tmp/hw-laptop-closed; echo "exit $?"

Run it once with the lid open, which should print exit 1, and once with the lid closed and an external monitor attached, which should print exit 0. Run it over SSH or from the external display, since closing the lid without a monitor suspends the machine. On the Razer, the open-lid run is the one that matters while /proc/acpi/button/lid/*/state still says closed. Please paste both outputs here.

@omarchybot

Copy link
Copy Markdown
Collaborator

Closing as out of scope: Omarchy now supports only installs made from the official Omarchy ISO, and this change exists for Apple Silicon, which the ISO doesn't produce. We aren't taking on code paths for setups outside that, because nobody here can test or maintain them. The community-maintained omarchy-mac project is the place for Apple Silicon work. Thanks for the work that went into this. (Checked by Claude Opus 5.5; no second review.)

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

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

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

4 participants