Skip to content

Commit

Permalink
lock: add param_add array
Browse files Browse the repository at this point in the history
Only supports i3lock -n for now. Also move up scriptpath to error out as soon as there's a path issue (i.e., before running convert).
  • Loading branch information
AladW authored May 18, 2017
1 parent f2b2a01 commit da2b14a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
# Dependencies: imagemagick, i3lock-color-git, scrot, wmctrl (optional)
set -o errexit -o noclobber -o nounset

# get path where the script is located to find the lock icon
scriptpath=$(readlink -f -- "$0")
scriptpath=${scriptpath%/*}

hue=(-level "0%,100%,0.6")
effect=(-filter Gaussian -resize 20% -define "filter:sigma=1.5" -resize 500.5%)
# default system sans-serif font
font="$(convert -list font | awk "{ a[NR] = \$2 } /family: $(fc-match sans -f "%{family}\n")/ { print a[NR-1]; exit }")"
image="$(mktemp).png"
shot=(import -window root)
desktop=""
param_add=("")
shot_custom=false

options="Options:
Expand All @@ -29,6 +34,8 @@ options="Options:
Note: this option will not lock the screen, it displays
the list and exits immediately.
-n, --nofork Do not fork i3lock after starting.
-- Must be last option. Set command to use for taking a
screenshot. Default is 'import -window root'. Using 'scrot'
or 'maim' will increase script speed and allow setting
Expand All @@ -37,7 +44,7 @@ options="Options:
# move pipefail down as for some reason "convert -list font" returns 1
set -o pipefail
trap 'rm -f "$image"' EXIT
temp="$(getopt -o :hdpglt:f: -l desktop,help,listfonts,pixelate,greyscale,text:,font: --name "$0" -- "$@")"
temp="$(getopt -o :hdnpglt:f: -l desktop,help,listfonts,nofork,pixelate,greyscale,text:,font: --name "$0" -- "$@")"
eval set -- "$temp"

# l10n support
Expand Down Expand Up @@ -72,6 +79,7 @@ while true ; do
-l|--listfonts)
convert -list font | awk -F: '/Font: / { print $2 }' | sort -du | command -- ${PAGER:-less}
exit 0 ;;
-n|--nofork) param_add=(--nofork) ; shift ;;
--) shift; shot_custom=true; break ;;
*) echo "error" ; exit 1 ;;
esac
Expand All @@ -83,10 +91,6 @@ fi

command -- "${shot[@]}" "$image"

# get path where the script is located to find the lock icon
scriptpath=$(readlink -f -- "$0")
scriptpath=${scriptpath%/*}

value="60" #brightness value to compare to

color=$(convert "$image" -gravity center -crop 100x100+0+0 +repage -colorspace hsb \
Expand Down Expand Up @@ -116,9 +120,9 @@ convert "$image" "${hue[@]}" "${effect[@]}" -font "$font" -pointsize 26 -fill "$
${desktop} ${desktop:+-k on}

# try to use a forked version of i3lock with prepared parameters
if ! i3lock -n "${param[@]}" -i "$image" > /dev/null 2>&1; then
if ! i3lock "${param_add[@]}" "${param[@]}" -i "$image" > /dev/null 2>&1; then
# We have failed, lets get back to stock one
i3lock -n -i "$image"
i3lock "${param_add[@]}" -i "$image"
fi

# As above, if we were passed -d/--desktop, we'll attempt to restore all windows
Expand Down

0 comments on commit da2b14a

Please sign in to comment.