You are not logged in.

#1 2023-09-21 14:26:45

Gonda
Member
Registered: 2023-09-07
Posts: 8

[Solved] Article: Slock - Incomplete instructions at lock at suspend

Solution

https://bbs.archlinux.org/viewtopic.php … 7#p2122247

Post

https://wiki.archlinux.org/title/Slock#Lock_on_suspend

This section says to get lock on suspend working you need to do following (create service and enable):

[Unit]
Description=Lock X session using slock for user %i
Before=sleep.target

[Service]
User=%i
Environment=DISPLAY=:0
ExecStartPre=/usr/bin/xset dpms force suspend
ExecStart=/usr/bin/slock

[Install]
WantedBy=sleep.target

Enable the slock@user.service systemd unit for it to take effect for the username user.

However this will make the service crash like:

Sep 21 12:33:07 IdeapadArch xset[1074]: Authorization required, but no authorization protocol specified
Sep 21 12:33:07 IdeapadArch xset[1074]: /usr/bin/xset:  unable to open display ":0"

This is because the XAUTHORITY environment variable is not set for non-user systemd. Only after doing

 sudo systemctl import-environment XAUTHORITY

does the service work properly. The solution for a static XAUTHORITY location (if you use something like LightDM) is to add an XAUTHORITY environment variable to the service, for example:

[Unit]
Description=Lock X session using slock for user %i
Before=sleep.target

[Service]
User=%i
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/%i/.Xauthority
ExecStartPre=/usr/bin/xset dpms force suspend
ExecStart=/usr/bin/slock

[Install]
WantedBy=sleep.target

If your XAUTHORITY location is not static (like in my case using sddm), I have not found a way to execute 'systemctl import-environment XAUTHORITY' on boot, instead I used xss-lock to attach to system sleep events, see solution https://bbs.archlinux.org/viewtopic.php … 7#p2122247

Last edited by Gonda (2023-09-23 04:51:05)

Offline

#2 2023-09-21 14:58:14

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 749

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

Please use the Discussion page on the wiki for discussing corrections to the wiki content.

Offline

#3 2023-09-21 15:02:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,550
Website

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

Well then add another environment variable to the service file just as DISPLAY is already there.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2023-09-21 15:27:05

seth
Member
Registered: 2012-09-03
Posts: 51,603

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

OP probably can't  - $XAUTHORITY defaults to unset defaults to ~/.Xauthority, except if you're using one of the stupider DMs. Then it's some tmpfile…
Using a user service is also not an option because  of one of the stupider strokes of systemd, https://github.com/systemd/systemd/issues/3312

=> wrap slock in some script and import the enviroment there

Online

#5 2023-09-21 15:30:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,550
Website

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

seth wrote:

... one of the stupider DMs... one of the stupider strokes of systemd

Which is the more applicable aphorism:
- Two wrongs don't make a right
- You can't fix stupid

Either way getting stupid software to do smart things is a waste of time.  Just use smarter software.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2023-09-21 15:42:45

seth
Member
Registered: 2012-09-03
Posts: 51,603

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

"Between systemd and a DisplayManager"
homer-simpsons.gif

Chances are that the DM is useless.

Online

#7 2023-09-22 03:47:21

Gonda
Member
Registered: 2023-09-07
Posts: 8

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

seth wrote:

OP probably can't  - $XAUTHORITY defaults to unset defaults to ~/.Xauthority, except if you're using one of the stupider DMs. Then it's some tmpfile…
Using a user service is also not an option because  of one of the stupider strokes of systemd, https://github.com/systemd/systemd/issues/3312

=> wrap slock in some script and import the enviroment there

Thank you for your reply. I am using sddm/i3wm and yes, it's some tmpfile, that's why I could just not specify it in the service as ~/.Xauthority. In the end I solved/settled to xss-lock.

Solution:

I copied "/usr/share/doc/xss-lock/transfer-sleep-lock-generic-delay.sh" to a user path. Changed permissions and edited locker value referencing to a script of "/usr/bin/xset dpms force suspend && /usr/bin/slock". Then I added following line in my i3 config:

exec --no-startup-id xss-lock -l *path to script*

as elaborated here: https://www.reddit.com/r/i3wm/comments/ … _of_after/

UPDATE:

I ended up just using LightDM instead of SDDM. No need for the hassle if you don't care about your Display Manager.

Last edited by Gonda (2024-02-17 13:16:35)

Offline

#8 2023-09-22 06:06:36

seth
Member
Registered: 2012-09-03
Posts: 51,603

Re: [Solved] Article: Slock - Incomplete instructions at lock at suspend

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Online

Board footer

Powered by FluxBB