Short power press to sleep, long press to power off
Hi,
is it possible to configure your power button such that if you quickly press the power button it will put the computer into sleep/suspend mode, but if you press if for a little longer it will poweroff? I think it has something to do with /etc/system/logind.conf. Do you have any ideas? Thanks!
About this post
- Posted
- Archived
- Score
- 10 · 99% up
- Kind
- Text
- ID
- lfmlju
3 comments
You need to set it to
HandlePowerKey=ignorein the logind.conf and then have your DE or WM to react to your button press. The button should be called something like "XF86PowerOff".But keep in mind, that the power button often has a delay before sending an event, e.g. you have to hold it for a second until your systems gets the "XF86PowerOff" event. And often there is a hard shutdown, when you press it for a longer time (a couple of seconds). This functionality is in firmware and can't be turned of.
So you would need to find the sweet spots between pressing for one second and less than five seconds. I'd recommend a little script that checks for a button press. If it gets one, it waits a few seconds for another one. If nothing else happens, it suspends, if there is a second press it shuts down.
Edit: This might work. Save it somewhere, make it executable and have your DE run it wen XF86PowerOff is pressed:
Basically: if run the first time, the script checks if there is a file in /tmp with the the name of the script. It checks this for five seconds, and if there is no file the script calls
systemctl suspendand sends your system to sleep.But in the beginning the script checks if there is another instance of itself running. So if you press the power button a second time (in about 5 seconds or less) it sees it is already running. Then it writes the file to /tmp. Now the first instance finds the file, kills the second process and calls
systemctl poweroff.Thanks, I'll try that
I think that the DE handles that. Which are u using?