we_full.sh 4.7 KB

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