You are not logged in.

#1 2020-09-10 11:33:36

internatetional
Member
Registered: 2020-09-10
Posts: 4

Lock screen doesn't run on suspend with a sleep hook

Hi, this is my first time posting in the Arch Linux help forum. I'm currently trying to configure my lock screen to run on suspend with a sleep hook, like so:

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

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

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

and this sleep hook came with this AUR package and is installed under the filename betterlockscreen@.service in /usr/lib/systemd/system.

I tried putting my machine in sleep mode and waking it back, but the lock screen didn't seem to be running. Here's what I got when I run systemctl status betterlockscreen@nate.service (my username is nate, meliora is the hostname)

● betterlockscreen@nate.service - Lock screen when going to sleep/suspend
     Loaded: loaded (/usr/lib/systemd/system/betterlockscreen@.service; enabled; vendor preset: disabled)
     Active: inactive (dead)

Sep 10 16:35:41 meliora systemd[1]: Started Lock screen when going to sleep/suspend.
Sep 10 16:35:41 meliora betterlockscreen[3372]: No protocol specified
Sep 10 16:35:41 meliora betterlockscreen[3372]: xdpyinfo:  unable to open display ":0".
Sep 10 16:35:41 meliora betterlockscreen[3367]: Got /home/nate/.cache/i3lock/
Sep 10 16:35:41 meliora betterlockscreen[3378]: No protocol specified
Sep 10 16:35:41 meliora betterlockscreen[3378]: i3lock: Could not connect to X11, maybe you need to set DISPLAY?
Sep 10 16:35:41 meliora systemd[1]: betterlockscreen@nate.service: Succeeded.

I'm having trouble figuring this out, some assistance would be appreciated.

Last edited by internatetional (2020-09-10 11:45:09)

Offline

#2 2020-09-10 12:09:19

solskog
Member
Registered: 2020-09-05
Posts: 462

Re: Lock screen doesn't run on suspend with a sleep hook

A system wide systemd service don't have the necessary environment variable from X e.g: DISPLAY and XAUTHORITY.
It's preferred to create a user@.service instead. read this:
https://wiki.archlinux.org/index.php/Sy … XAUTHORITY

Offline

#3 2020-09-10 13:59:55

internatetional
Member
Registered: 2020-09-10
Posts: 4

Re: Lock screen doesn't run on suspend with a sleep hook

solskog wrote:

It's preferred to create a user@.service instead. read this:
https://wiki.archlinux.org/index.php/Sy … XAUTHORITY

I really regret to say this but... I'm not sure how to go about doing it sad
What exactly is a user@.service, and how do I create it?
If I understand correctly from the Arch wiki page you referred me to, my systemd unit needs to know the DISPLAY and XAUTHORITY variables, and systemd provides a shell script to import those, but I don't know what I'm supposed to do with the script, sorry sad

Offline

#4 2020-09-11 04:55:56

solskog
Member
Registered: 2020-09-05
Posts: 462

Re: Lock screen doesn't run on suspend with a sleep hook

I followed author's instruction https://github.com/pavanjadhaw/betterlockscreen to install and configure this AUR package. And it works out of the box.

# move service file to proper dir (the aur package does this for you)
cp betterlockscreen@.service /etc/systemd/system/

# enable systemd user@.service
systemctl enable betterlockscreen@$USER

These two steps are what I previous stated about user@.service. The author already does it for you. But Pls do it manually via command line and also check your DISPLAY enviroment variable:

echo $DISPLAY
:0
systemctl status betterlockscreen@$USER
systemctl suspend
...
systemctl status betterlockscreen@$USER

Offline

Board footer

Powered by FluxBB