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