Before migrating to systemd, I had a nice setup using laptop-mode where I would use the laptop "Sleep key" as a toggle for whether closing the lid put the laptop into sleep mode or not. This was just a few lines reading/writing to a file ~/.lidsleep, which I hacked into the laptop-mode shell scripts. Having switched to systemd, and wanting to do the same the "systemd way", I've come up short.
What I have managed to do is temporarily disable the "lid -> sleep" action, with this command:
# systemd-inhibit --what=handle-lid-switch cat
where the function of the final `cat` is to be a program that does not return until I type ^C.
I basically have two questions:
1) How can I make systemd perform an arbitrary command when I press the "Sleep key"?
2) Short of something like running `pgrep systemd-inhibit && pkill systemd-inhibit || systemd-inhibit --what=handle-lid-switch cat`, what is the best way to setup a toggle like this?
Final bonus question, if these two are answered:
My previous setup also included restoring the toggle to its default state (lid -> sleep : yes) when resuming from hibernate (not suspend). How would I do this using systemd?
I don't see why you think it is better to do it the proper "systemd way" and then go about using suck a dirty dirty hack to toggle the lid sleep. If you really want this functionality, disable systemd's handling of this, and then go back to using acpid like before. I am assuming that the sleep key produces an event in /sys/ that is picked up by acpid. But as this is your machine, not mine, I cannot tell you that this is definitely the case.
Could you please post the script you use to toggle sleep behavior using sleep button?
As WonderWoofy suggests, why not just tell systemd to not handle lid close or the sleep key (not sure it does that but if it does) and continue to use your existing solution with laptop mode tools?
systemd is not, that I know of, supposed to handle stuff like key presses and it is deliberately designed so that you can have a more sophisticated system hand events such as lid closing and so on. Moreover, it doesn't replace the remaining functionality of laptop-mode tools so assuming you used that for other things too, you'll need it anyway. That is, I can't even see how this would let you uninstall laptop-mode tools if you've been using it without giving up a bunch of other stuff. Could you explain why you want to do it without laptop-mode tools etc.?
systemd is not, that I know of, supposed to handle stuff like key presses
Not generally, no. But power, suspend, and hibernate buttons (where applicable) are handled by systemd (logind?) by default*. This default is quite easy to disable though via logind.conf.
EDIT*: also Lidswitch on laptops.
Last edited by Trilby (2013-07-15 23:32:45)
I was thinking more of the sleep key. At least on my laptop, that's a regular function key and not handled that I know of. Or is that what systemd means by HibernatKey? I think I more-or-less assumed I just didn't have one of those...
Yes, that is what is meant by those keys. My laptop has all four lidswitch (if were counting this), powerkey, sleep key, and hibernate key, the last two of which are function-key combinations that systemd does handle by default.
Last edited by Trilby (2013-07-16 01:02:18)
Oops. I forgot that systemd uses 'suspend' for what I'd call 'sleep' and 'hibernate' for what I'd call 'suspend' or 'hibernate'. You're absolutely right. My laptop only has a sleep key so I've not had to worry about configuring the hibernate/suspend key function.