Tuesday, September 7, 2010

Suspend on Lid Close with LXDE

LXDE has been great on my Asus EEE 1001P. It's fast and usable. I've had some issues with it, but the most frustrating problem is that Fedora 12 with LXDE doesn't suspend by default when you close the lid. I did some googling and discovered this is known and the easy to fix it is to install the gnome-power-manager. But that kind of defeats the point of LXDE, right? I'm trying to avoid installing and using gnome heaviness to stay lean and mean and fast.

So, after lots of googling around, I finally came up with the optimum configuration which uses what I hope are lighter-weight services.

First, I had to install acpid to respond to lid close/open events (my code is based on this post):
yum install acpid


I hunted through the LXDE source code and discovered that lxde-logout uses a dbus call to HAL to trigger the suspend. I found a great blog post describing how to do this from a script. I implemented that by doing creating the following files:

/etc/acpi/events/lid (update: don't put a dot in the filename for Fedora 14+, it seems a new version of acpid ignores all files with dots in their names)

event=button/lid
action=/etc/acpi/actions/lid.sh


/etc/acpi/actions/lid.sh

#!/bin/bash

# maybe this sleep isn't needed, but just to make sure the lid close event doesn't trigger immediate wake-up
sleep 2

# make sure the lid is closed
grep -q open /proc/acpi/button/lid/LID/state && exit 0

# suspend
dbus-send --system --dest=org.freedesktop.Hal --type=method_call --print-reply /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0

5 comments:

Bjarni said...

Hi,

The "dbus-send..." command did not work for me, but a simple "pm-suspend" did!

Thanks for the tip,

-Bjarni

Fityk said...

for me pm-suspend didn't work, I don't know why, but systemctl suspend worked (on Fedora 17).

Steven Tierney said...

In Linux Mint 14 (nadia) this worked:

cd /etc/acpi
sudo vi lid.sh

add pm-suspend as follows:

if [ x"$XAUTHORITY" != x"" ]; then
export DISPLAY=":$displaynum"
. /usr/share/acpi-support/screenblank
# Allow suspend in lxde when lid is closed
pm-suspend
fi

Humbert said...

I've solve it uncommenting variable LID_SLEEP=true from /etc/default/acpi-support , then service acpid restart

Humbert said...
This comment has been removed by the author.