Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

52 lines
1.3KB

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