The LID and the LCD backlight

So I noticed that what I close the lid on my laptop the backlight doesn’t switch off. This is pretty bad for obvious reasons, primarily that it’s a waste of power, and secondly that even though not much it does radiate some heat and in a confined space it does escalate (and not mention that it’s an easy way to save a few watts of power when running on battery and waiting for some task to finish). So something had to be done.

Once more I assume that you already have non-root user ACPI hack in place. Note that I’ve updated this hack just now in order to convert events like button/lid (the one we’re after) to button_lid.

I then googled a little and found that I can switch the backlight on and off with xset (assuming X is running and a user is logged in). So re-using a small component from my acpi battery state notifications, namely the little snippet that generates a /tmp/${USER}-acpi-vars.sh from .xsession (or anywhere else your WM allows you to do it in):

oumask=$(umask)
umask 0077
for acpivar in DISPLAY XAUTHORITY DBUS_SESSION_BUS_ADDRESS; do
    echo "export ${acpivar}='${!acpivar}'"
done > /tmp/${USER}-acpi-vars.sh
umask "${oumask}"

I then cooked up a button_lid script that can be placed in ${HOME}/.acpi that’ll switch off the backlight when the lid closes, and back on when it opens (to save you from having to move the mouse of pressing a key to achieve this):

#! /bin/bash

state=$(/usr/bin/awk '$1=="state:" { print $2 }' < /proc/acpi/button/lid/LID/state)

[ -r /tmp/${USER}-acpi-vars.sh ] && . /tmp/${USER}-acpi-vars.sh

case "${state}" in
  open)
    /usr/bin/xset dpms force on
    ;;
  closed)
    /usr/bin/xset dpms force off
    ;;
  *)
    echo "Unknown lid state '${state}' - unsure of what to do"
    ;;
esac

I seriously doubt you can get much simpler than that.

Comments are closed.