2013-09-14 14:35:23 +02:00
#!/bin/bash
### From http://www.archlinux.org/index.php/i3
2016-02-24 21:08:13 +01:00
_logfile="$LOGDIR/i3/i3exit.log"
2017-08-09 22:05:06 +02:00
LOCKSCREEN="$LIBDIR/wallpaper/lockscreen"
2013-09-15 21:05:30 +02:00
2017-09-09 14:12:38 +02:00
_fallback_color="000000"
2013-09-15 22:14:43 +02:00
2016-02-24 21:08:13 +01:00
touch "$_logfile"
2013-09-15 21:05:30 +02:00
log()
{
2016-02-24 21:08:13 +01:00
echo "$*"
echo "[$(date +%FT%T)] $*" >> "$_logfile"
2013-09-15 21:05:30 +02:00
}
lock()
{
2017-09-01 09:53:09 +02:00
set -x
playing=0
2019-07-04 14:34:52 +02:00
# 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
2017-08-09 22:05:06 +02:00
if [[ -f "$LOCKSCREEN" ]] ; then
i3lock --nofork --show-failed-attempts --ignore-empty-password \
2018-02-05 20:07:59 +01:00
--image "$LOCKSCREEN"
2013-09-15 22:14:43 +02:00
else
2017-08-09 22:05:06 +02:00
i3lock --nofork --show-failed-attempts --ignore-empty-password \
2018-02-05 20:07:59 +01:00
--color "$_fallback_color"
2013-09-15 22:14:43 +02:00
fi
2019-07-04 14:34:52 +02:00
# (( $playing )) && dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play
2013-09-14 14:35:23 +02:00
}
2016-02-24 21:08:13 +01:00
screen_off() {
2017-09-01 09:53:09 +02:00
:
2016-02-24 21:08:13 +01:00
xset dpms force off
}
2013-09-15 21:05:30 +02:00
2017-08-09 22:05:06 +02:00
reset_screen() {
xset -dpms
xset s off
}
lock_and_screen_off() {
lock &
_pid=$!
screen_off
2019-05-20 21:29:00 +02:00
xset dpms 0 0 5
2017-08-09 22:05:06 +02:00
wait $_pid
reset_screen
}
2018-08-21 22:02:02 +02:00
disable_lid_switch() {
grep "^${ACPI_LID_NAME}.*enabled" /proc/acpi/wakeup && echo " ${ACPI_LID_NAME}" | sudo tee /proc/acpi/wakeup
}
2016-02-24 21:08:13 +01:00
signal="$1"
2014-08-17 23:34:02 +02:00
log "[I] Received signal \"$signal\"."
case "$signal" in
2013-09-14 14:35:23 +02:00
lock)
2013-09-15 21:05:30 +02:00
log "[I] Locking session."
2017-08-09 22:05:06 +02:00
lock_and_screen_off
2013-09-14 14:35:23 +02:00
;;
logout)
2013-09-15 21:05:30 +02:00
log "[I] Exiting i3."
2013-09-14 14:35:23 +02:00
i3-msg exit
;;
suspend)
2013-09-15 21:05:30 +02:00
log "[I] Suspending."
2018-02-05 20:07:59 +01:00
lock &
2018-08-21 22:02:02 +02:00
disable_lid_switch
2018-02-05 20:07:59 +01:00
sleep 0.1
2017-08-09 22:05:06 +02:00
systemctl suspend
2013-09-14 14:35:23 +02:00
;;
hibernate)
2013-09-15 21:05:30 +02:00
log "[I] Hibernating."
2018-08-21 22:02:02 +02:00
disable_lid_switch
2019-07-04 14:34:58 +02:00
sudo systemctl hibernate
2013-09-14 14:35:23 +02:00
;;
reboot)
2013-09-15 21:05:30 +02:00
log "[I] Rebooting."
2013-09-14 14:35:23 +02:00
systemctl reboot
;;
shutdown)
2013-09-15 21:05:30 +02:00
log "[I] Shutting down."
2013-09-14 14:35:23 +02:00
systemctl poweroff
;;
2014-08-19 13:49:19 +02:00
screen-off)
log "[I] Turning screen off."
2017-09-12 19:36:50 +02:00
screen_off
2014-08-19 13:49:19 +02:00
;;
2013-09-14 14:35:23 +02:00
*)
echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
2014-08-17 23:34:02 +02:00
log "[E] Signal \"$signal\" unknown. Aborting."
2013-09-14 14:35:23 +02:00
exit 2
esac
2013-09-15 21:05:30 +02:00
log "[I] Done."
2013-09-14 14:35:23 +02:00
exit 0