Wednesday, October 31, 2007

Gutsy laptop lid tweak

I had a naggling little issue with gutsy on my laptop lid where when I closed the lid with it plugged in, the screen would turn off for a second, and then turn back on (I don't have the problem when not plugged in because I have it set to suspend when closed on battery power, which works beautifully). Thanks to the tweakfulness of linux, I was able to fix it in the following manner:

I created a file /etc/acpi/lidscreenblank.sh containing the following code:
#!/bin/bash

. /etc/default/acpi-support
. /usr/share/acpi-support/power-funcs

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
fi
done
fi

then I made that file executable.
edited /etc/acpi/events/lidbtn

and changed
action=/etc/acpi/lid.sh

to
action=/etc/acpi/lidscreenblank.sh


then restarted acpi: sudo /etc/init.d/acpid restart

and voila! it works. I know its missing some of the screensaver handling that lid.sh was doing, but I dont really use screensavers anyways, so i guess i dont cante about that.

No comments: