]> git.donarmstrong.com Git - bin.git/blob - locker
add reset usb bus command
[bin.git] / locker
1 #!/bin/bash
2
3 # Example locker script -- demonstrates how to use the --transfer-sleep-lock
4 # option with i3lock's forking mode to delay sleep until the screen is locked.
5
6 ## CONFIGURATION ##############################################################
7
8 # Options to pass to i3lock
9 i3lock_options="-c 000000"
10
11 # Run before starting the locker
12 pre_lock() {
13     #mpc pause
14     return
15 }
16
17 # Run after the locker exits
18 post_lock() {
19     return
20 }
21
22 ###############################################################################
23
24 pre_lock
25
26 # We set a trap to kill the locker if we get killed, then start the locker and
27 # wait for it to exit. The waiting is not that straightforward when the locker
28 # forks, so we use this polling only if we have a sleep lock to deal with.
29 if [[ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]]; then
30     kill_i3lock() {
31         pkill -xu $EUID "$@" i3lock
32     }
33
34     trap kill_i3lock TERM INT
35
36     # we have to make sure the locker does not inherit a copy of the lock fd
37     i3lock $i3lock_options {XSS_SLEEP_LOCK_FD}<&-
38
39     # now close our fd (only remaining copy) to indicate we're ready to sleep
40     exec {XSS_SLEEP_LOCK_FD}<&-
41
42     while kill_i3lock -0; do
43         sleep 0.5
44     done
45 else
46     trap 'kill %%' TERM INT
47     i3lock -n $i3lock_options &
48     wait
49 fi
50
51 post_lock