You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.1 KiB
88 lines
2.1 KiB
#!/bin/bash |
|
|
|
# Defaults |
|
# Taken from https://github.com/guimeira/i3lock-fancy-multimonitor |
|
# |
|
# Modified to remove TEXT option & logic, |
|
# and use /home/<user>/.config/i3lock |
|
# dir for images. |
|
|
|
DISPLAY_RE="([0-9]+)x([0-9]+)\\+([0-9]+)\\+([0-9]+)" |
|
IMAGE_RE="([0-9]+)x([0-9]+)" |
|
FOLDER="/home/$(whoami)/.config/i3lock" |
|
LOCK="$FOLDER/lock.png" |
|
PARAMS="" |
|
OUTPUT_IMAGE="/tmp/i3lock.png" |
|
PIXELATE=true |
|
BLURTYPE="1x1" |
|
|
|
# Read user input |
|
POSITIONAL=() |
|
for i in "$@" |
|
do |
|
case $i in |
|
-h|--help) |
|
echo "lock: Syntax: lock [-n|--no-text] [-p|--pixelate] [-b=VAL|--blur=VAL]" |
|
echo "for correct blur values, read: http://www.imagemagick.org/Usage/blur/#blur_args" |
|
exit |
|
shift |
|
;; |
|
-b=*|--blur=*) |
|
VAL="${i#*=}" |
|
BLURTYPE=(${VAL//=/ }) |
|
shift |
|
;; |
|
-p|--pixelate) |
|
PIXELATE=false |
|
shift # past argument |
|
;; |
|
*) # unknown option |
|
echo "unknown option: $i" |
|
exit |
|
POSITIONAL+=("$1") # save it in an array for later |
|
shift # past argument |
|
;; |
|
esac |
|
done |
|
set -- "${POSITIONAL[@]}" # restore positional parameters |
|
|
|
#Take screenshot: |
|
scrot -z $OUTPUT_IMAGE |
|
|
|
#Get dimensions of the lock image: |
|
LOCK_IMAGE_INFO=`identify $LOCK` |
|
[[ $LOCK_IMAGE_INFO =~ $IMAGE_RE ]] |
|
IMAGE_WIDTH=${BASH_REMATCH[1]} |
|
IMAGE_HEIGHT=${BASH_REMATCH[2]} |
|
|
|
#Execute xrandr to get information about the monitors: |
|
while read LINE |
|
do |
|
#If we are reading the line that contains the position information: |
|
if [[ $LINE =~ $DISPLAY_RE ]]; then |
|
#Extract information and append some parameters to the ones that will be given to ImageMagick: |
|
WIDTH=${BASH_REMATCH[1]} |
|
HEIGHT=${BASH_REMATCH[2]} |
|
X=${BASH_REMATCH[3]} |
|
Y=${BASH_REMATCH[4]} |
|
POS_X=$(($X+$WIDTH/2-$IMAGE_WIDTH/2)) |
|
POS_Y=$(($Y+$HEIGHT/2-$IMAGE_HEIGHT/2)) |
|
|
|
PARAMS="$PARAMS '$LOCK' '-geometry' '+$POS_X+$POS_Y' '-composite'" |
|
fi |
|
done <<<"`xrandr`" |
|
|
|
#Execute ImageMagick: |
|
if $PIXELATE ; then |
|
PARAMS="'$OUTPUT_IMAGE' '-scale' '10%' '-scale' '1000%' $PARAMS '$OUTPUT_IMAGE'" |
|
else |
|
PARAMS="'$OUTPUT_IMAGE' '-level' '0%,100%,0.6' '-blur' '$BLURTYPE' $PARAMS '$OUTPUT_IMAGE'" |
|
fi |
|
|
|
eval convert $PARAMS |
|
|
|
#Lock the screen: |
|
i3lock -i $OUTPUT_IMAGE -t |
|
|
|
#Remove the generated image: |
|
rm $OUTPUT_IMAGE
|
|
|