How to lock and suspend when lid closed


#42

tl;dr: try slock instead :smiley:


#44

Slock works better/more consistent than i3lock-fancy, the only “annoying” thing that persists is that I can’t lock&suspend twice in a short amount of time. The second time it’ll only suspend after unlocking which is useless.

Following setup works for me now:

Two .service files + as is/stock /etc/systemd/logind.conf

I’m going to play around with more screen lockers but for now it’s functional enough, thanks guys for your help!


#45

Bump!

I managed to get screen locking working for both suspend and hiberbnate (and hybrid-sleep as well) with a single unit file:

# /etc/systemd/system/resume@.service

[Unit]
Description=Lock the screen on resume

[Service]
User=%I
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock

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

^ The WantedBy string includes all the .targets I could find that seemed to relate to resuming.

It could be that the problems experienced by others were because of race conditions between the multiple unit files, the single version above seems to work very well for me.

To get this working, first disable the current unit file (if it is in use):

systemctl disable resume@${USER}.service

Then add the new file & remove any others and reload the configuration:

systemctl daemon-reload

Finally re-enable the unit:

systemctl enable resume@${USER}.service

A message should list the symlinks being made to all the .target.wants.d directories, reboot to test.


#46

This configuration doesn’t work for me, it goes to sleep but doesn’t lock at all…


#47

Oh dear :confused:

Are there any errors in the journal?

journalctl -u resume@${USER}.service

Are all the symlinks in place?

ls -l /etc/systemd/system/{hibernate,{hybrid-,}sleep,suspend,suspend-then-hibernate}.target.wants

Also, have you rebooted since enabling the unit file?