OPINIONATED OMARCHY
TROUBLESHOOTING CORPUS
790
RECORDS
790
AUDITED
0
UNCHECKED
2388
SOURCES
LIVE
power-suspend medium very-common DISPUTE

Control what closing the laptop lid does (docked, external monitor, on AC)

archomarchyendeavouroscachyosmanjarolaptophyprlandwaylandsystemd
CORRECTED An auditor found the fix wrong or incomplete and rewrote it.
AUDIT NOTE

Almost entirely correct: the three-setting split is real, the action list matches logind.conf(5), and HandleLidSwitchDocked does default to ignore. Two errors. First, the closing note that "logind delays lid-close suspends by up to 90 s to detect docks" is wrong on both the number and the meaning: logind.conf(5) says HoldoffTimeoutSec "Specifies a period of time after system startup or system resume in which systemd will hold off on reacting to lid events... Defaults to 30s". It is a post-boot/post-resume holdoff, not dock detection, and setting it to 30s as the record does changes nothing. Second, it says HandleLidSwitchExternalPower falls back to on-AC behaviour by default. The man page says it "is completely ignored by default (for backwards compatibility) — an explicit value must be set before it will be used", so on a stock system HandleLidSwitch governs on AC too.

The cause above was not rewritten and may still contain the error described. The fix below is the corrected version.
RISK

HandleLidSwitch=ignore on a laptop means closing the lid and putting it in a bag leaves it running at full power, a real overheating and battery-drain risk.

Symptom

Closing the lid still suspends the laptop even though it is docked with an external monitor attached. Or the opposite, closing the lid does nothing at all and the machine cooks in my bag.

Cause

systemd-logind uses three separate settings: HandleLidSwitch, HandleLidSwitchExternalPower (on AC) and HandleLidSwitchDocked (docked, or more than one display connected, default ignore). A desktop power manager may also take an inhibitor lock and override logind entirely.

Fix

Set all three explicitly. HandleLidSwitchExternalPower is ignored entirely until you give it a value, so on a stock system HandleLidSwitch applies on AC as well:


# /etc/systemd/logind.conf.d/lid.conf
[Login]
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=suspend
HandleLidSwitchDocked=ignore

Valid actions: ignore, poweroff, reboot, halt, suspend, hibernate, hybrid-sleep, suspend-then-hibernate, lock, kexec.

Apply:


sudo systemctl restart systemd-logind.service

(reload also works on current systemd. Either way, logind does not retroactively change already-active sessions. If behaviour does not change, log out and back in, or reboot. Check for stale sessions with loginctl list-sessions.)

Drop the HoldoffTimeoutSec=30s line from the original: 30s is already the default, and it is not dock detection. HoldoffTimeoutSec is the window after boot or after resume during which logind ignores lid events entirely. It is relevant if your machine suspends again immediately on opening the lid, not if it is picking the wrong action.

If logind is being overridden by a desktop power manager or an application inhibitor:


systemd-inhibit --list
systemd-inhibit --list --what=handle-lid-switch

A block inhibitor on handle-lid-switch means another process owns the lid, and no logind setting will win until it releases.

Verify

loginctl show-session $XDG_SESSION_ID and closing the lid produce the action you configured. journalctl -f -u systemd-logind logs Lid closed. and the action taken.

Sources

lid-close-wrong-action-docked-or-external-power