Systemd is configured by default to shutdown the computer when the power button is pressed. I want to keep this behavior, unless when my user is logged. When I'm logged in, I want to open a shutdown dialog instead of immediately shutting down.
I have achieved to disable systemd
's handling using systemd-inhibit
in a user service that starts when I log in and stops when I log out. This method works well, except that I have an idle thread for the call to sleep 1000d
open all the time.
For cleanliness, I'm looking for a way to achieve this without the sleeping thread, which I find very annoying when I look at my htop
.
Here is my user service:
[Unit]
Description=User daemon to disable systemd's handling of the power button
[Service]
ExecStart=nohup systemd-inhibit \
--what="handle-power-key" \
--who="disable-shutdown-button script" \
--why="allows i3 to open shutdown-dialog instead" \
sleep 1000d
[Install]
WantedBy=default.target
Edit: login is done through lightdm
display manager.