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"