I have a laptop that runs several desktop sessions, which are all gnome-based (gnome,budgie,pantheon).
Budgie and Pantheon don’t share the screen-locking mechanism of gnome, so I implement xscreenlock (or i3lock) to be run when the session starts.
When it comes to linking the screen-locker to the suspend daemon (lid-close or power-button), all of the options that I am finding point to creating a service that is triggered by sleep.target, that executes an xscreensaver or i3lock command.
The issue is that the service is also active if the user logs into a gnome session, unless the service can be set to only go into effect in a specific desktop environment.
Or am I approaching this incorrectly?
https://github.com/ruudud/i3wm-scripts#lock-on-suspend-when-closing-laptop-lid
[Unit]
Description=i3lock on suspend
Before=sleep.target
[Service]
User=<USERNAME>
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 141414
[Install]
WantedBy=sleep.target
https://bbs.archlinux.org/viewtopic.php?pid=1218771#p1218771
[Unit] Description=XScreensaver
[Service]
ExecStart=/usr/bin/xscreensaver -no-splash
[Install]
WantedBy=default.target