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.

100 lines
2.5KB

  1. #!/bin/bash
  2. INDIR="$HOME/wp/curr"
  3. OUTDIR="$HOME/wp/curr"
  4. mkdir -p "$OUTDIR"
  5. sedstr="\([0-9][0-9]*\)x\([0-9][0-9]*\)+\([0-9][0-9]*\)+\([0-9][0-9]*\)"
  6. monitors="$(xrandr -q | grep '[0-9]*x[0-9]*+[0-9]*+[0-9]*' | cut -f1 -d' ' | tr '\n' '~')"
  7. function getinfo() {
  8. xrandr -q | grep "^$1" | grep -o "[0-9][0-9]*x[0-9][0-9]*+[0-9][0-9]*+[0-9][0-9]*"
  9. }
  10. function getres() {
  11. getinfo "$1" | sed "s:$sedstr:\1x\2:"
  12. }
  13. function getoff() {
  14. getinfo "$1" | sed "s:$sedstr:+\3+\4:"
  15. }
  16. function getwidth() {
  17. getinfo "$1" | sed "s:$sedstr:\1:"
  18. }
  19. function getheight() {
  20. getinfo "$1" | sed "s:$sedstr:\2:"
  21. }
  22. function getleft() {
  23. getinfo "$1" | sed "s:$sedstr:\3:"
  24. }
  25. function gettop() {
  26. getinfo "$1" | sed "s:$sedstr:\4:"
  27. }
  28. function screenres() {
  29. xrandr -q | grep "^Screen 0" | sed 's:^.*current \([0-9][0-9]*\) x \([0-9][0-9]*\).*$:\1x\2:'
  30. }
  31. function run() {
  32. echo "$@"
  33. "$@" || exit 1
  34. }
  35. function main() {
  36. all="$OUTDIR/all-$monitors.png"
  37. all_blur="$OUTDIR/all-${monitors}_blur.png"
  38. if [ ! -e "$all" ] || [ ! -e "$all_blur" ] \
  39. || [ "$INDIR/motif.png" -nt "$all" ] \
  40. || [ "$INDIR/panorama.png" -nt "$all" ] \
  41. || [ "$(realpath "$INDIR/motif.png")" -nt "$all" ] \
  42. || [ "$(realpath "$INDIR/panorama.png")" -nt "$all" ]; then
  43. local joinargs=()
  44. while [ -n "$1" ] && [ "$1" != "--" ]; do
  45. if xrandr --listmonitors | grep -q "$1"; then
  46. local res="$(getres "$1")"
  47. run convert "$INDIR/motif.png" -resize "$res^" -gravity center -extent "$res" "$OUTDIR/$1.png"
  48. joinargs+=("$OUTDIR/$1.png" -geometry "$(getoff "$1")" -composite)
  49. fi
  50. shift
  51. done
  52. shift
  53. if [ -n "$1" ]; then
  54. local splitargs=()
  55. local off=0
  56. local maxh=0
  57. while [ -n "$1" ]; do
  58. if xrandr --listmonitors | grep -q "$1"; then
  59. splitargs+=(\( -clone 0 -gravity West -extent "$(getres "$1")+$off+0" -write "$OUTDIR/$1.png" +delete \))
  60. joinargs+=("$OUTDIR/$1.png" -geometry "$(getoff "$1")" -composite)
  61. off=$((off + $(getwidth "$1")))
  62. if [ "$maxh" -lt "$(getheight "$1")" ]; then
  63. maxh="$(getheight "$1")"
  64. fi
  65. fi
  66. shift
  67. done
  68. run convert -respect-parenthesis "$INDIR/panorama.png" -gravity Center -resize "${off}x${maxh}^" -crop "${off}x${maxh}+0+0^" "${splitargs[@]}" "jpg:/dev/null"
  69. fi
  70. run convert -respect-parenthesis -size "$(screenres)" 'xc:#000000' "${joinargs[@]}" "$all"
  71. run convert "$all" -blur 0x"$((maxh / 100))" "$all_blur"
  72. fi
  73. test -e "$OUTDIR/all.png" && rm "$OUTDIR/all.png"
  74. ln -sf "$all" "$OUTDIR/all.png"
  75. test -e "$OUTDIR/all_blur.png" && rm "$OUTDIR/all_blur.png"
  76. ln -sf "$all_blur" "$OUTDIR/all_blur.png"
  77. }
  78. main "$@"