1

My laptop does not turn off the screen when the lid is closed. This is already present when booted from the Arch install stick.

The event itself is properly recognized since the system logs:

systemd-logind[500]: Lid opened.
systemd-logind[500]: Lid closed.

How can I tell the system I want the screen to be off when the lid is closed?

  • 1
    What dm are you using? – Cyclic3 Sep 30 '18 at 15:30
  • @Cyclic3: I directly boot into i3. – Suuuehgi Sep 30 '18 at 16:19
  • man logind.conf – jasonwryan Sep 30 '18 at 16:20
  • @Suuuehgi I have never used i3 before. Stupid question: have you looked around for a 'turn off the screen when not in use' – Cyclic3 Sep 30 '18 at 16:22
  • @jasonwryan: Could you tell me what I am supposed to find/search for there? – Suuuehgi Sep 30 '18 at 16:23
2

I now found an answer that works for me (single user system).

Although systemd-logind handles ACPI events, there is just a standard set of options poweroff, reboot, halt, ... (see man logind.conf) that don't include the screen alone.

The predecessor acpid also provides handlers to act on ACPI events such as lid close. The simplest way is to directly clutter use the demo file /etc/acpi/handler.sh and alter the section

button/lid)
    case "$3" in
        close)
            logger 'LID closed'
            ;;
        open)
            logger 'LID opened'
            ;;
        *)
            logger "ACPI action undefined: $3"
            ;;

to

button/lid)
    case "$3" in
        close)
            logger 'LID closed'
            XAUTHORITY=/home/USERNAME/.Xauthority DISPLAY=:0 xset dpms force off
            ;;
        open)
            logger 'LID opened'
            XAUTHORITY=/home/USERNAME/.Xauthority DISPLAY=:0 xset dpms force on
            ;;
        *)
            logger "ACPI action undefined: $3"
            ;;

(For extensive use of acpid it is certainly adviced to create a separate rule/file for this task.)

Explanation

xset dpms force off implicitly turns off the screen $DISPLAY (otherwise xset -d $DISPLAY dpms force off). To do that it needs the cookie (authorization file) of the person that started X located at $XAUTHORITY.

In case X was started by root during the login process (what is the standard case), a simgple xset dpms force off might be sufficient.

I start X within the ~/.shellrc config of my login shell. I hence have to manually give it the display and cookie of me.


Addendum

One can fiddle tweak that even further to not use the command when on AC (xset turns off all attached screens and udev does not detect the lid switch on my system).

        close)
            logger 'LID closed'
            if [[ $(cat /sys/class/power_supply/AC/online) == 0 ]];then
                XAUTHORITY=/home/USERNAME/.Xauthority DISPLAY=:0 xset dpms force off
            fi
            ;;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.