The lid switch makes the laptop’s screen turn off when the lid is closed and turns it back on when the lid opens. This already worked well in Ubuntu but I needed to tweak the behavior a bit. Sometimes I use a projector as the main display and turn off the laptop’s screen to save some battery, however, Ubuntu turns off ALL displays (including the analog output) when the panel lid is closed, which then leaves me with no screen at all!
How it Works
You can determine the state of the lid switch by doing:
$ cat /proc/acpi/button/lid/LID/state
In order to turn on/off the backlight of the LCD panel, you can use radeontool. This tool is part of the Ubuntu distribution so you can install it with Synaptic (if it is not already installed). After installing both, the laptop-mode-tools (also part of Ubuntu) and radeontool packages, I created the following script:
#!/bin/bash
LIGHT=$(radeontool light | grep "looks on")
if [ "$LIGHT" = "" ]; then
radeontool light on
else
radeontool light off
fi
This script toggles on/off the backlight of the LCD panel. You can then use xbindkeys to assign a keyboard shortcut and control the LCD backlight at will.
Tweaking the Lid Switch Behavior
In order to set and maintain the state of the backlight when the lid is closed, you can create a daemon and call it with laptop-mode-tools. This is specially handy if some of your applications (usually games) like to turn the panel backlight back on when resetting the video resolution or when going into full screen.
Step 1
Comment everything on /etc/acpi/lid.sh and add the following at the end of the script:
LID_CLOSED=$(cat /proc/acpi/button/lid/LID/state | grep open) if [ "$LID_CLOSED" = "" ]; then /usr/sbin/blightoffd & else /usr/sbin/radeontool light on fi
Step 2
Save the following script as /usr/sbin/blightoffd
#!/bin/bash
#
# Keeps panel backlight off when computer lid is closed.
#
LID_CLOSED=$(cat /proc/acpi/button/lid/LID/state | grep open)
while [ "$LID_CLOSED" = "" ]; do
LIGHT_ON=$(/usr/sbin/radeontool light | grep "looks off")
if [ "$LIGHT_ON" = "" ]; then
/usr/sbin/radeontool light off
fi
sleep 1
LID_CLOSED=$(cat /proc/acpi/button/lid/LID/state | grep open)
done
Step 3
Disable or uninstall both kpowersave and klaptop.
Making it all work with powersave
I installed powersaved which is great tool for enabling dynamic control of the CPU speed and save additional power. However, that bugger messed up the scripts controlling the lid switch events. Here is how to fix the problem:
Find the following line in /etc/powersave/events:
EVENT_BUTTON_LID_CLOSED="xxxxxxx"
and make sure it says:
EVENT_BUTTON_LID_CLOSED="ignore"
This will make powersave ignore lid switch events














0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.