Step 0: Preparation
Step 1: Create the lock script
Step 2: Create the systemd
module
Step 3: Enable the systemd
module
Disable any preexisting screen locker. I'm using KDE on Arch Linux, so my options for kscreenlocker look like this:
If you don't have it already, make sure you install i3lock
. I highly recommend installing i3lock-color.
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
Create a file using sudo
at /etc/systemd/system/[email protected]
, 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
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>
@Raymo111 I'm aware that it should work, but I don't know why it doesn't, and yes I do have i3lock-color installed and I do have my own script with a bunch of options (https://github.com/SafwanLjd/BlurLocker) and neither my script nor running /bin/i3lock work through the method in this gist; However, as mentioned above, when trying the same method with slock it also works.
For now I just use xss-lock to sort of achieve the same behavior and it works almost flawlessly (and yes, I did kill xss-lock when trying this method, it still doesn't work), but I would love to be using this method, I just don't know why it won't work...