You are not logged in.

#1 2017-07-04 12:54:29

stertingen
Member
Registered: 2016-05-06
Posts: 3

Systemd sleep hook as user

Hello,

I've recently set up xautolock with i3lock as locker for my desktop. It works fine, but I'd love to have my screen locked when suspending or hibernating my computer.
I've discovered the systemd sleep hooks (https://wiki.archlinux.org/index.php/Po … leep_hooks), but they do not seem to work when enabling service files with the --user option.
Is there a way to use these systemd hooks without setting them up globally?


~/.config/systemd/user/blurlock.service

[Unit]
Description=Blur und lock screen
Before=sleep.target

[Service]
Type=forking
Environment=DISPLAY=:0
ExecStart=/home/stertingen/bin/blurlock
ExecStartPost=/usr/bin/sleep 1

[Install]
WantedBy=sleep.target

~/bin/blurlock

#!/bin/sh

IMGFILE=screen.png
[ -d "$XDG_CACHE_HOME" ] && IMGPATH=$XDG_CACHE_HOME/$IMGFILE || IMGPATH=$HOME/.cache/IMGFILE

sleep 0.1
scrot --silent $IMGFILE --exec "mv $IMGFILE $IMGPATH"
convert $IMGPATH -gaussian-blur 5x5 $IMGPATH
i3lock --image=$IMGPATH

tree ~/.config/systemd/user/

.
├── blurlock.service
└── sleep.target.wants
    └── blurlock.service -> /home/stertingen/.config/systemd/user/blurlock.service

Offline

#2 2017-07-05 20:49:35

randomguy
Member
Registered: 2007-06-19
Posts: 101

Re: Systemd sleep hook as user

There doesn't seem to be a sleep target in a systemd --user:

$ systemctl --user list-unit-files --all --type target
UNIT FILE                    STATE 
basic.target                 static
bluetooth.target             static
busnames.target              static
default.target               static
exit.target                  static
graphical-session-pre.target static
graphical-session.target     static
paths.target                 static
printer.target               static
shutdown.target              static
smartcard.target             static
sockets.target               static
sound.target                 static
timers.target                static

I wonder whether the systemd maintainers would consider including it as it seems useful for --user...

Edit: words

Last edited by randomguy (2017-07-05 21:06:22)

Offline

#3 2018-09-28 04:39:04

aiguofer
Member
Registered: 2011-10-09
Posts: 32

Re: Systemd sleep hook as user

Sorry to revive this, but figured I'd post a useful link in case someone stumbles upon this thread in the future: https://unix.stackexchange.com/question … -hibernate

Essentially, trick is to use dbus in your user session to listen for the event you care about (suspend, screen lock, etc) and start a user version of the target.

Last edited by aiguofer (2018-09-28 04:40:09)

Offline

#4 2018-11-28 00:49:49

randomguy
Member
Registered: 2007-06-19
Posts: 101

Re: Systemd sleep hook as user

Can you elaborate more? I do not see how this is using dbus.

Offline

#5 2018-11-28 02:59:27

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,729

Re: Systemd sleep hook as user

There's  a link to a stackoverflow with  a link to the code that listens to dbus

Last edited by V1del (2018-11-28 03:00:40)

Offline

#6 2018-11-28 03:07:47

randomguy
Member
Registered: 2007-06-19
Posts: 101

Re: Systemd sleep hook as user

Nevermind, I thought the post before me meant a systemd based dbus call. I misread.

Coding it with dbus bindings/implementation in whatever language is obiviously always a solution.

OT: Edit: Thanks for the edit making it more gentile big_smile

Last edited by randomguy (2018-11-28 03:12:16)

Offline

Board footer

Powered by FluxBB