I am running Sway on Fedora 26 and want my laptop to be locked when I close my screen. I changed HandleLidSwitch to lock in /etc/systemd/logind.conf and ran systemctl restart systemd-logind after that. However, closing the lid does nothing.

The lock program I intend to use is Swaylock and I can manually call it by runnig the command swaylock in a terminal.

How do I make Systemd call swaylock when it tries to close the screen (as instructed to do in logind.conf)?

  • Normally, you can control what happens on LidSwitch through your window manager. Which window manager do you use? /etc/systemd/logind.conf is responsible for what happens on LidSwitch, but your window manager may force an inhibitor lock which overrides logind.conf. Oops, logind.conf doesn't support a script action. I think you can make one script enabling acpid daemon and writing a /etc/acpi/handler.sh. For more info, consult man logind.conf and bbs.archlinux.org/viewtopic.php?id=158081 and update if you find a solution. I don't have a laptop currently to test it. – Konstantinos Mar 13 at 19:58


If the HandleLidSwitch is set to sleep, you can create a new systemd service with sleep target, and thus your service will be executed when the sleep is called (lid closed) here is an example with power target.. update that to sleep.

Command on lock

This question explain how to run a command when the lock screen is enabled

Screen saver

You can use a bash to watch for screen saver if you want to trigger that when the screen saver is enabled it's explained here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.