logind (part of systemd) emits events when the system is lock or goes into
These events though, are simple D-Bus events, and don't actually run anything. There are no facilities to easily run anything on these events either (e.g.: a screen locker).
This application fills this gap.
When the system is either locked, or about to go into sleep, this service will
sleep.target systemd targets respectively.
You can then have any of your own services (including screen lockers and other one-shot commands) run when this event is activated.
Note that systemd already has a
sleep.target, however, that's a
system-level target, and your user-level units can't rely on it. The one
included in this package does not conflict, but rather compliments that one.
A package is available in the AUR:
paru -S systemd-lock-handler
You can manually build and install:
firstname.lastname@example.org:~whynothugo/systemd-lock-handler cd systemd-lock-handler make build sudo make install
You should service files for anything you intend to intend to run on lock. For
enabling this service file would run
[Unit] Description=A simple X screen locker Requisite=xorg.target [Service] ExecStart=/usr/bin/slock # Explicitly run `unlock.target` when locker exits. This stops # `lock.target`, and other units that are wanted by it. ExecStopPost=/usr/bin/systemctl --user start unlock.target [Install] WantedBy=lock.target WantedBy=sleep.target
You'll also need to enable and start this service:
systemctl --user enable --now systemd-lock-handler.service
Lock your session using
This will mark your session as locked, and start
lock.target along with any
services that are
Sleep your device using
This will start
sleep.target along with any services that are
This will happen before the system is suspended.
systemd-lock-handler is licensed under the ISC licence. See LICENCE for details.