we_resize.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # usage: we_resize.sh <scene dir or scene.json/scene.pkg> <out dir> <WxH> [WxH ...]
  3. # live WE 2.8.42 -playInWindow on one span_display.sh output (2560x1440), started with the first client size and
  4. # resized to each following one with wewinsize.exe (SetWindowPos inside Wine, WE's own WM_SIZE path); grabs the
  5. # client area as <out>/<n>_<W>x<H>.png. WE_RESIZE_FRESH=1 instead starts a new WE for every size (the reference a
  6. # resize should match). WE_WAIT=<seconds> before the first grab (default 20), WE_RESIZE_SETTLE after a resize (3).
  7. # RESIZE_POINTER="dx,dy" puts the pointer at that client position before each grab.
  8. ulimit -c 0
  9. HERE=$(cd "$(dirname "$0")" && pwd)
  10. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  11. P=${WE_SPAN_DIR:-$S/span}
  12. MINGW=${MINGW_CC:-$(command -v x86_64-w64-mingw32-gcc || echo $HOME/.local/share/mingw-root/usr/bin/x86_64-w64-mingw32-gcc)}
  13. bash "$HERE/span_display.sh" start 2560x1440+0+0 >/dev/null || exit 1
  14. eval "$(bash "$HERE/span_display.sh" env)"
  15. X=$DISPLAY WL=$WAYLAND_DISPLAY WLR=$XDG_RUNTIME_DIR
  16. WINE=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wine}; WINE=${WINE:-$(command -v wine)}
  17. WINESERVER=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wineserver}; WINESERVER=${WINESERVER:-$(command -v wineserver)}
  18. export WINEPREFIX=${WE_PREFIX:-$P/wineprefix} DISPLAY=$X WINEDEBUG=${WE_WINEDEBUG:--all} DXVK_LOG_PATH=$P
  19. unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS; export XDG_RUNTIME_DIR=$P/run
  20. mkdir -p $P/run && chmod 700 $P/run
  21. export PULSE_SERVER=unix:$P/run/no-pulse PIPEWIRE_REMOTE=$P/run/no-pipewire ALSA_CONFIG_PATH=/dev/null
  22. EXE=$P/bin/wewinsize.exe
  23. if [ ! -f "$EXE" ] || [ "$HERE/wewinsize.c" -nt "$EXE" ]; then
  24. mkdir -p $P/bin && "$MINGW" -O2 -o "$EXE" "$HERE/wewinsize.c" -luser32 || exit 1
  25. fi
  26. F=$1; [ -d "$F" ] && F=$F/scene.json
  27. WIN=$(echo "Z:$F" | tr '/' '\\')
  28. OUT=$2
  29. shift 2
  30. mkdir -p "$OUT"
  31. python3 - "$P/we28/config.json" <<'PY'
  32. import json, sys
  33. config = json.load(open(sys.argv[1]))
  34. # WE keeps the settings under the Windows user's name
  35. user = config[next(k for k, v in config.items() if isinstance(v, dict) and 'general' in v)]
  36. user['general']['user']['safemode'] = False
  37. json.dump(config, open(sys.argv[1], 'w'), indent='\t')
  38. PY
  39. start() {
  40. $WINESERVER -k 2>/dev/null; timeout 3 tail -f /dev/null
  41. (cd $P/we28 && nohup $WINE wallpaper64.exe -control openWallpaper -file "$WIN" -playInWindow -width ${1%x*} \
  42. -height ${1#*x} -x 40 -y 60 -silent > $P/we_run_last.log 2>&1 &)
  43. timeout ${WE_WAIT:-20} tail -f /dev/null
  44. DISPLAY=$X python3 - <<'PY'
  45. from Xlib import display
  46. d = display.Display(); root = d.screen().root
  47. for w in root.query_tree().children:
  48. try:
  49. cls = (w.get_wm_class() or ('', ''))[1]
  50. g = w.get_geometry()
  51. except Exception:
  52. continue
  53. if cls in ('wallpaperui.exe', 'explorer.exe') or (cls == 'wallpaper64.exe' and max(g.width, g.height) < 200):
  54. w.unmap()
  55. d.sync()
  56. PY
  57. }
  58. grab() {
  59. local rect
  60. rect=$(cd $P && $WINE "$EXE" ${1%x*} ${1#*x} 2>/dev/null | tr -d '\r')
  61. set -- $rect
  62. # the pointer at the same client position in both engines
  63. [ -n "$RESIZE_POINTER" ] && DISPLAY=$X xdotool mousemove $(($1 + ${RESIZE_POINTER%,*})) $(($2 + ${RESIZE_POINTER#*,}))
  64. timeout ${WE_RESIZE_SETTLE:-3} tail -f /dev/null
  65. WAYLAND_DISPLAY=$WL XDG_RUNTIME_DIR=$WLR grim -g "$1,$2 $3x$4" "$OUT/${N}_$3x$4.png"
  66. echo "$N: client $3x$4 at $1,$2"
  67. }
  68. N=0
  69. [ -z "$WE_RESIZE_FRESH" ] && start $1
  70. for size in "$@"; do
  71. [ -n "$WE_RESIZE_FRESH" ] && start $size
  72. grab $size
  73. N=$((N + 1))
  74. done
  75. cp $P/we_run_last.log "$OUT/we_run.log"
  76. $WINESERVER -k 2>/dev/null