vincentbernat.i3wm-configur.../bin/xss-lock

44 lines
1.5 KiB
Text
Raw Normal View History

#!/bin/bash
me="$(readlink -f "$0")"
timeout=240
2014-09-12 21:23:15 +02:00
notify=10
case "$1" in
start)
xset s $(($timeout - $notify)) $notify
xset dpms $(($timeout * 2)) $(($timeout * 3)) $(($timeout * 4))
exec xss-lock -n "$me notify" -l $me lock
;;
dim|notify)
echo "$(date --rfc-3339=seconds) $me: notify: start"
trap 'exit 0' TERM INT
trap "kill %% ; wait" EXIT
notify-send "Lock screen" -t $(($notify * 1000)) \
"Screen will be locked in 10 seconds..."
echo "$(date --rfc-3339=seconds) $me: notify: end"
sleep 2147483647 &
wait
;;
lock)
2014-12-11 08:32:21 +01:00
# First, stop Spotify
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause
# Then, lock screen
i3lock_options="-e -i $HOME/.cache/awesome/current-wallpaper.png -t"
2014-09-14 11:03:45 +02:00
echo "$(date --rfc-3339=seconds) $me: lock: lock screen"
if [ -e /proc/self/fd/${XSS_SLEEP_LOCK_FD:--1} ]; then
trap 'kill %%' TERM INT
i3lock -n $i3lock_options {XSS_SLEEP_LOCK_FD}<&- &
sleep 0.3 # Slight race condition, better than an active loop
exec {XSS_SLEEP_LOCK_FD}<&-
wait
else
trap 'kill %%' TERM INT
i3lock -n $i3lock_options &
wait
fi
2014-09-14 11:03:45 +02:00
echo "$(date --rfc-3339=seconds) $me: lock: unlock screen"
;;
esac