Avatar
Hund

# emerge life

Using i3lock with systemd-suspend

Note: This is a remake of a few days old post [Commit: 83ac8455]. I shouldn't make posts when I'm that tired. :)

It took me a few tries before figuring this one out. But I eventually found the [the easy] solution in an old thread on the Arch Linux forums [Link].

I started out by creating the file /etc/systemd/system/i3lock.service with the following content:

[Unit]
Description=Lock screen before suspend
Before=sleep.target

[Service]
User=johan
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/johan/Scripts/i3lock.sh

[Install]
WantedBy=sleep.target

I then enabled the service with the command:

# systemctl enable i3lock.service

That’s it! And for those curious, this is what my i3lock.sh looks like:

#!/bin/bash

icon="$HOME/.config/i3/lock.png"
img="$HOME/.cache/i3lock.png"

# Take a screenshot for our background
scrot $img
# Pixelate the background
convert $img -scale 10% -scale 1000% $img
# Add the lock-icon
convert $img $icon -gravity center -composite $img
# Finally run i3lock itself
i3lock -u -i $img

It will now lock my screen before it goes to sleep, so it’s locked when it wakes up again.

Feedback

I don't have a commenting system on my blog since there's no good solutions that works without JavaScript, is user friendly and respects both the users freedom and privacy. So for now, all feedback and hellos can be done via either e-mail, XMPP or Mastodon.