You are not logged in.

#1 2013-04-02 21:14:13

AsmundEr
Member
From: Trondheim, Norway
Registered: 2010-05-07
Posts: 13

[systemd] Toggle whether lid close makes laptop sleep

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?

Offline

#2 2013-04-02 21:18:43

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: [systemd] Toggle whether lid close makes laptop sleep

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.

Offline

#3 2013-07-06 19:06:31

pinak
Member
Registered: 2013-07-06
Posts: 1

Re: [systemd] Toggle whether lid close makes laptop sleep

Could you please post the script you use to toggle sleep behavior using sleep button?

Offline

#4 2013-07-15 23:26:49

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,662

Re: [systemd] Toggle whether lid close makes laptop sleep

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.?


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

#5 2013-07-15 23:31:30

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,829
Website

Re: [systemd] Toggle whether lid close makes laptop sleep

cfr wrote:

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)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#6 2013-07-15 23:40:45

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,662

Re: [systemd] Toggle whether lid close makes laptop sleep

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...


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

#7 2013-07-16 01:01:39

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,829
Website

Re: [systemd] Toggle whether lid close makes laptop sleep

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)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#8 2013-07-16 01:09:01

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,662

Re: [systemd] Toggle whether lid close makes laptop sleep

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.


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

Board footer

Powered by FluxBB