#!/bin/bash INDIR="$HOME/wp/curr" OUTDIR="$HOME/wp/curr" mkdir -p "$OUTDIR" sedstr="\([0-9][0-9]*\)x\([0-9][0-9]*\)+\([0-9][0-9]*\)+\([0-9][0-9]*\)" monitors="$(xrandr -q | grep '[0-9]*x[0-9]*+[0-9]*+[0-9]*' | cut -f1 -d' ' | tr '\n' '~')" function getinfo() { xrandr -q | grep "^$1" | grep -o "[0-9][0-9]*x[0-9][0-9]*+[0-9][0-9]*+[0-9][0-9]*" } function getres() { getinfo "$1" | sed "s:$sedstr:\1x\2:" } function getoff() { getinfo "$1" | sed "s:$sedstr:+\3+\4:" } function getwidth() { getinfo "$1" | sed "s:$sedstr:\1:" } function getheight() { getinfo "$1" | sed "s:$sedstr:\2:" } function getleft() { getinfo "$1" | sed "s:$sedstr:\3:" } function gettop() { getinfo "$1" | sed "s:$sedstr:\4:" } function screenres() { xrandr -q | grep "^Screen 0" | sed 's:^.*current \([0-9][0-9]*\) x \([0-9][0-9]*\).*$:\1x\2:' } function run() { echo "$@" "$@" || exit 1 } function main() { all="$OUTDIR/all-$monitors.png" all_blur="$OUTDIR/all-${monitors}_blur.png" if [ ! -e "$all" ] || [ ! -e "$all_blur" ] \ || [ "$INDIR/motif.png" -nt "$all" ] \ || [ "$INDIR/panorama.png" -nt "$all" ] \ || [ "$(realpath "$INDIR/motif.png")" -nt "$all" ] \ || [ "$(realpath "$INDIR/panorama.png")" -nt "$all" ]; then local joinargs=() while [ -n "$1" ] && [ "$1" != "--" ]; do if xrandr --listmonitors | grep -q "$1"; then local res="$(getres "$1")" run convert "$INDIR/motif.png" -resize "$res^" -gravity center -extent "$res" "$OUTDIR/$1.png" joinargs+=("$OUTDIR/$1.png" -geometry "$(getoff "$1")" -composite) fi shift done shift if [ -n "$1" ]; then local splitargs=() local off=0 local maxh=0 while [ -n "$1" ]; do if xrandr --listmonitors | grep -q "$1"; then splitargs+=(\( -clone 0 -gravity West -extent "$(getres "$1")+$off+0" -write "$OUTDIR/$1.png" +delete \)) joinargs+=("$OUTDIR/$1.png" -geometry "$(getoff "$1")" -composite) off=$((off + $(getwidth "$1"))) if [ "$maxh" -lt "$(getheight "$1")" ]; then maxh="$(getheight "$1")" fi fi shift done run convert -respect-parenthesis "$INDIR/panorama.png" -gravity Center -resize "${off}x${maxh}^" -crop "${off}x${maxh}+0+0^" "${splitargs[@]}" "jpg:/dev/null" fi run convert -respect-parenthesis -size "$(screenres)" 'xc:#000000' "${joinargs[@]}" "$all" run convert "$all" -blur 0x20 "$all_blur" fi test -e "$OUTDIR/all.png" && rm "$OUTDIR/all.png" ln -sf "$all" "$OUTDIR/all.png" test -e "$OUTDIR/all_blur.png" && rm "$OUTDIR/all_blur.png" ln -sf "$all_blur" "$OUTDIR/all_blur.png" } main "$@"