Just some configs for backup and evaluation

lockscreen.sh 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env bash
  2. # Author: Dolores Portalatin <hello@doloresportalatin.info>
  3. # Dependencies: imagemagick, i3lock-color-git, scrot, wmctrl (optional)
  4. set -o errexit -o noclobber -o nounset
  5. # get path where the script is located to find the lock icon
  6. scriptpath=$(readlink -f -- "$0")
  7. scriptpath=${scriptpath%/*}
  8. hue=(-level "0%,100%,0.6")
  9. effect=(-filter Gaussian -resize 20% -define "filter:sigma=1.5" -resize 500.5%)
  10. # default system sans-serif font
  11. font=$(convert -list font | awk "{ a[NR] = \$2 } /family: $(fc-match sans -f "%{family}\n")/ { print a[NR-1]; exit }")
  12. image=$(mktemp --suffix=.png)
  13. shot=(import -window root)
  14. desktop=""
  15. i3lock_cmd=(i3lock -i "$image")
  16. shot_custom=false
  17. options="Options:
  18. -h, --help This help menu.
  19. -d, --desktop Attempt to minimize all windows before locking.
  20. -g, --greyscale Set background to greyscale instead of color.
  21. -p, --pixelate Pixelate the background instead of blur, runs faster.
  22. -f <fontname>, --font <fontname> Set a custom font.
  23. -t <text>, --text <text> Set a custom text prompt.
  24. -l, --listfonts Display a list of possible fonts for use with -f/--font.
  25. Note: this option will not lock the screen, it displays
  26. the list and exits immediately.
  27. -n, --nofork Do not fork i3lock after starting.
  28. -- Must be last option. Set command to use for taking a
  29. screenshot. Default is 'import -window root'. Using 'scrot'
  30. or 'maim' will increase script speed and allow setting
  31. custom flags like having a delay."
  32. # move pipefail down as for some reason "convert -list font" returns 1
  33. set -o pipefail
  34. trap 'rm -f "$image"' EXIT
  35. temp="$(getopt -o :hdnpglt:f: -l desktop,help,listfonts,nofork,pixelate,greyscale,text:,font: --name "$0" -- "$@")"
  36. eval set -- "$temp"
  37. # l10n support
  38. text="Type password to unlock"
  39. case "${LANG:-}" in
  40. de_* ) text="Bitte Passwort eingeben" ;; # Deutsch
  41. da_* ) text="Indtast adgangskode" ;; # Danish
  42. en_* ) text="Type password to unlock" ;; # English
  43. es_* ) text="Ingrese su contraseña" ;; # Española
  44. fr_* ) text="Entrez votre mot de passe" ;; # Français
  45. id_* ) text="Masukkan kata sandi Anda" ;; # Bahasa Indonesia
  46. it_* ) text="Inserisci la password" ;; # Italian
  47. lv_* ) text="Ievadi paroli" ;; # Latvian
  48. pl_* ) text="Podaj hasło" ;; # Polish
  49. pt_* ) text="Digite a senha para desbloquear" ;; # Português
  50. ru_* ) text="Введите пароль" ;; # Russian
  51. * ) text="Type password to unlock" ;; # Default to English
  52. esac
  53. while true ; do
  54. case "$1" in
  55. -h|--help)
  56. printf "Usage: %s [options]\n\n%s\n\n" "${0##*/}" "$options"; exit 1 ;;
  57. -d|--desktop) desktop=$(command -V wmctrl) ; shift ;;
  58. -g|--greyscale) hue=(-level "0%,100%,0.6" -set colorspace Gray -separate -average) ; shift ;;
  59. -p|--pixelate) effect=(-scale 10% -scale 1000%) ; shift ;;
  60. -f|--font)
  61. case "$2" in
  62. "") shift 2 ;;
  63. *) font=$2 ; shift 2 ;;
  64. esac ;;
  65. -t|--text) text=$2 ; shift 2 ;;
  66. -l|--listfonts)
  67. convert -list font | awk -F: '/Font: / { print $2 }' | sort -du | command -- ${PAGER:-less}
  68. exit 0 ;;
  69. -n|--nofork) i3lock_cmd+=(--nofork) ; shift ;;
  70. --) shift; shot_custom=true; break ;;
  71. *) echo "error" ; exit 1 ;;
  72. esac
  73. done
  74. if "$shot_custom" && [[ $# -gt 0 ]]; then
  75. shot=("$@");
  76. fi
  77. command -- "${shot[@]}" "$image"
  78. value="60" #brightness value to compare to
  79. color=$(convert "$image" -gravity center -crop 100x100+0+0 +repage -colorspace hsb \
  80. -resize 1x1 txt:- | awk -F '[%$]' 'NR==2{gsub(",",""); printf "%.0f\n", $(NF-1)}');
  81. if [[ $color -gt $value ]]; then #white background image and black text
  82. bw="black"
  83. icon="$scriptpath/icons/lockdark.png"
  84. param=("--textcolor=00000000" "--insidecolor=0000001c" "--ringcolor=0000003e" \
  85. "--linecolor=00000000" "--keyhlcolor=ffffff80" "--ringvercolor=ffffff00" \
  86. "--separatorcolor=22222260" "--insidevercolor=ffffff1c" \
  87. "--ringwrongcolor=ffffff55" "--insidewrongcolor=ffffff1c")
  88. else #black
  89. bw="white"
  90. icon="$scriptpath/icons/lock.png"
  91. param=("--textcolor=ffffff00" "--insidecolor=ffffff1c" "--ringcolor=ffffff3e" \
  92. "--linecolor=ffffff00" "--keyhlcolor=00000080" "--ringvercolor=00000000" \
  93. "--separatorcolor=22222260" "--insidevercolor=0000001c" \
  94. "--ringwrongcolor=00000055" "--insidewrongcolor=0000001c")
  95. fi
  96. convert "$image" "${hue[@]}" "${effect[@]}" -font "$font" -pointsize 26 -fill "$bw" -gravity center \
  97. -annotate +0+160 "$text" "$icon" -gravity center -composite "$image"
  98. # If invoked with -d/--desktop, we'll attempt to minimize all windows (ie. show
  99. # the desktop) before locking.
  100. ${desktop} ${desktop:+-k on}
  101. # try to use i3lock with prepared parameters
  102. if ! "${i3lock_cmd[@]}" "${param[@]}" >/dev/null 2>&1; then
  103. # We have failed, lets get back to stock one
  104. "${i3lock_cmd[@]}"
  105. fi
  106. # As above, if we were passed -d/--desktop, we'll attempt to restore all windows
  107. # after unlocking.
  108. ${desktop} ${desktop:+-k off}