├── .gitignore ├── LICENSE ├── README.md ├── i3lock-multimonitor-demo.png ├── img ├── background.png └── cache │ └── .keep └── lock /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | img/cache/*.png 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Gui Meira 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # i3lock-multimonitor 2 | This is a script which uses a background image, resizes it to show correctly on any multimonitor setup. 3 | 4 | ![i3lock-multimonitor-demo](./i3lock-multimonitor-demo.png "i3lock-multimonitor-demo.png") 5 | 6 | The idea for this project was shamelessly copied from [guimeira](https://github.com/guimeira)'s [i3lock-fancy-multimonitor](https://github.com/guimeira/i3lock-fancy-multimonitor). 7 | 8 | It uses [ImageMagick](http://www.imagemagick.org/) to resize the [background image](./img/background.png). You can replace this image to change background. 9 | 10 | By using information from [xrandr](http://www.x.org/wiki/Projects/XRandR/) and basic math, this script supports multiple monitor setups, displaying the background image on all screens. 11 | 12 | It caches the generated image for different screen sizes and xrandr output. So even though first `lock` command will take a second to finish, subsequent `lock` will be lighting fast. 13 | 14 | ## Installation 15 | Make sure you have all the dependencies: 16 | Note - Instructions are for Ubuntu since its the most popular linux distro. 17 | ``` 18 | sudo apt-get install imagemagick i3lock 19 | ``` 20 | Copy the `lock` script along with the images to some place on your system (e.g.: the i3 folder) and give it execution permission: 21 | ``` 22 | git clone https://github.com/shikherverma/i3lock-multimonitor.git 23 | cp -r i3lock-multimonitor ~/.i3 24 | chmod +x ~/.i3/i3lock-multimonitor/lock 25 | ``` 26 | Create a key binding on your i3 config file (in this example I'm using $mod+p): 27 | ``` 28 | echo "bindsym \$mod+p exec /home/$USER/.i3/i3lock-multimonitor/lock" >> ~/.i3/config 29 | ``` 30 | Now reload the i3 configuration file. By default, the key binding is `$mod+Shift+c`. 31 | -------------------------------------------------------------------------------- /i3lock-multimonitor-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShikherVerma/i3lock-multimonitor/146d6de67cb49c6fe06160c911d8b47144554843/i3lock-multimonitor-demo.png -------------------------------------------------------------------------------- /img/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShikherVerma/i3lock-multimonitor/146d6de67cb49c6fe06160c911d8b47144554843/img/background.png -------------------------------------------------------------------------------- /img/cache/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShikherVerma/i3lock-multimonitor/146d6de67cb49c6fe06160c911d8b47144554843/img/cache/.keep -------------------------------------------------------------------------------- /lock: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Constants 4 | DISPLAY_RE="([0-9]+)x([0-9]+)\\+([0-9]+)\\+([0-9]+)" # Regex to find display dimensions 5 | PARAMS="-colorspace sRGB" # ensure that images are created in sRGB colorspace, to avoid greyscale output 6 | DEFAULT_CACHE_FOLDER="$HOME"/.cache/i3lock-multimonitor/img/ # Cache folder 7 | 8 | # Use XDG cache folder if that variable is set. 9 | if [ -z "$XDG_CACHE_HOME" ] 10 | then 11 | CACHE_FOLDER=$DEFAULT_CACHE_FOLDER 12 | else 13 | CACHE_FOLDER=$XDG_CACHE_HOME 14 | fi 15 | 16 | if ! [[ "$CACHE_FOLDER" == "*/" ]]; then 17 | CACHE_FOLDER="$CACHE_FOLDER/" 18 | fi 19 | 20 | # Create the cache folder if it does not exist 21 | if ! [ -e $CACHE_FOLDER ]; then 22 | mkdir -p $CACHE_FOLDER 23 | fi 24 | 25 | #Passed arguments 26 | while getopts ":i:a:d:" opt; do 27 | case $opt in 28 | i) arg_image="$OPTARG" 29 | ;; 30 | a) lock_args="$OPTARG" 31 | ;; 32 | d) lock_cmd=":" 33 | arg_image="$OPTARG" 34 | ;; 35 | \?) echo "Invalid option -$OPTARG" >&2 && exit 1 36 | ;; 37 | esac 38 | done 39 | 40 | #Image paths 41 | if [ "$arg_image" ]; then 42 | BKG_IMG="$arg_image" # Passed image 43 | elif [ -f "/usr/share/i3lock-multimonitor/img/background.png" ]; then 44 | BKG_IMG="/usr/share/i3lock-multimonitor/img/background.png" # Default image 45 | else 46 | BKG_IMG="$(dirname "$BASH_SOURCE")/img/background.png" # Fallback to current folder 47 | fi 48 | 49 | if ! [ -e "$BKG_IMG" ]; then 50 | echo "No background image! Exiting..." 51 | exit 2 52 | fi 53 | 54 | MD5_BKG_IMG=$(md5sum $BKG_IMG | cut -c 1-10) 55 | MD5_SCREEN_CONFIG=$(xrandr | md5sum - | cut -c 1-32) # Hash of xrandr output 56 | OUTPUT_IMG="$CACHE_FOLDER""$MD5_SCREEN_CONFIG"."$MD5_BKG_IMG".png # Path of final image 57 | OUTPUT_IMG_WIDTH=0 # Decide size to cover all screens 58 | OUTPUT_IMG_HEIGHT=0 # Decide size to cover all screens 59 | 60 | #i3lock command 61 | if [ "$lock_cmd" ]; then 62 | LOCK_BASE_CMD="$lock_cmd" 63 | else 64 | LOCK_BASE_CMD="i3lock -i $OUTPUT_IMG" 65 | fi 66 | 67 | if [ "$lock_args" ]; then 68 | LOCK_ARGS="$lock_args" # Passed command 69 | else 70 | LOCK_ARGS="-t -e" # Default 71 | fi 72 | LOCK_CMD="$LOCK_BASE_CMD $LOCK_ARGS" 73 | 74 | if [ -e $OUTPUT_IMG ] 75 | then 76 | # Lock screen since image already exists 77 | $LOCK_CMD 78 | exit 0 79 | fi 80 | 81 | #Execute xrandr to get information about the monitors: 82 | while read LINE 83 | do 84 | #If we are reading the line that contains the position information: 85 | if [[ $LINE =~ $DISPLAY_RE ]]; then 86 | #Extract information and append some parameters to the ones that will be given to ImageMagick: 87 | SCREEN_WIDTH=${BASH_REMATCH[1]} 88 | SCREEN_HEIGHT=${BASH_REMATCH[2]} 89 | SCREEN_X=${BASH_REMATCH[3]} 90 | SCREEN_Y=${BASH_REMATCH[4]} 91 | 92 | CACHE_IMG="$CACHE_FOLDER""$SCREEN_WIDTH"x"$SCREEN_HEIGHT"."$MD5_BKG_IMG".png 93 | ## if cache for that screensize doesnt exist 94 | if ! [ -e $CACHE_IMG ] 95 | then 96 | # Create image for that screensize 97 | eval convert '$BKG_IMG' '-resize' '${SCREEN_WIDTH}X${SCREEN_HEIGHT}^' '-gravity' 'Center' '-crop' '${SCREEN_WIDTH}X${SCREEN_HEIGHT}+0+0' '+repage' '$CACHE_IMG' 98 | fi 99 | 100 | # Decide size of output image 101 | if (( $OUTPUT_IMG_WIDTH < $SCREEN_WIDTH+$SCREEN_X )); then OUTPUT_IMG_WIDTH=$(($SCREEN_WIDTH+$SCREEN_X)); fi; 102 | if (( $OUTPUT_IMG_HEIGHT < $SCREEN_HEIGHT+$SCREEN_Y )); then OUTPUT_IMG_HEIGHT=$(( $SCREEN_HEIGHT+$SCREEN_Y )); fi; 103 | 104 | PARAMS="$PARAMS -type TrueColor $CACHE_IMG -geometry +$SCREEN_X+$SCREEN_Y -composite " 105 | fi 106 | done <<<"`xrandr`" 107 | 108 | #Execute ImageMagick: 109 | eval convert -size ${OUTPUT_IMG_WIDTH}x${OUTPUT_IMG_HEIGHT} 'xc:black' $OUTPUT_IMG 110 | eval convert $OUTPUT_IMG $PARAMS $OUTPUT_IMG 111 | 112 | #Lock the screen: 113 | $LOCK_CMD 114 | --------------------------------------------------------------------------------