|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/bin/bash
-
- INDIR="$HOME/wp/curr"
- OUTDIR="$HOME/wp/curr/out"
-
- mkdir -p "$OUTDIR"
-
- gravity="Center"
- if [ -e "$INDIR/gravity" ]; then
- gravity="$(cat "$INDIR/gravity")"
- fi
-
- 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]*' | sed 's:^\([^ ]*\).* \([0-9]*x[0-9]*+[0-9]*+[0-9]*\).*$:\1@\2:' | tr '\n' '-')$gravity"
-
- 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/${monitors}_all.png"
- all_blur="$OUTDIR/${monitors}_all_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 "$gravity" -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 "$@"
|