-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi3lock-multimonitor
executable file
·56 lines (47 loc) · 2.07 KB
/
i3lock-multimonitor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#Constants
DISPLAY_RE="([0-9]+)x([0-9]+)\\+([0-9]+)\\+([0-9]+)" # Regex to find display dimensions
IMAGE_RE="([0-9]+)x([0-9]+)" # Regex to find image dimensions
FOLDER=`dirname "$BASH_SOURCE"` # Current folder
CACHE_FOLDER="$FOLDER"/img/cache/ # Cache folder
#Image paths
BKG_IMG="$FOLDER/img/background.png" # Path of background image
MD5_BKG_IMG=$(md5sum $BKG_IMG | cut -c 1-10)
MD5_SCREEN_CONFIG=$(xrandr | md5sum - | cut -c 1-32) # Hash of xrandr output
OUTPUT_IMG="$CACHE_FOLDER""$MD5_SCREEN_CONFIG"."$MD5_BKG_IMG".png # Path of final image
OUTPUT_IMG_WIDTH=0 # Decide size to cover all screens
OUTPUT_IMG_HEIGHT=0 # Decide size to cover all screens
if [ -e $OUTPUT_IMG ]
then
# Lock screen since image already exists
i3lock --image=$OUTPUT_IMG --tiling --show-failed-attempts
exit 0
fi
#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:
SCREEN_WIDTH=${BASH_REMATCH[1]}
SCREEN_HEIGHT=${BASH_REMATCH[2]}
SCREEN_X=${BASH_REMATCH[3]}
SCREEN_Y=${BASH_REMATCH[4]}
CACHE_IMG="$CACHE_FOLDER""$SCREEN_WIDTH"x"$SCREEN_HEIGHT"."$MD5_BKG_IMG".png
## if cache for that screensize doesnt exist
if ! [ -e $CACHE_IMG ]
then
eval convert '$BKG_IMG' '-resize' '${SCREEN_WIDTH}X${SCREEN_HEIGHT}!' \
'$CACHE_IMG'
fi
# Decide size of output image
if (( $OUTPUT_IMG_WIDTH < $SCREEN_WIDTH+$SCREEN_X )); then OUTPUT_IMG_WIDTH=$(($SCREEN_WIDTH+$SCREEN_X)); fi;
if (( $OUTPUT_IMG_HEIGHT < $SCREEN_HEIGHT+$SCREEN_Y )); then OUTPUT_IMG_HEIGHT=$(( $SCREEN_HEIGHT+$SCREEN_Y )); fi;
PARAMS="$PARAMS $CACHE_IMG -geometry +$SCREEN_X+$SCREEN_Y -composite "
fi
done <<<"`xrandr`"
#Execute ImageMagick:
eval convert -size ${OUTPUT_IMG_WIDTH}x${OUTPUT_IMG_HEIGHT} 'xc:black' $OUTPUT_IMG
eval convert $OUTPUT_IMG $PARAMS $OUTPUT_IMG
#Lock the screen:
i3lock --image=$OUTPUT_IMG --tiling --show-failed-attempts