we_full.sh 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_HRTF=1: sound objects render like on headphones: an alsoft.ini with stereo-mode = headphones next to
  9. # wallpaper64.exe (OpenAL Soft 1.21.1 in mediaextensions64.dll reads it from the exe's folder), removed otherwise
  10. ulimit -c 0
  11. HERE=$(cd "$(dirname "$0")" && pwd)
  12. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  13. D=${WE_DISPLAY:-:98}
  14. [ "$D" = ":98" ] && { bash "$(dirname "$0")/we_display.sh" >/dev/null || exit 1; }
  15. # WE_WINE_DIR=<other Wine build root> with its own WE_PREFIX (README); default is system Wine and $S/wineprefix
  16. 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}
  17. 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}
  18. export WINEPREFIX=${WE_PREFIX:-$S/wineprefix} DISPLAY=$D WINEDEBUG=${WE_WINEDEBUG:--all} DXVK_LOG_PATH=$S
  19. # Wine must only see the isolated :98, not the desktop session (wayland-0, D-Bus) in the shared runtime dir
  20. unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS; export XDG_RUNTIME_DIR=$S/run
  21. # 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)
  22. export PULSE_SERVER=unix:$S/run/no-pulse PIPEWIRE_REMOTE=$S/run/no-pipewire ALSA_CONFIG_PATH=/dev/null
  23. # WE_AUDIO_REC=<file.wav>: record WE's audio from a private null sink (audio_sink.sh)
  24. if [ -n "$WE_AUDIO_REC" ]; then
  25. bash "$(dirname "$0")/audio_sink.sh" start || exit 1
  26. eval "$(bash "$(dirname "$0")/audio_sink.sh" env)"
  27. fi
  28. [ -n "$WE_WINED3D" ] && export WINEDLLOVERRIDES="d3d11,d3d10core,dxgi=b"
  29. [ "$D" != ":97" ] || pgrep -f "Xvfb :97" >/dev/null || { Xvfb :97 -screen 0 1920x1080x24 -nolisten tcp >/dev/null 2>&1 & sleep 1; }
  30. $WINESERVER -k 2>/dev/null; timeout 4 tail -f /dev/null
  31. cd $S/we28
  32. if [ -n "$WE_HRTF" ]; then printf '[general]\nstereo-mode = headphones\n' > alsoft.ini; else rm -f alsoft.ini; fi
  33. F=$1; [ -d "$F" ] && F=$F/scene.json
  34. WIN=$(echo "Z:$F" | tr '/' '\\')
  35. if [ -n "$WE_AUDIO_REC" ]; then
  36. bash "$(dirname "$0")/audio_sink.sh" record "$WE_AUDIO_REC" 600 & REC=$!
  37. # WE plays ~1.5 s after launch, wait for the recorder
  38. for i in $(seq 50); do pactl list short source-outputs 2>/dev/null | grep -q . && break; sleep 0.1; done
  39. sleep 0.5
  40. fi
  41. MODE=-playInWindow
  42. if [ -n "$WE_DESKTOP" ]; then
  43. MODE=
  44. EXE=$S/wedesktop.exe
  45. if [ ! -f "$EXE" ] || [ "$HERE/wedesktop.c" -nt "$EXE" ]; then
  46. if command -v x86_64-w64-mingw32-gcc >/dev/null; then
  47. x86_64-w64-mingw32-gcc -O2 -municode -mwindows -o "$EXE" "$HERE/wedesktop.c" -luser32 -lgdi32 || exit 1
  48. else
  49. python3 -m ziglang cc -target x86_64-windows-gnu -O2 -municode -o "$EXE" "$HERE/wedesktop.c" -luser32 -lgdi32 || exit 1
  50. fi
  51. fi
  52. nohup $WINE "$EXE" > $S/wedesktop.log 2>&1 &
  53. timeout 4 tail -f /dev/null
  54. fi
  55. nohup $WINE wallpaper64.exe -control openWallpaper -file "$WIN" -monitor 0 $MODE -silent > $S/we_run_last.log 2>&1 &
  56. timeout ${WE_WAIT:-25} tail -f /dev/null
  57. mkdir -p "$2"
  58. python3 - "$2" "${3:-10}" "${4:-1}" "$D" <<'PY'
  59. import sys, time, mss
  60. from PIL import Image
  61. from Xlib import display
  62. d=display.Display(sys.argv[4]); root=d.screen().root
  63. def walk(w):
  64. for c in w.query_tree().children:
  65. yield c; yield from walk(c)
  66. for w in walk(root):
  67. try: n=w.get_wm_name()
  68. except Exception: n=None
  69. if n=='Wallpaper UI': w.unmap()
  70. # the hidden UI leaves its border/shadow strips (8px override-redirect windows) and a small bar on top
  71. for w in root.query_tree().children:
  72. g=w.get_geometry()
  73. if w.get_attributes().map_state==2 and min(g.width,g.height)<=20 and (g.width,g.height)!=(1,1): w.unmap()
  74. d.sync(); time.sleep(2)
  75. t0=time.time()
  76. with mss.MSS(display=sys.argv[4]) as m:
  77. for i in range(int(sys.argv[2])):
  78. s=m.grab(m.monitors[0])
  79. Image.frombytes('RGB',s.size,s.rgb).save('%s/f%03d_%.1f.png'%(sys.argv[1],i,time.time()-t0))
  80. time.sleep(float(sys.argv[3]))
  81. PY
  82. if [ -n "$WE_UNLOAD" ]; then
  83. # any other scene, keyorder's probe loads fast
  84. OTHER=$(echo "Z:${WE_UNLOAD_SCENE:-$HOME/.local/share/we_live/tests/keyorder/probe/scene.json}" | tr '/' '\\')
  85. $WINE wallpaper64.exe -control openWallpaper -file "$OTHER" -monitor 0 $MODE >> $S/we_run_last.log 2>&1
  86. timeout 10 tail -f /dev/null
  87. fi
  88. $WINESERVER -k 2>/dev/null
  89. if [ -n "$REC" ]; then
  90. pkill -INT -P $REC timeout
  91. wait $REC || true
  92. fi