97 lines
2.1 KiB
Bash
Executable File
97 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
### From http://www.archlinux.org/index.php/i3
|
|
|
|
_logfile="$LOGDIR/i3/i3exit.log"
|
|
LOCKSCREEN="$LIBDIR/wallpaper/lockscreen"
|
|
|
|
_fallback_color="000000"
|
|
|
|
touch "$_logfile"
|
|
|
|
log()
|
|
{
|
|
echo "$*"
|
|
echo "[$(date +%FT%T)] $*" >> "$_logfile"
|
|
}
|
|
|
|
lock()
|
|
{
|
|
set -x
|
|
playing=0
|
|
if dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|grep -q Playing ; then
|
|
playing=1
|
|
fi
|
|
echo $playing
|
|
(( $playing )) && dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause
|
|
if [[ -f "$LOCKSCREEN" ]] ; then
|
|
i3lock --nofork --show-failed-attempts --ignore-empty-password \
|
|
--image "$LOCKSCREEN"
|
|
else
|
|
i3lock --nofork --show-failed-attempts --ignore-empty-password \
|
|
--color "$_fallback_color"
|
|
fi
|
|
(( $playing )) && dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play
|
|
}
|
|
|
|
screen_off() {
|
|
:
|
|
xset dpms force off
|
|
}
|
|
|
|
reset_screen() {
|
|
xset -dpms
|
|
xset s off
|
|
}
|
|
|
|
lock_and_screen_off() {
|
|
lock &
|
|
_pid=$!
|
|
screen_off
|
|
wait $_pid
|
|
reset_screen
|
|
}
|
|
|
|
signal="$1"
|
|
log "[I] Received signal \"$signal\"."
|
|
|
|
case "$signal" in
|
|
lock)
|
|
log "[I] Locking session."
|
|
lock_and_screen_off
|
|
;;
|
|
logout)
|
|
log "[I] Exiting i3."
|
|
i3-msg exit
|
|
;;
|
|
suspend)
|
|
log "[I] Suspending."
|
|
lock &
|
|
sleep 0.1
|
|
systemctl suspend
|
|
;;
|
|
hibernate)
|
|
log "[I] Hibernating."
|
|
systemctl hibernate
|
|
;;
|
|
reboot)
|
|
log "[I] Rebooting."
|
|
systemctl reboot
|
|
;;
|
|
shutdown)
|
|
log "[I] Shutting down."
|
|
systemctl poweroff
|
|
;;
|
|
screen-off)
|
|
log "[I] Turning screen off."
|
|
screen_off
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
|
|
log "[E] Signal \"$signal\" unknown. Aborting."
|
|
exit 2
|
|
esac
|
|
|
|
log "[I] Done."
|
|
exit 0
|