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} from .xsession (or anywhere else your WM allows you to do it in):

umask 0077
    echo "export ${acpivar}='${!acpivar}'"
done > /tmp/${USER}
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} ] && . /tmp/${USER}
case "${state}" in
    /usr/bin/xset dpms force on
    /usr/bin/xset dpms force off
    echo "Unknown lid state '${state}' - unsure of what to do"

I seriously doubt you can get much simpler than that.

Leave a Reply

This blog is kept spam free by WP-SpamFree.