Skip to content

Instantly share code, notes, and snippets.

@olvaffe
Created May 30, 2014 17:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save olvaffe/06af825f69bd058e0116 to your computer and use it in GitHub Desktop.
Save olvaffe/06af825f69bd058e0116 to your computer and use it in GitHub Desktop.
i3lock-wait-for-suspend
#!/bin/sh
DBUS_NAME="org.freedesktop.login1"
DBUS_PATH="/org/freedesktop/login1"
DBUS_INTERFACE="org.freedesktop.login1.Manager"
DBUS_SIGNAL="PrepareForSleep"
INHIBITOR_PIDS=
install_background_inhibitor() {
systemd-inhibit --what sleep --mode delay \
--who $0 --why "i3lock before suspend" \
tail -f /dev/null &
# There should be a better way...
pid=$!
pgid=`ps x -o "%r %p" | grep "$pid$" | cut -d' ' -f2`
tail_pid=`ps x -o "%p %r %c" | grep "$pgid.*tail$" | cut -d' ' -f2`
INHIBITOR_PIDS="$pid $tail_pid"
}
kill_background_inhibitor() {
kill $INHIBITOR_PIDS
}
trap kill_background_inhibitor INT TERM
install_background_inhibitor
gdbus monitor --system \
--dest $DBUS_NAME \
--object-path $DBUS_PATH | while read line; do
if echo "$line" | grep -q "$DBUS_INTERFACE.$DBUS_SIGNAL"; then
if echo "$line" | grep -q true; then
i3lock
kill_background_inhibitor
else
install_background_inhibitor
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment