ours_resize.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # usage: ours_resize.sh <scene dir> <out dir> <WxH> [WxH ...] [-- engine args]
  3. # this engine as an X11 window (--window) on the span_display.sh Xwayland, started at the first size and resized to
  4. # each following one by an X configure (xdotool windowsize), the counterpart of we_resize.sh; grabs the window as
  5. # <out>/<n>_<W>x<H>.png. OURS_RESIZE_FRESH=1 starts a new engine per size. OURS_WAIT (default 8) before the first
  6. # grab, OURS_RESIZE_SETTLE (default 2) after a resize.
  7. # RESIZE_POINTER="dx,dy" puts the pointer at that client position before each grab.
  8. # LWE=<dir with linux-wallpaperengine> picks the build (default: this checkout's build/output)
  9. ulimit -c 0
  10. HERE=$(cd "$(dirname "$0")" && pwd)
  11. P=${WE_SPAN_DIR:-$HOME/.local/share/we_live/span}
  12. LWE=${LWE:-$(cd "$HERE/../../.." && pwd)/build/output}
  13. bash "$HERE/span_display.sh" start 2560x1440+0+0 >/dev/null || exit 1
  14. eval "$(bash "$HERE/span_display.sh" env)"
  15. SCENE=$1 OUT=$2
  16. shift 2
  17. SIZES=()
  18. while [ $# -gt 0 ] && [ "$1" != "--" ]; do SIZES+=("$1"); shift; done
  19. [ "$1" = "--" ] && shift
  20. mkdir -p "$OUT" $P/run && chmod 700 $P/run
  21. ENGINE=
  22. stop_engine() {
  23. [ -n "$ENGINE" ] || return
  24. pkill -TERM -s $ENGINE 2>/dev/null
  25. for i in $(seq 50); do kill -0 $ENGINE 2>/dev/null || break; sleep 0.1; done
  26. ENGINE=
  27. }
  28. start() {
  29. local size=$1
  30. shift
  31. stop_engine
  32. # X11 window on the session's Xwayland: no Wayland socket, a private bus, dead audio sockets
  33. env -i PATH=$PATH HOME=$HOME LANG=C.UTF-8 XDG_RUNTIME_DIR=$P/run DISPLAY=$DISPLAY XDG_SESSION_TYPE=x11 \
  34. vblank_mode=0 PULSE_SERVER=unix:$P/run/no-pulse PIPEWIRE_REMOTE=$P/run/no-pipewire ALSA_CONFIG_PATH=/dev/null \
  35. setsid dbus-run-session -- "$LWE/linux-wallpaperengine" --silent --fps 30 --window 40x60x${size%x*}x${size#*x} \
  36. --assets-dir /workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets "$@" "$SCENE" \
  37. >> "$OUT/engine.log" 2>&1 &
  38. ENGINE=$!
  39. timeout ${OURS_WAIT:-8} tail -f /dev/null
  40. }
  41. grab() {
  42. local id=$(xdotool search --name '.' 2>/dev/null | while read w; do
  43. [ "$(xprop -id $w WM_CLASS 2>/dev/null | grep -c -i wallpaper)" = 1 ] && echo $w; done | head -1)
  44. [ -n "$id" ] || { echo "no engine window"; return 1; }
  45. xdotool windowsize $id ${1%x*} ${1#*x}
  46. timeout ${OURS_RESIZE_SETTLE:-2} tail -f /dev/null
  47. eval "$(xwininfo -id $id | awk '/Absolute upper-left X/{print "X="$4} /Absolute upper-left Y/{print "Y="$4} /Width/{print "W="$2} /Height/{print "H="$2}')"
  48. # the pointer at the same client position in both engines
  49. if [ -n "$RESIZE_POINTER" ]; then
  50. xdotool mousemove $((X + ${RESIZE_POINTER%,*})) $((Y + ${RESIZE_POINTER#*,}))
  51. timeout 1 tail -f /dev/null
  52. fi
  53. grim -g "$X,$Y ${W}x$H" "$OUT/${N}_${W}x$H.png"
  54. echo "$N: window ${W}x$H at $X,$Y"
  55. }
  56. N=0
  57. [ -z "$OURS_RESIZE_FRESH" ] && start ${SIZES[0]} "$@"
  58. for size in "${SIZES[@]}"; do
  59. [ -n "$OURS_RESIZE_FRESH" ] && start $size "$@"
  60. grab $size
  61. N=$((N + 1))
  62. done
  63. stop_engine