Automatic i3lock on Suspend

I use Manjaro with i3 on my laptop and I have my laptop set to suspend when I close the lid. However, a few days ago, I realised that when it suspended in this way, it didn't lock - when I open the lid again, I'm just presented with an unlocked session!

After a bit of searching, I found that someone had shared the configuration for a systemd service on the Arch Linux Forum. I've repeated it below for convenience.

[Unit]
Description=i3lock
Before=sleep.target

[Service]
User=<user>
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 6600cc

[Install]
WantedBy=sleep.target

You need to change <user> to be your username and then save this configuration file as /etc/systemd/system/i3lock.service. You can also set a custom colour for the lockscreen - I chose purple (#6600cc).

Once you've saved your new service, you need to start and enable it (or just enable it and reboot).

sudo systemctl start i3lock.service
sudo systemctl enable i3lock.service

And just for good measure, you should probably test this new functionality!