Manjaro i3 Lock Screen When Lid Closed

10/18/20191 Min Read — In DevTools, Linux

When you close the lid on your laptop (using Manjaro i3), the laptop goes to suspend mode. But the screen doesn't lock.

You have to write a script for systemd.

i3lock

Manjaro i3 ships with i3lock and a custom blur screen out of the box.
If you use this tool, you have to create a suspend script as etc/systemd/system/suspend@.service (with root):

[Unit]
Description=User suspend actions
Before=sleep.target
[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/blurlock
ExecStartPost=/usr/bin/sleep 1
[Install]
WantedBy=sleep.target

The service starts the blurlock script before the laptop goes to sleep mode.
With ExecStartPost=/usr/bin/sleep 1 we avoid a screen flash after you open the laptop lid.

Activate the service with:

sudo systemctl enable suspend@$USER

betterlockscreen

If you use betterlockscreen (install it via AUR), you can use their script:

sudo systemctl enable betterlockscreen@$USER

Further Reading