ours_span.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # usage: ours_span.sh <scene dir> <out dir> [count] [interval seconds] [engine args...]
  3. # this engine on the span_display.sh outputs (same layout as we_span.sh), grabs of the whole layout via grim
  4. # WE_SPAN_MONITORS the outputs, as for we_span.sh
  5. # OURS_SPAN_SCREENS --screen-span list (default every output: HEADLESS-1,HEADLESS-2,...); "none" gives each
  6. # output its own --screen-root
  7. # WE_SPAN_CURSOR "x,y x,y" pointer positions in layout pixels before each grab (a wlr virtual pointer)
  8. # OURS_WAIT seconds before the first grab (default 8)
  9. # LWE=<dir with linux-wallpaperengine> picks the build (default: this checkout's build/output)
  10. ulimit -c 0
  11. HERE=$(cd "$(dirname "$0")" && pwd)
  12. P=${WE_SPAN_DIR:-$HOME/.local/share/we_live/span}
  13. LWE=${LWE:-$(cd "$HERE/../../.." && pwd)/build/output}
  14. MONITORS=${WE_SPAN_MONITORS:-1920x1080+0+0 1280x1024+2120+200}
  15. bash "$HERE/span_display.sh" start $MONITORS >/dev/null || exit 1
  16. eval "$(bash "$HERE/span_display.sh" env)"
  17. SCENE=$1 OUT=$2 COUNT=${3:-3} INTERVAL=${4:-1}
  18. shift 4 2>/dev/null || shift $#
  19. N=$(echo $MONITORS | wc -w)
  20. SCREENS=${OURS_SPAN_SCREENS:-$(seq -s, -f 'HEADLESS-%g' 1 $N)}
  21. if [ "$SCREENS" = none ]; then
  22. TARGETS=$(for i in $(seq $N); do printf -- '--screen-root HEADLESS-%d --bg %s ' $i "$SCENE"; done)
  23. else
  24. TARGETS="--screen-span $SCREENS --bg $SCENE"
  25. fi
  26. mkdir -p "$OUT" $P/run && chmod 700 $P/run
  27. VP=$P/bin/wlr_virtual_pointer
  28. D=$HERE/../../desktops
  29. if [ -n "$WE_SPAN_CURSOR" ] && { [ ! -x $VP ] || [ $D/wlr_virtual_pointer.c -nt $VP ]; }; then
  30. mkdir -p $P/bin/vp
  31. wayland-scanner client-header $D/wlr-virtual-pointer-unstable-v1.xml $P/bin/vp/wlr-virtual-pointer-unstable-v1-client-protocol.h
  32. wayland-scanner private-code $D/wlr-virtual-pointer-unstable-v1.xml $P/bin/vp/wlr-virtual-pointer.c
  33. cc -o $VP $D/wlr_virtual_pointer.c $P/bin/vp/wlr-virtual-pointer.c -I$P/bin/vp -lwayland-client || exit 1
  34. fi
  35. # the session's own runtime dir (its Wayland socket), a private bus, dead audio sockets, no X display
  36. env -i PATH=$PATH HOME=$HOME LANG=C.UTF-8 XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
  37. XDG_SESSION_TYPE=wayland PULSE_SERVER=unix:$P/run/no-pulse PIPEWIRE_REMOTE=$P/run/no-pipewire \
  38. ALSA_CONFIG_PATH=/dev/null LWE_SCRIPT_LOG=1 \
  39. setsid dbus-run-session -- "$LWE/linux-wallpaperengine" --silent --fps 30 \
  40. --assets-dir /workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets "$@" $TARGETS > "$OUT/engine.log" 2>&1 &
  41. ENGINE=$!
  42. timeout ${OURS_WAIT:-8} tail -f /dev/null
  43. python3 - "$OUT" "$COUNT" "$INTERVAL" "$WE_SPAN_CURSOR" "$VP" <<'PY'
  44. import glob, json, os, subprocess, sys, time
  45. out, count, interval, cursor, vp = sys.argv[1], int(sys.argv[2]), float(sys.argv[3]), sys.argv[4], sys.argv[5]
  46. env = dict(os.environ, SWAYSOCK=glob.glob(os.environ['XDG_RUNTIME_DIR'] + '/sway-ipc.*.sock')[0])
  47. points = [tuple(map(int, p.split(','))) for p in cursor.split()]
  48. pointer = None
  49. if points:
  50. rects = [o['rect'] for o in json.loads(subprocess.run(['swaymsg', '-t', 'get_outputs', '-r'], env=env,
  51. capture_output=True, text=True).stdout) if o['active']]
  52. left, top = min(r['x'] for r in rects), min(r['y'] for r in rects)
  53. width = max(r['x'] + r['width'] for r in rects) - left
  54. height = max(r['y'] + r['height'] for r in rects) - top
  55. pointer = subprocess.Popen([vp], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True, env=env)
  56. t0 = time.time()
  57. for i in range(count):
  58. if pointer:
  59. x, y = points[min(i, len(points) - 1)]
  60. pointer.stdin.write('abs %d %d %d %d\n' % (x - left, y - top, width, height))
  61. pointer.stdin.flush()
  62. pointer.stdout.readline()
  63. time.sleep(1)
  64. subprocess.run(['grim', '%s/f%03d_%.1f.png' % (out, i, time.time() - t0)], env=env, check=True)
  65. time.sleep(interval)
  66. if pointer:
  67. pointer.stdin.write('quit\n')
  68. pointer.stdin.close()
  69. pointer.wait(5)
  70. PY
  71. pkill -TERM -s $(ps -o sid= -p $ENGINE | tr -d ' ') 2>/dev/null
  72. wait $ENGINE 2>/dev/null