Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save violentmagician/f2b6bd02565b952a13b32f212cc2629c to your computer and use it in GitHub Desktop.
Save violentmagician/f2b6bd02565b952a13b32f212cc2629c to your computer and use it in GitHub Desktop.
How to use i3lock to wake from suspend state

How to use i3lock to wake from suspend state

By Raymond Li (Raymo111), September 3rd, 2019

Last updated 28 August 2021

Table of Contents

Step 0: Preparation
Step 1: Create the lock script
Step 2: Create the systemd module
Step 3: Enable the systemd module

Step 0: Preparation

Disable any preexisting screen locker. I'm using KDE on Arch Linux, so my options for kscreenlocker look like this: The options lock screen automatically after and lock screen on resume are unchecked

If you don't have it already, make sure you install i3lock. I highly recommend installing i3lock-color.

Step 1: Create the lock script

Create a file at ~/scripts/i3lock.sh, with the following content:

#!/bin/bash
i3lock # Whatever i3lock options you want to use. Use i3lock -h for a list of options

Step 2: Create the systemd module

Create a file using sudo at /etc/systemd/system/wakelock@.service, with the following content:

[Unit]
Description=Lock the screen on resume from suspend
Before=sleep.target suspend.target

[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/%i/scripts/i3lock.sh

[Install]
WantedBy=sleep.target suspend.target

Step 3: Enable the systemd module

Enable the systemd module you just created with:

sudo systemctl enable wakelock@<YOUR-USER-NAME> --now

i3lock will now run once as a demo, then when you wake from suspend, i3lock will automatically start.

That's it! If you make any changes and want them reflected immediately without restart, simply do:

sudo systemctl restart wakelock@<YOUR-USER-NAME>

If my tutorial helped you, or if you encountered any errors or have any suggestions for me, leave a comment below to let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment