How to configure acpid

From ThinkWiki
Revision as of 06:04, 14 May 2005 by 69.142.223.199 (Talk)
Jump to: navigation, search

With the introduction of ACPI there are more things under programmatic control. Sleeping is one of those things. To sleep the T30 manually is simple. You just do:

echo -n "mem" /sys/power/state

However there are two problems with this. It doesn't happen automatically when you close the lid and it does not turn off the LCD backlight. The acpid daemon is provided to solve the first problem. By adding an event handler you can run a script in response to both closing the lid and pressing Fn-F4 (suspend on the T30). You just need to create a file in /etc/acpi/events like the following:

$ cat /etc/acpi/events/sleep
event=button/(sleep|lid)
action=/etc/acpi/actions/sleep %e

The "event" line is a regular expression specifying the events we're interested in. I determined what the event strings are from looking at /var/log/acpid after trying to suspend, close the lid, etc. What I found was that when the Fn-F4 key sequence is selected a "button/sleep" event is dispatched. Closing and opening the lid both yield "button/lid" events. Note that if you add or modify one of these events files you must kill -SUGHUP <pidofacpid>.

The "action" line is the command to be executed when these events are dispatched. In this example I call a script and pass the event description text using the builtin %e macro. The /etc/acpi/actions/sleep script is as follows:

#!/bin/sh

if [ "$1" = "button/sleep" ] || \
        grep -q closed /proc/acpi/button/lid/${2}/state
then
    chvt 6;
    /usr/sbin/radeontool light off;
    echo -n "mem" > /sys/power/state;
    chvt 7;
fi

Translated this reads -- if the event is a sleep event (meaning Fn-F4 was triggered) or the state of the lid is closed, then switch to a virtual console, turn off the backlight, and goto sleep. When we wake up, switch back to X.

Note that the echo line does not return until we are revived. So there is only one event generated and there is no need to check the state of anything. This is unlike the lid which generates an event for both opening and closing thus requiring that we check it's state and only act if it's closed.

Unfortunately this will not work for a wide range of machines. For some machines it may be sufficient to turn off the backlight using 'xset dpms force off' (for this to even do anything for me with FC3 I had to use 'su miallen -c "xset -display :0 dpms force off"'). But for whatever reason, when the T30 starts to sleep, it switches to console mode which causes the backlight to come back on. So my solution above is to preemptively switch to console mode and turn off the backlight so that doesn't happen. However now, we cannot use xset because it's an X program that has no bearing on the console. Fortunately I happenstanced across radeontool which communicates directly with the T30 radeon mobility and therefore works from the console.

Altogether these two files and radeontool make sleeping the T30 when you close the lid or hit Fn-F4 work as expected.