Is there a such thing as a systemd service that is session-sensitive?

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

systemd services are “system” services, not specific to a Desktop session.
That is why Desktop settings are located in hidden directories in your User’s /home directory or partition… That way, the Desktop starts up only when a User logs in and is identified so that settings specific only for that User are loaded.

I suppose someone could specify enough conditions in the Unit file to cause User-specific behavior, but that’s doing things the hard way.

TSU

Perhaps run a script (rather than just executing i3lock directly) to test active sessions and desktop environments. Then determine further administrator actions from there.

For example, ’systemd-loginctl list-sessions’, ‘systemd-loginctl session-status <session ID>’ might provide info, as well as ‘w’ and ‘ps -u <user>’.