Intro: I like it to have my desktop locked when my laptop goes into suspend (after for example an inactive timeout has reached).
To achieve this I crafted up the following files/settings/service
- Install i3lock (default available on mabox)
- Create a lock picture on which you state that the user needs to enter his/her password (make sure it has the correct size for your (full)screen as i3lock will not resize it.
Save this picture in a folder (for this example we place it in /usr/share/backgrounds and name it pwd.png [png is mandatory])
- Create a new file named suspend@.service in /etc/systemd/system
Place the following lines inside this file
[Unit] Description=User suspend actions Before=sleep.target [Service] User=%I Type=forking Environment=DISPLAY=:0 ExecStart=/usr/bin/i3lock -i /usr/share/backgrounds/pwd.png ExecStartPost=/usr/bin/sleep 1 [Install] WantedBy=sleep.target
- Now enable the service by running the command “sudo systemctl enable suspend@$USER.service” (if this doesn’t work then replace $USER with your username (without $))
- Test by running the command “systemctl suspend”. If all went well your picture should show and you can start typing your password and press enter to unlock your desktop.