Arch Linux Systemd – Suspend and Lock Screen on Lid Close

arch linuxscreen-locksuspendsystemd

what is the most straightforward way to lock the screen AND suspend when closing the lid? I'm using event hooks in /etc/systemd/logind.conf and successfully suspend upon closing the lid. However I'm lost when it comes to the locking part – am I supposed to enable some screensaver service and how can I trigger two events at once in logind.conf?

Best Answer

There are a couple of examples in the Arch Wiki.

Basically, it involves creating a service file for your screen locker and ensuring it is hooked to either the suspend, hibernate or sleep targets.

If you use a simple screen locker like slock, /etc/systemd/system/lock.service would look like this:

[Unit]
Description=Lock the screen on resume from suspend

[Service]
User=jason
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock

[Install]
WantedBy=suspend.target

Other examples on the wiki have more complex options, including shutting down and bringing up other services, etc.

Related Question