we_pause.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # usage: we_pause.sh <scene dir> <out dir> [seconds] (WE_SPAN_MONITORS="1920x1080+0+0")
  3. # live WE 2.8.42 in desktop mode on a private sway display (span_display.sh), a global pause (-control pause at
  4. # P_AT, default 6 s) and play (PL_AT, default 12 s) while grim grabs decode the frame number blocks of the videotex
  5. # kit's scene_pause (video texture + a script blinking square) into <out dir>/frames.txt (time, frame mod 128, square).
  6. # -playInWindow ignores -control pause (no player objects, checked with gdb), desktop mode is needed
  7. # the rest is we_span.sh
  8. # live WE 2.8.42 in desktop mode on several monitors (span_display.sh), screen grabs of the whole layout via grim
  9. # WE_SPAN_MONITORS="1920x1080+0+0 1280x1024+2120+200" the outputs (default these two)
  10. # WE_SPAN_LAYOUT=0|1|2 wallpaperconfig.layout: per monitor, stretch over all ("fit" in WE's UI), clone
  11. # WE_SPAN_GROUP="Monitor0,Monitor1" a stretch group (profile.groups, layout 1) with the wallpaper on the group
  12. # WE_SPAN_CURSOR="x,y x,y" pointer position in layout pixels before each grab (the last one repeats)
  13. # WE_WAIT=<seconds> wait before the first grab (default 20)
  14. # WE runs in its own install copy ($WE_SPAN_DIR/we28, config.json rewritten each run) and a Wine prefix whose
  15. # windows are unmanaged ("Managed"="N"), so sway places WE's desktop windows where WE puts them
  16. ulimit -c 0
  17. HERE=$(cd "$(dirname "$0")" && pwd)
  18. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  19. P=${WE_SPAN_DIR:-$S/span}
  20. MONITORS=${WE_SPAN_MONITORS:-1920x1080+0+0 1280x1024+2120+200}
  21. bash "$HERE/span_display.sh" start $MONITORS >/dev/null || exit 1
  22. eval "$(bash "$HERE/span_display.sh" env)"
  23. X=$DISPLAY WL=$WAYLAND_DISPLAY WLR=$XDG_RUNTIME_DIR
  24. # WE_PROTON=<name> picks an installed Proton build (proton.sh) instead
  25. [ -n "$WE_PROTON" ] && { eval "$(bash "$(dirname "$0")/proton.sh" env "$WE_PROTON")" || exit 1; }
  26. WINE=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wine}; WINE=${WINE:-$(command -v wine)}
  27. WINESERVER=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wineserver}; WINESERVER=${WINESERVER:-$(command -v wineserver)}
  28. export WINEPREFIX=${WE_PREFIX:-$P/wineprefix} DISPLAY=$X WINEDEBUG=${WE_WINEDEBUG:--all} DXVK_LOG_PATH=$P
  29. unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS; export XDG_RUNTIME_DIR=$P/run
  30. mkdir -p $P/run && chmod 700 $P/run
  31. export PULSE_SERVER=unix:$P/run/no-pulse PIPEWIRE_REMOTE=$P/run/no-pipewire ALSA_CONFIG_PATH=/dev/null
  32. $WINESERVER -k 2>/dev/null; timeout 3 tail -f /dev/null
  33. F=$1; [ -d "$F" ] && F=$F/scene.json
  34. WIN=$(echo "Z:$F" | tr '/' '\\' | tr '\\' '/')
  35. python3 - "$P/we28/config.json" "$WIN" "${WE_SPAN_LAYOUT:-0}" "$WE_SPAN_GROUP" <<'PY'
  36. import json, sys
  37. path, scene, layout, group = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4]
  38. config = json.load(open(path))
  39. # WE keeps the settings under the Windows user's name
  40. user = config[next(k for k, v in config.items() if isinstance(v, dict) and 'general' in v)]
  41. general = user['general']
  42. # a killed WE leaves faultyShutdown=1 in the registry, the next start then runs -nowallpapers when safemode is on
  43. # (sub_14000A220)
  44. general['user']['safemode'] = False
  45. user.pop('wallpaperconfig', None)
  46. wc = {'layout': layout, 'selectedwallpapers': {}}
  47. if group:
  48. members = group.split(',')
  49. wc['profile'] = {'groups': {'group_span': {'monitors': members, 'layout': 1}}}
  50. wc['selectedwallpapers']['group_span'] = {'file': scene}
  51. else:
  52. for i in range(8):
  53. wc['selectedwallpapers']['Monitor%d' % i] = {'file': scene}
  54. general['wallpaperconfig'] = wc
  55. json.dump(config, open(path, 'w'), indent='\t')
  56. PY
  57. cd $P/we28
  58. : > log.txt
  59. EXE=$S/wedesktop.exe
  60. if [ ! -f "$EXE" ] || [ "$HERE/wedesktop.c" -nt "$EXE" ]; then
  61. x86_64-w64-mingw32-gcc -O2 -municode -mwindows -o "$EXE" "$HERE/wedesktop.c" -luser32 -lgdi32 || exit 1
  62. fi
  63. nohup $WINE "$EXE" > $P/wedesktop.log 2>&1 &
  64. timeout 4 tail -f /dev/null
  65. # no -control: openWallpaper rewrites wallpaperconfig without the layout, WE loads selectedwallpapers by itself
  66. nohup $WINE wallpaper64.exe > $P/we_run_last.log 2>&1 &
  67. timeout ${WE_WAIT:-20} tail -f /dev/null
  68. mkdir -p "$2"
  69. # the "Wallpaper UI" pop-up and WE's small helper windows cover the wallpaper
  70. DISPLAY=$X python3 - <<'PY'
  71. from Xlib import display
  72. d = display.Display(); root = d.screen().root
  73. for w in root.query_tree().children:
  74. try:
  75. cls = (w.get_wm_class() or ('', ''))[1]
  76. g = w.get_geometry()
  77. except Exception:
  78. continue
  79. if cls in ('wallpaperui.exe', 'explorer.exe') or (cls == 'wallpaper64.exe' and max(g.width, g.height) < 200):
  80. w.unmap()
  81. d.sync()
  82. PY
  83. DISPLAY=$X xwininfo -root -tree > "$2/windows.txt" 2>&1
  84. XDG_RUNTIME_DIR=$WLR SWAYSOCK=$(ls $WLR/sway-ipc.*.sock | head -1) swaymsg -t get_tree > "$2/sway_tree.json"
  85. python3 - "$2" "${3:-24}" "$WL" "$WLR" "$WINE" <<'PY'
  86. import glob, os, subprocess, sys, time
  87. import numpy as np
  88. out, dur, wl, runtime, wine = sys.argv[1], float(sys.argv[2]), sys.argv[3], sys.argv[4], sys.argv[5]
  89. env = dict(os.environ, WAYLAND_DISPLAY=wl, XDG_RUNTIME_DIR=runtime, SWAYSOCK=glob.glob(runtime + '/sway-ipc.*.sock')[0])
  90. cenv = dict(os.environ)
  91. pts = [(20 + b * 88 + 36) * 1920 // 640 for b in range(7)]
  92. t0 = time.time(); rows = []; ev = []
  93. sched = [(float(os.environ.get('P_AT', 6)), 'pause'), (float(os.environ.get('PL_AT', 12)), 'play')]
  94. procs = []
  95. while time.time() - t0 < dur:
  96. t = time.time() - t0
  97. if sched and t >= sched[0][0]:
  98. _, c = sched.pop(0); ev.append((t, c))
  99. procs.append(subprocess.Popen([wine, 'wallpaper64.exe', '-control', c], env=cenv, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=os.getcwd()))
  100. p = subprocess.run(['grim', '-t', 'ppm', '-'], env=env, capture_output=True).stdout
  101. # header P6\nW H\n255\n
  102. parts = p.split(b'\n', 3); w, h = map(int, parts[1].split())
  103. a = np.frombuffer(parts[3], np.uint8).reshape(h, w, 3).mean(2)
  104. bits = 0
  105. for px in pts:
  106. v = a[240 - 3:240 + 4, px - 3:px + 4].mean()
  107. bits = -1 if (bits < 0 or 60 < v < 190) else bits * 2 + (v >= 190)
  108. ind = int(a[240 - 3:240 + 4, 1870 - 3:1870 + 4].mean())
  109. rows.append((time.time() - t0, bits, ind, w, h))
  110. open(out + '/frames.txt', 'w').write(''.join('%.3f %d %d\n' % r[:3] for r in rows))
  111. open(out + '/events.txt', 'w').write(''.join('%.3f %s\n' % e for e in ev))
  112. print('size', rows[0][3:], 'grabs', len(rows))
  113. PY
  114. cp $P/we28/log.txt "$2/we_log.txt"
  115. $WINESERVER -k 2>/dev/null