we_full.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # usage: we_full.sh <scene dir or scene.json/scene.pkg> <out dir> [count] [interval seconds]
  3. # runs on the GPU display :98 (DXVK); WE_DISPLAY=:97 WE_WINED3D=1 is the old Xvfb + wined3d (llvmpipe) path
  4. # full window captures (1920x1058 at +4+30 on :97) of real WE 2.8.42 under Wine, see README.md
  5. # WE_DESKTOP=1: desktop mode on monitor 0 via the wedesktop.c shell windows instead of -playInWindow
  6. # WE_UNLOAD=1: open another wallpaper before stopping so WE writes bin/scenestorage (needs a real we28/bin, not a link)
  7. # WE_WAIT=<seconds>: wait before the first grab (default 25, WE needs ~5 s to show the first frame)
  8. # WE_LED=1: starts WE once on its own first (a patched wallpaper64.exe, see we_led.sh) so the LED plugin loads, then opens the scene
  9. # WE_HRTF=1: sound objects render like on headphones: an alsoft.ini with stereo-mode = headphones next to
  10. # wallpaper64.exe (OpenAL Soft 1.21.1 in mediaextensions64.dll reads it from the exe's folder), removed otherwise
  11. ulimit -c 0
  12. HERE=$(cd "$(dirname "$0")" && pwd)
  13. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  14. D=${WE_DISPLAY:-:98}
  15. [ "$D" = ":98" ] && { bash "$(dirname "$0")/we_display.sh" >/dev/null || exit 1; }
  16. # WE_WINE_DIR=<other Wine build root> with its own WE_PREFIX (README); default is system Wine and $S/wineprefix
  17. # WE_PROTON=<name> picks an installed Proton build (proton.sh) instead
  18. [ -n "$WE_PROTON" ] && { eval "$(bash "$(dirname "$0")/proton.sh" env "$WE_PROTON")" || exit 1; }
  19. WINE=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wine}; [ -x /usr/lib/wine/wine64 ] && SYS_WINE=/usr/lib/wine/wine64 || SYS_WINE=$(command -v wine); WINE=${WINE:-$SYS_WINE}
  20. WINESERVER=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wineserver}; [ -x /usr/lib/wine/wineserver ] && SYS_WINESERVER=/usr/lib/wine/wineserver || SYS_WINESERVER=$(command -v wineserver); WINESERVER=${WINESERVER:-$SYS_WINESERVER}
  21. export WINEPREFIX=${WE_PREFIX:-$S/wineprefix} DISPLAY=$D WINEDEBUG=${WE_WINEDEBUG:--all} DXVK_LOG_PATH=$S
  22. # Wine must only see the isolated :98, not the desktop session (wayland-0, D-Bus) in the shared runtime dir
  23. unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS; export XDG_RUNTIME_DIR=$S/run
  24. # keep Wine off the desktop's audio server (a shared /run/user/<uid>/pulse would play the wallpaper's sounds on real speakers and feed real system audio to the visualizers)
  25. export PULSE_SERVER=unix:$S/run/no-pulse PIPEWIRE_REMOTE=$S/run/no-pipewire ALSA_CONFIG_PATH=/dev/null
  26. # WE_AUDIO_REC=<file.wav>: record WE's audio from a private null sink (audio_sink.sh)
  27. if [ -n "$WE_AUDIO_REC" ]; then
  28. bash "$(dirname "$0")/audio_sink.sh" start || exit 1
  29. eval "$(bash "$(dirname "$0")/audio_sink.sh" env)"
  30. fi
  31. [ -n "$WE_WINED3D" ] && export WINEDLLOVERRIDES="d3d11,d3d10core,dxgi=b"
  32. [ "$D" != ":97" ] || pgrep -f "Xvfb :97" >/dev/null || { Xvfb :97 -screen 0 1920x1080x24 -nolisten tcp >/dev/null 2>&1 & sleep 1; }
  33. $WINESERVER -k 2>/dev/null; timeout 4 tail -f /dev/null
  34. cd $S/we28
  35. if [ -n "$WE_HRTF" ]; then printf '[general]\nstereo-mode = headphones\n' > alsoft.ini; else rm -f alsoft.ini; fi
  36. F=$1; [ -d "$F" ] && F=$F/scene.json
  37. WIN=$(echo "Z:$F" | tr '/' '\\')
  38. if [ -n "$WE_AUDIO_REC" ]; then
  39. bash "$(dirname "$0")/audio_sink.sh" record "$WE_AUDIO_REC" 600 & REC=$!
  40. for i in $(seq 50); do pactl list short source-outputs 2>/dev/null | grep -q . && break; sleep 0.1; done
  41. sleep 0.5
  42. fi
  43. MODE=-playInWindow
  44. if [ -n "$WE_DESKTOP" ]; then
  45. MODE=
  46. EXE=$S/wedesktop.exe
  47. if [ ! -f "$EXE" ] || [ "$HERE/wedesktop.c" -nt "$EXE" ]; then
  48. if command -v x86_64-w64-mingw32-gcc >/dev/null; then
  49. x86_64-w64-mingw32-gcc -O2 -municode -mwindows -o "$EXE" "$HERE/wedesktop.c" -luser32 -lgdi32 || exit 1
  50. else
  51. python3 -m ziglang cc -target x86_64-windows-gnu -O2 -municode -o "$EXE" "$HERE/wedesktop.c" -luser32 -lgdi32 || exit 1
  52. fi
  53. fi
  54. nohup $WINE "$EXE" > $S/wedesktop.log 2>&1 &
  55. timeout 4 tail -f /dev/null
  56. fi
  57. SILENT=-silent
  58. if [ -n "$WE_LED" ]; then
  59. nohup $WINE wallpaper64.exe -silent > $S/we_pre.log 2>&1 &
  60. timeout 12 tail -f /dev/null
  61. SILENT=
  62. fi
  63. nohup $WINE wallpaper64.exe -control openWallpaper -file "$WIN" -monitor 0 $MODE $SILENT > $S/we_run_last.log 2>&1 &
  64. timeout ${WE_WAIT:-25} tail -f /dev/null
  65. mkdir -p "$2"
  66. python3 - "$2" "${3:-10}" "${4:-1}" "$D" <<'PY'
  67. import sys, time, mss
  68. from PIL import Image
  69. from Xlib import display
  70. d=display.Display(sys.argv[4]); root=d.screen().root
  71. def walk(w):
  72. for c in w.query_tree().children:
  73. yield c; yield from walk(c)
  74. for w in walk(root):
  75. try: n=w.get_wm_name()
  76. except Exception: n=None
  77. if n=='Wallpaper UI': w.unmap()
  78. # the hidden UI leaves its border/shadow strips (8px override-redirect windows) and a small bar on top
  79. for w in root.query_tree().children:
  80. g=w.get_geometry()
  81. if w.get_attributes().map_state==2 and min(g.width,g.height)<=20 and (g.width,g.height)!=(1,1): w.unmap()
  82. d.sync(); time.sleep(2)
  83. t0=time.time()
  84. with mss.MSS(display=sys.argv[4]) as m:
  85. for i in range(int(sys.argv[2])):
  86. s=m.grab(m.monitors[0])
  87. Image.frombytes('RGB',s.size,s.rgb).save('%s/f%03d_%.1f.png'%(sys.argv[1],i,time.time()-t0))
  88. time.sleep(float(sys.argv[3]))
  89. PY
  90. if [ -n "$WE_UNLOAD" ]; then
  91. OTHER=$(echo "Z:${WE_UNLOAD_SCENE:-$HOME/.local/share/we_live/tests/keyorder/probe/scene.json}" | tr '/' '\\')
  92. $WINE wallpaper64.exe -control openWallpaper -file "$OTHER" -monitor 0 $MODE >> $S/we_run_last.log 2>&1
  93. timeout 10 tail -f /dev/null
  94. fi
  95. $WINESERVER -k 2>/dev/null
  96. if [ -n "$REC" ]; then
  97. pkill -INT -P $REC timeout
  98. wait $REC || true
  99. fi