You are not logged in.

#1 2012-10-04 13:50:46

darkfeline
Member
Registered: 2012-02-14
Posts: 94

[solved] i3lock and systemd suspend

I have this in /usr/lib/systemd/systemd-sleep/

#!/bin/sh
#
# 00screensaver-lock: lock workstation on hibernate or suspend

DBUS=$(ps aux | grep 'dbus-launch' | grep -v root)
if [[ ! -z $DBUS ]];then
    USER=$(echo $DBUS | awk '{print $1}')
    USERHOME=$(getent passwd $USER | cut -d: -f6)
    export XAUTHORITY="$USERHOME/.Xauthority"
    for x in /tmp/.X11-unix/*; do
        DISPLAYNUM=$(echo $x | sed s#/tmp/.X11-unix/X##)
        if [[ -f "$XAUTHORITY" ]]; then
            export DISPLAY=":$DISPLAYNUM"
        fi
    done
else
    USER=darkfeline
    USERHOME=/home/darkfeline
    export XAUTHORITY="$USERHOME/.Xauthority"
    export DISPLAY=":0"
fi

case "$1" in
    pre)
        su $USER -c "$USERHOME/bin/myi3lock" &
        ;;
    post)
        ;;
    *) 
        exit $NA
        ;;
esac

For some reason, when I resume, I get a quick glimpse of i3lock before it dies.  Presumably systemd is killing it or something?  I imagine all X lockers have this same problem with systemd.  Any solutions?

Last edited by darkfeline (2012-10-04 17:41:06)

Offline

#2 2012-10-04 13:58:35

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [solved] i3lock and systemd suspend

please use code tags.

you may want to use this service file instead:

[Unit]
Description=i3lock
Before=sleep.target

[Service]
User=<user>
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 000000

[Install]
WantedBy=sleep.target
systemctl enable i3lock.service

Offline

#3 2012-10-04 17:42:28

darkfeline
Member
Registered: 2012-02-14
Posts: 94

Re: [solved] i3lock and systemd suspend

Oops, I edited in some code tags.

Thanks for the unit file, it works!

Offline

#4 2014-11-20 12:30:11

SuperBo
Member
Registered: 2012-02-20
Posts: 45

Re: [solved] i3lock and systemd suspend

Find this topic useful. Thank you!

Offline

#5 2015-02-17 21:51:01

bartbkr
Member
Registered: 2015-02-17
Posts: 10

Re: [solved] i3lock and systemd suspend

I'm not sure if anyone is still paying attention to this thread, but after an update, I am getting a similar error:

My resume.service:

[Unit]
Description=User resume actions
Before=sleep.target

[Service]
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 000000

[Install]
WantedBy=sleep.target

I have added in a User line under [Service] to no avail. When trying to enable the service and I return from suspend, systemctl status resume.service reads:

i3lock[14065]: No protocol specified
i3lock[14065]: i3lock: Could not connect to X11, maybe you need to set DISPLAY?
systemd[1]: resume.service: main process exited, code=exited, status=1/FAILURE
systemd[1]: Unit resume.service entered failed state.
systemd[1]: resume.service failed.

I've also tried other X-based screen lockers and none work. I am using gdm as the display manager and i3 as the window manager. Could this be an issue with the recent update to X11?

Offline

#6 2015-02-17 23:21:12

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,413
Website

Re: [solved] i3lock and systemd suspend

You probably want to start a new thread. But there's a reason you see horrendous hacks like in the first post - the DISPLAY variable is prone to change, for example when you relogin. You also need XAUTHORITY.

Last edited by Alad (2015-02-17 23:23:17)


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#7 2015-02-21 00:20:42

bartbkr
Member
Registered: 2015-02-17
Posts: 10

Re: [solved] i3lock and systemd suspend

Thanks, I just posted a new thread:

https://bbs.archlinux.org/viewtopic.php?id=193946

Offline

Board footer

Powered by FluxBB