You are not logged in.

#1 2022-04-20 19:44:48

GscheadaHamme
Member
Registered: 2021-01-12
Posts: 8

[SOLVED] i3lock doesn't lock screen immediately after wakeup

I'm trying to use i3lock to lock the screen after startup from suspend and hibernation.

The current approach leads to 2 seconds after wakeup during which the screen isn't blurred.
At the time there are 2 separate shell scripts and 2 corresponding system units, since I found out the expensive operation delaying the screen locking is blurring the screenshot.
Therefore there is one script for taking the screenshot and blurring it.

~/.local/bin/lock_screen-background.sh
#!/bin/bash
# hide i3 bar
i3-msg mode "default"

# screenshot location
tmpbg='/tmp/screen.png'

scrot -d 1 "$tmpbg"
convert -blur 0x8 "$tmpbg" "$tmpbg"
convert -composite "$tmpbg" /home/username/pictures/wallpapers/Rick_Morty-Screenlocker.png -gravity South -geometry -20x1200 "$tmpbg"

The other script is responsible for starting i3lock and cleaning up temporary files after unlocking:

~/.local/bin/lock_screen.sh
#!/bin/bash

# temporary screenshot location
tmpbg='/tmp/screen.png'

revert() {
  rm /tmp/*screen*.png
}

trap revert HUP INT TERM

i3lock -i "$tmpbg"
revert

My approach is heavily inspired by https://www.reddit.com/r/i3wm/comments/ … ck_screen/ and was split to ensure the unit regarding blurring is completed before sleep/hibernation by design of the systemd units according to https://bbs.archlinux.org/viewtopic.php?id=194792:

/etc/systemd/system/lock_screen@.service
[Unit]
Description=Activate lock screen when leaving active state
Before=suspend.target
Before=hibernate.target
Before=suspend-then-hibernate.target
Requires=lock_screen-background.service
After=lock_screen-background.service

[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/username/.local/bin/lock_screen.sh

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=suspend-then-hibernate.target
/etc/systemd/system/lock_screen-background@.service
[Unit]
Description=Create lock screen background before leaving active state
Before=lock_screen.socket

[Service]
User=%I
Type=oneshot
RemainAfterExit=yes
Environment=DISPLAY=:0
ExecStart=/home/username/.local/bin/lock_screen-background.sh

[Install]
RequiredBy=lock_screen.socket

I assumed, choosing service type oneshot and introducing dependencies ensures completion of one service unit before the other but sadly there is still a 2 second delay after wakeup.
I'm aware this approach is pretty convoluted so I'm happy about every helpful advice even if it means to dismiss my approach entirely.

Many thanks for your help.

Last edited by GscheadaHamme (2022-05-03 10:19:04)

Offline

#2 2022-04-21 12:11:17

amr962
Member
Registered: 2021-02-11
Posts: 52

Re: [SOLVED] i3lock doesn't lock screen immediately after wakeup

I simply use https://aur.archlinux.org/packages/i3lock-color which does the blurring and is pretty quick

Offline

#3 2022-04-21 14:49:45

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,691

Re: [SOLVED] i3lock doesn't lock screen immediately after wakeup

While I'm heavily in favor of i3lock-color, too, try adding "ExecStartPost=/usr/bin/sleep 5" to the lock service to give i3lock of any color some time to do its thing.

Offline

#4 2022-04-25 20:53:21

GscheadaHamme
Member
Registered: 2021-01-12
Posts: 8

Re: [SOLVED] i3lock doesn't lock screen immediately after wakeup

Many thanks for your replies.

Sadly adding "ExecStartPost=/usr/bin/sleep 5" doesn't work in my setup, but I'm planning to use i3lock-color anyway.

Currently I'm not sure how to use a compositor with i3lock-color, but it looks like a great alternative.
Thanks for the tip.

Offline

#5 2022-05-03 10:16:24

GscheadaHamme
Member
Registered: 2021-01-12
Posts: 8

Re: [SOLVED] i3lock doesn't lock screen immediately after wakeup

I finally got around to fixing my lock screen and set it up using i3lock-color, which sped up the screen blurring significantly.

There are now two configuration files:

#/etc/systemd/system/lock_screen@.service
[Unit]
Description=Activate lock screen when leaving active state
Before=suspend.target
Before=sleep.target
Before=hibernate.target
Before=suspend-then-hibernate.target

[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/username/.local/bin/lock_screen.sh
ExecStartPost=/usr/bin/sleep 2

[Install]
WantedBy=suspend.target
WantedBy=sleep.target
WantedBy=hibernate.target
WantedBy=suspend-then-hibernate.target

The script can be used by key binding to lock the screen manually.

#!/bin/bash
# hide i3 bar
i3-msg mode "default"

/bin/i3lock -B 8 -i /home/username/Pictures/Wallpaper/Rick_Morty-Screenlocker.png -C

Thanks for the input.

Last edited by GscheadaHamme (2022-05-03 13:45:05)

Offline

Board footer

Powered by FluxBB