2

I have recently moved to using systemd to manage power control.

In order to get my screen to be locked when returning from suspend, I created /etc/systemd/system/i3lock.service with these contents

[Unit]
Description=i3lock
Before=sleep.target

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

[Install]
WantedBy=sleep.target

and then ran systemctl enable i3lock.service.

But this means the lock is always for the fommil user.

How does one set up a service that will run the screen locker as the user who currently owns the X session?

2

1 Answer 1

1

You should use a user unit for that instead of a system unit. Put it in /etc/systemd/user/, if you want it to be available (not enabled) for all users, or $HOME/.config/systemd/user/, if you want it to be available for that user only.

Then you can remove the User= option (and probably the Environment= option as well, you can run systemctl show-environment as the current user to see if the required env vars have already been imported), and then enable the service with systemd --user enable i3clock. (Or sudo systemd --global enable i3lock if it's available for all users and you want it to be enabled for all users.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .