I3 - Does not lock on suspend

I am using the i3 community edition.
The screen lock works perfectly when the threshold time has passed while the laptop is awake. It works fine after the threshold even while the laptop is suspended.
But, if I suspend the laptop and wake it before the lock threshold time has passed, the screen is not locked. How do I enable this?

1 Like

I'm using systemd unit to lock screen before it goes to suspend/hibernation. Here how it works:
Create file named /etc/systemd/system/i3lock@.service with following content:

[Unit]
Description = Lock screen when going to sleep/suspend/hibernate

[Service]
User=%I
Type=simple
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3exit lock
TimeoutSec=infinity

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

And enable service:

sudo systemctl enable i3lock@$USER

Edit:
I forgot, you need "--nofork" option for i3lock. In this example, edit /usr/bin/blurlock and add "-n" option to i3lock like this:
i3lock -n -i /tmp/screenshotblur.png

2 Likes

Worked. Thanks!

The suggested solution almost works for me:

  • I close the lid of my laptop (2011 macbook pro)
  • wait for it to go into hibernation
  • open the lid again

The screen lock is brought up BUT with a 1 to 2 second delay. During this delay I can register keystrokes and operate the cursor as if the pc was unlocked. Do you have any idea why that is?

Here's a service I wrote a little while back, not sure if it will get the job done for you on I3. It's worth giving it a shot.

Create the service file:

/etc/systemd/system/screen-lock.service

With the following contents:

[Unit]
Description=Lock screen upon suspend
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/loginctl lock-sessions

[Install]
WantedBy=sleep.target

Enable the service:

sudo systemctl enable screen-lock.service

I had the same behavior once but I don't remember what caused it.
I'm using betterlockscreen as my config right now and it's working fine.

It didn't work, unfortunately... thanks for the reply though

I kind of half figured that. I only tested it on KDE.

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

Forum kindly sponsored by