3

The awesome WM doesn't suspend automatically when closing the lid, so I followed some instructions to get it working. I simply added a file /etc/acpi/local/lid.sh.post with the following contents:

#!/bin/sh
pm-suspend

Suspending works now, but after I open the lid and press the power button it shows the desktop for a fraction of a second before suspending again! The second time I press the power button it resumes properly. After that, any time I suspend I have to press the power button and wait three times before it resumes properly. I've tried suspending four times in a row, and it doesn't seem to get any worse.

Edit: I'm using a simple screen lock service instead of the original script:

[Unit]
Description=Lock X session
Before=sleep.target

[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xautolock -locknow

[Install]
WantedBy=sleep.target

It's not a perfect solution, though.

Solved! If anybody else wants it, I made a script to do this in one command:

#!/usr/bin/env bash
#
# NAME
#        suspend-on-close.sh - Enable suspend when closing laptop lid
#
# SYNOPSIS
#        suspend-on-close.sh [options]
#
# DESCRIPTION
#        Adds a new "post" event to the ACPI lid close handler
#
# BUGS
#        https://github.com/l0b0/tilde/issues
#
# COPYRIGHT
#        Copyright © 2013-2014 Victor Engmark. License GPLv3+: GNU GPL
#        version 3 or later <http://gnu.org/licenses/gpl.html>.
#        This is free software: you are free to change and redistribute it.
#        There is NO WARRANTY, to the extent permitted by law.
#
################################################################################

set -o errexit -o noclobber -o nounset -o pipefail

directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PATH='/usr/bin:/bin'

target_dir="/etc/acpi/local"
target_file="${target_dir}/lid.sh.post"

if [[ ! -d "$target_dir" ]]
then
    mkdir "$target_dir"
fi

> "$target_file" cat <<EOF
#!/bin/sh
grep -q closed /proc/acpi/button/lid/*/state && pm-suspend
EOF

chmod u+x "$target_file"
l0b0
  • 51,350

2 Answers2

5

I'm pretty sure that your lid callback is going to be called every time the lid is closed as well as opened.

The sleep.sh file here states:

# if launched through a lid event and lid is open, do nothing
echo "$1" | grep "button/lid" && grep -q open /proc/acpi/button/lid/LID/state && exit 0

the "lid open" scenario is one your script is not checking for...

You could quickly test this by echoing some parameters to a log file

2

I'm running Awesome WM with Ubuntu 14.04 on a Dell Inspiron 11z and was getting a similar sleep/suspend problem.

Once I confirmed s2ram -f and s2disk worked, I updated /usr/lib/pm-utils/sleep.d/00powersave to read /usr/sbin/s2ram -f, and it suspended on close, but it suspended again after opening.

Following your lead, I added the following to 00powersave

echo "$1" >> /home/user/lid.log
cat /proc/acpi/button/lid/LID0/state >> /home/user/lid.log

After closing and opening the laptop, the output was:

suspend
state:      closed
resume
state:      open

Based on those states I made my 00powersave file the following:

echo "$1" | grep "resume" && grep -q open /proc/acpi/button/lid/LID0/state && exit 0
/usr/sbin/s2ram -f

Which checked if the script was being called by "resume" and if the lid was open, and did nothing if those two conditions were met.

Thanks guys! Sorry if this is bad etiquette but this was a pain to solve, and I wanted to post this so the next person would have an easier time.

0Troy
  • 21