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"
|
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
|
2022-12-16 19:36:39 +01:00
|
|
|
playerctl -p spotify pause
|
2020-12-20 21:48:19 +01:00
|
|
|
|
2024-04-14 02:11:58 +02:00
|
|
|
i3lock --nofork --show-failed-attempts --ignore-empty-password \
|
|
|
|
|
--color "000000"
|
2013-09-14 14:35:23 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 21:08:13 +01:00
|
|
|
screen_off() {
|
|
|
|
|
xset dpms force off
|
|
|
|
|
}
|
2013-09-15 21:05:30 +02:00
|
|
|
|
2017-08-09 22:05:06 +02:00
|
|
|
reset_screen() {
|
2020-12-20 21:48:19 +01:00
|
|
|
systemctl --user restart dpms.service
|
2017-08-09 22:05:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock_and_screen_off() {
|
|
|
|
|
lock &
|
|
|
|
|
_pid=$!
|
2022-05-02 20:41:57 +02:00
|
|
|
dunst_paused=$(dunstctl is-paused)
|
|
|
|
|
[[ "${dunst_paused}" != "true" ]] && dunstctl set-paused true
|
2017-08-09 22:05:06 +02:00
|
|
|
screen_off
|
|
|
|
|
wait $_pid
|
2022-05-02 20:41:57 +02:00
|
|
|
[[ "${dunst_paused}" != "true" ]] && dunstctl set-paused false
|
2017-08-09 22:05:06 +02:00
|
|
|
reset_screen
|
|
|
|
|
}
|
|
|
|
|
|
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 &
|
|
|
|
|
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."
|
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
|