[i3wm] How to get the screen locked when i wake my laptop from sleep(suspend)

I am using i3wm with EOS.

It’s a very basic feature, If i suspend my Laptop and when i later wake it up, It must have the screen locked. But to my surprise as soon as it wakes up, there’s no lock. So any one can use it after waking it up.
I have googled a lot, but i can’t find a solution to it.
I am looking something like, when i wake laptop from sleep, the i3locks must itself be activated and lock the screen so only authorised user logs in.

Try to run suspend and lock command together.

systemctl suspend & i3lock -n

I am not sure if this is correct.

I had some old script I have not used for quite some time. It opens a fullscreen terminal window with cmatrix as a background. I3lock was set to be mostly transparent somewhere (not sure where).
A file lock-screen somewhere in the PATH. Notice the comment close to the end.


command="cmatrix -ab"

# get list of open windows before the script actually do anything
xdotool search --desktop $(xdotool get_desktop) --class "${terminal}" | sort > "${before_list}"

# launch terminal window with "screensaver"
$terminal -e bash -ic "${command}" &

# find window id for currently lauched terminal - a polling loop
while [ -z $window_id ]; do
    window_id=$(xdotool search --desktop $(xdotool get_desktop) --class "${terminal}" | sort | comm -23 - "${before_list}")
    sleep $loop_delay

    if [ $counter -ge 1000 ]; then
        notify-send "error: Lockscreen took too long to start"
        rm "${before_list}"
        exit 1

# cleanup
rm "${before_list}"

# put the terminal to fullscreen, lock the screen and wait until it is unlocked and then close the terminal
i3-msg "[id=${window_id}] fullscreen"

# delete active gpg cache - require new authentication when screen unlocked
gpg-connect-agent --no-autostart reloadagent /bye

# fork additional command - e.g. calling "lock-screen systemctl suspend" will still show the terminal window when woken up from suspend
$@ &

i3lock -n -t -c000000
i3-msg "[id=${window_id}] kill"

1 Like

Man! That worked.
I tried almost the same thing. But that time, it either locked the screen or just suspended it. Didn’t do both.
The only difference is, i did:

i3lock --image /path/to/img & systemctl suspend

That is, i tried to lock first and then suspend.

Anyways. Thank you for the help @vlkon

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.