-
-
Save cig0/121eb3ee877bdbd3ecb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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