vincentbernat.i3wm-configur.../bin/xss-lock
Vincent Bernat ae691bb025 systemd: tentative to manage session with systemd
To me, I think it was cleaner to have a parameter with the current
display. This way, the session is specific to the current display. It
seems BindsTo doesn't think this way.
2020-01-19 19:06:49 +01:00

50 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
me="$(readlink -f "$0")"
timeout=300
notify=10
configure() {
xset s $((timeout - notify)) $notify
xset dpms $((timeout * 3)) $((timeout * 4)) $((timeout * 5))
}
unconfigure() {
xset s 0
xset dpms 0 0 0
}
case "$1" in
start)
configure
exec xss-lock -n "$me notify" -l $me lock
;;
dim|notify)
echo "$(date --rfc-3339=seconds) $me: notify: start"
pkill -STOP redshift
trap 'pkill -CONT redshift' EXIT
trap 'kill %%; exit 0' HUP
trap 'sleep 1s; kill %%; exit 0' TERM
outputs=$(xrandr -q | sed -n 's/\([^ ]*\) connected .*/\1/p')
for i in $(seq 0.7 -0.01 0.1); do
for out in $outputs; do
xrandr --output $out --brightness $i
done
sleep 0.02
done
echo "$(date --rfc-3339=seconds) $me: notify: end"
sleep infinity &
wait
;;
lock)
# Something may have mendled with screensaver settings
configure
# First, stop any music player
xdotool key XF86AudioStop
# Then, lock screen
echo "$(date --rfc-3339=seconds) $me: lock: lock screen"
systemctl --user stop compton@$(systemd-escape -- "$DISPLAY").service
i3lock -n -e -i $HOME/.cache/awesome/current-wallpaper.png -t -f
systemctl --user start compton@$(systemd-escape -- "$DISPLAY").service
echo "$(date --rfc-3339=seconds) $me: lock: unlock screen"
;;
esac