Skip to content

Instantly share code, notes, and snippets.

@cig0
Forked from kanru/i3lock-wait-for-suspend
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cig0/121eb3ee877bdbd3ecb4 to your computer and use it in GitHub Desktop.
Save cig0/121eb3ee877bdbd3ecb4 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -x
DBUS_NAME="org.freedesktop.login1"
DBUS_PATH="/org/freedesktop/login1"
DBUS_INTERFACE="org.freedesktop.login1.Manager"
DBUS_SIGNAL="PrepareForSleep"
INHIBITOR_PID=
install_background_inhibitor() {
tail -f /dev/null &
INHIBITOR_PID=$!
wait $INHIBITOR_PID &&
echo done |
systemd-inhibit --what sleep --mode delay \
--who $0 --why "i3lock before suspend" \
read &
}
kill_background_inhibitor() {
kill $INHIBITOR_PID
}
gdbus monitor --system \
--dest $DBUS_NAME \
--object-path $DBUS_PATH |
(install_background_inhibitor;
trap kill_background_inhibitor INT TERM;
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