Tuesday, February 06, 2007
ACPI configuration - Lid event
I decide to play a little bit with the ACPI configuration. For now, each time I close the lip of my laptop, the system automatically lock the screen.
Now that the suspend is working since I update my kernel to 2.6.20, I want to customize the lip action a little bit. I want to check if the system is on the AC adapter, if it's, locking the screen is the good action. But if the system is running on the battery, I want it to turn on the standby mode when the lid is close.
First, the ACPI scripts are located in the /etc/acpi directory, and the configuration file for the lid event is /etc/acpi/lid.sh
To check the state of the AC adapter, we can do it with the following : cat /proc/acpi/ac_adapter/ACAD/state
If the AC adapter is present:
state: on-line
If we run on the battery:
state: off-line
To turn on the stanby mode, we can do it with the following command:
echo -n mem > /sys/power/state
To turn on the hibernate mode, we can do it with the following
echo -n disk > /sys/power/state
So based on that, this is my change:
diff -u lid.sh_distro lid.sh
--- lid.sh_distro 2007-02-06 14:21:31.000000000 -0500
+++ lid.sh 2007-02-06 14:34:21.000000000 -0500
@@ -11,14 +11,20 @@
grep -q closed /proc/acpi/button/lid/*/state
if [ $? = 0 ]
then
- for x in /tmp/.X11-unix/*; do
- displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
- getXuser;
- if [ x"$XAUTHORITY" != x"" ]; then
- export DISPLAY=":$displaynum"
- . /usr/share/acpi-support/screenblank
+ if grep -q "off-line" /proc/acpi/ac_adapter/ACAD/state; then
+ #Here we are on the battery, so we goes in sleep mode
+ echo -n mem > /sys/power/state
+ else
+ #Here we are on the AC adapter
+ for x in /tmp/.X11-unix/*; do
+ displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
+ getXuser;
+ if [ x"$XAUTHORITY" != x"" ]; then
+ export DISPLAY=":$displaynum"
+ . /usr/share/acpi-support/screenblank
+ fi
+ done
fi
- done
else
for x in /tmp/.X11-unix/*; do
displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
Now that the suspend is working since I update my kernel to 2.6.20, I want to customize the lip action a little bit. I want to check if the system is on the AC adapter, if it's, locking the screen is the good action. But if the system is running on the battery, I want it to turn on the standby mode when the lid is close.
First, the ACPI scripts are located in the /etc/acpi directory, and the configuration file for the lid event is /etc/acpi/lid.sh
To check the state of the AC adapter, we can do it with the following : cat /proc/acpi/ac_adapter/ACAD/state
If the AC adapter is present:
state: on-line
If we run on the battery:
state: off-line
To turn on the stanby mode, we can do it with the following command:
echo -n mem > /sys/power/state
To turn on the hibernate mode, we can do it with the following
echo -n disk > /sys/power/state
So based on that, this is my change:
diff -u lid.sh_distro lid.sh
--- lid.sh_distro 2007-02-06 14:21:31.000000000 -0500
+++ lid.sh 2007-02-06 14:34:21.000000000 -0500
@@ -11,14 +11,20 @@
grep -q closed /proc/acpi/button/lid/*/state
if [ $? = 0 ]
then
- for x in /tmp/.X11-unix/*; do
- displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
- getXuser;
- if [ x"$XAUTHORITY" != x"" ]; then
- export DISPLAY=":$displaynum"
- . /usr/share/acpi-support/screenblank
+ if grep -q "off-line" /proc/acpi/ac_adapter/ACAD/state; then
+ #Here we are on the battery, so we goes in sleep mode
+ echo -n mem > /sys/power/state
+ else
+ #Here we are on the AC adapter
+ for x in /tmp/.X11-unix/*; do
+ displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
+ getXuser;
+ if [ x"$XAUTHORITY" != x"" ]; then
+ export DISPLAY=":$displaynum"
+ . /usr/share/acpi-support/screenblank
+ fi
+ done
fi
- done
else
for x in /tmp/.X11-unix/*; do
displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
Subscribe to Posts [Atom]