You are not logged in.

#1 2013-10-10 14:42:55

labotsirc
Member
Registered: 2013-08-21
Posts: 108

Laptop under AC, do nothing when lid is closed.

I need the laptop to stay fully awake when the lid is closed and plugged to AC.
On battery, the default behavior is ok.

This is /etc/systemd/logind.conf

[cristobal@orion ~]$ cat /etc/systemd/logind.conf 
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# See logind.conf(5) for details

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#IdleAction=ignore
#IdleActionSec=30min
[cristobal@orion ~]$ cat /etc/systemd/logind.conf 

Question,
If i change the option HandleLidSwitch to 'ignore' will this affect both 'on battery' and 'on AC' states? If yes, then how we can be more specific?

Offline

#2 2013-10-10 14:56:52

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

Re: Laptop under AC, do nothing when lid is closed.

There should be no difference (as far as logind is concerned) between the power source being connected or disconnected.  If you want fine grain control over what happens during lid switch events, you will need to use a third party tool for this.

The most common choice is acpid.  This is a daemon that just repsonds to certain machine events, running scripts that you set up.  There is a wiki page for this.  It used to be one of the more common ways of handling things before logind came along with that functioanlity.


Edit: Oh yeah, and if you set up acpid, don't forget to tell logind to ignore those events in logind.conf.

Last edited by WonderWoofy (2013-10-10 14:57:25)

Offline

#3 2013-10-10 15:00:13

labotsirc
Member
Registered: 2013-08-21
Posts: 108

Re: Laptop under AC, do nothing when lid is closed.

WonderWoofy wrote:

There should be no difference (as far as logind is concerned) between the power source being connected or disconnected.  If you want fine grain control over what happens during lid switch events, you will need to use a third party tool for this.

The most common choice is acpid.  This is a daemon that just repsonds to certain machine events, running scripts that you set up.  There is a wiki page for this.  It used to be one of the more common ways of handling things before logind came along with that functioanlity.


Edit: Oh yeah, and if you set up acpid, don't forget to tell logind to ignore those events in logind.conf.

I see, will check acpid. In the file i posted, everything is commented, so i just leave it like that right?

Offline

#4 2013-10-10 22:09:42

Pse
Member
Registered: 2008-03-15
Posts: 413

Re: Laptop under AC, do nothing when lid is closed.

Since the default behavior is fine in my case most of the time, I use the following command to disable suspend manually when I want to close the lid and leave the laptop on:

systemd-inhibit --what=handle-lid-switch:sleep --who=$(id -un) --why="I want" --mode=block cat

To stop it, press CTRL-C. Not elegant, but it's good enough for me.

Offline

#5 2013-10-10 23:58:58

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

Re: Laptop under AC, do nothing when lid is closed.

Pse wrote:

Since the default behavior is fine in my case most of the time, I use the following command to disable suspend manually when I want to close the lid and leave the laptop on:

systemd-inhibit --what=handle-lid-switch:sleep --who=$(id -un) --why="I want" --mode=block cat

To stop it, press CTRL-C. Not elegant, but it's good enough for me.

I've pulled this crap too... Hey, it works!


Edit: Oh and @OP, if all the values are commented that means that they are all set to the defaults.  You need to look over the man page to see if the defaults are what you want, or what might be better.  (Hint: You don't want the defaults.)

Last edited by WonderWoofy (2013-10-11 00:00:13)

Offline

#6 2013-11-12 14:53:20

xterminus
Member
From: Tacoma, WA, USA, Earth, Sol, M
Registered: 2005-10-30
Posts: 93

Re: Laptop under AC, do nothing when lid is closed.

labotsirc wrote:

I see, will check acpid. In the file i posted, everything is commented, so i just leave it like that right?

What I do is pretty simple.  In /etc/systemd/logind.conf I uncommented the lidswitch statement and set it to ignore it: eg:

#HandleLidSwitch=suspend

became

HandleLidSwitch=ignore

Then I tweaked /etc/acpid/handler.sh, browse towards the bottom and add/replace the default with something like the following:

    button/lid)
        case "$3" in
            close)
                logger 'LID closed'

                # Closed on Battery (suspend)
                acpi | grep -q "Discharging"
                if [ $? = 0 ] ; then
                        systemctl suspend

                # Otherwise blank screen
                else
                        sudo -u `ps -o ruser= -C xinit` xset -display :0 dpms force off
                fi

                ;;
            open)
                logger 'LID opened'
                # Force Monitor on, regardless of suspended status
                sudo -u `ps -o ruser= -C xinit` xset -display :0 dpms force on
                ;;
            *)
                logger "ACPI action undefined: $3"
                ;;
    esac
    ;;

It works perfectly here, and has the advantage that suspend is very, very fast since it's being handled behind the scenes and not by your DE.  On the flip side, it's stupid that you have to setup hackery like this in order to do something reasonably simple and standard on laptops.

Offline

Board footer

Powered by FluxBB