we_span.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # usage: we_span.sh <scene dir or scene.json/scene.pkg> <out dir> [count] [interval seconds]
  3. # live WE 2.8.42 in desktop mode on several monitors (span_display.sh), screen grabs of the whole layout via grim
  4. # WE_SPAN_MONITORS="1920x1080+0+0 1280x1024+2120+200" the outputs (default these two)
  5. # WE_SPAN_LAYOUT=0|1|2 wallpaperconfig.layout: per monitor, stretch over all ("fit" in WE's UI), clone
  6. # WE_SPAN_GROUP="Monitor0,Monitor1" a stretch group (profile.groups, layout 1) with the wallpaper on the group
  7. # WE_SPAN_CURSOR="x,y x,y" pointer position in layout pixels before each grab (the last one repeats)
  8. # WE_WAIT=<seconds> wait before the first grab (default 20)
  9. # WE runs in its own install copy ($WE_SPAN_DIR/we28, config.json rewritten each run) and a Wine prefix whose
  10. # windows are unmanaged ("Managed"="N"), so sway places WE's desktop windows where WE puts them
  11. ulimit -c 0
  12. HERE=$(cd "$(dirname "$0")" && pwd)
  13. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  14. P=${WE_SPAN_DIR:-$S/span}
  15. MONITORS=${WE_SPAN_MONITORS:-1920x1080+0+0 1280x1024+2120+200}
  16. bash "$HERE/span_display.sh" start $MONITORS >/dev/null || exit 1
  17. eval "$(bash "$HERE/span_display.sh" env)"
  18. X=$DISPLAY WL=$WAYLAND_DISPLAY WLR=$XDG_RUNTIME_DIR
  19. WINE=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wine}; WINE=${WINE:-$(command -v wine)}
  20. WINESERVER=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wineserver}; WINESERVER=${WINESERVER:-$(command -v wineserver)}
  21. export WINEPREFIX=${WE_PREFIX:-$P/wineprefix} DISPLAY=$X WINEDEBUG=${WE_WINEDEBUG:--all} DXVK_LOG_PATH=$P
  22. unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS; export XDG_RUNTIME_DIR=$P/run
  23. mkdir -p $P/run && chmod 700 $P/run
  24. export PULSE_SERVER=unix:$P/run/no-pulse PIPEWIRE_REMOTE=$P/run/no-pipewire ALSA_CONFIG_PATH=/dev/null
  25. $WINESERVER -k 2>/dev/null; timeout 3 tail -f /dev/null
  26. F=$1; [ -d "$F" ] && F=$F/scene.json
  27. WIN=$(echo "Z:$F" | tr '/' '\\' | tr '\\' '/')
  28. python3 - "$P/we28/config.json" "$WIN" "${WE_SPAN_LAYOUT:-0}" "$WE_SPAN_GROUP" <<'PY'
  29. import json, sys
  30. path, scene, layout, group = sys.argv[1], sys.argv[2], int(sys.argv[3]), sys.argv[4]
  31. config = json.load(open(path))
  32. # WE keeps the settings under the Windows user's name
  33. user = config[next(k for k, v in config.items() if isinstance(v, dict) and 'general' in v)]
  34. general = user['general']
  35. # a killed WE leaves faultyShutdown=1 in the registry, the next start then runs -nowallpapers when safemode is on
  36. # (sub_14000A220)
  37. general['user']['safemode'] = False
  38. user.pop('wallpaperconfig', None)
  39. wc = {'layout': layout, 'selectedwallpapers': {}}
  40. if group:
  41. members = group.split(',')
  42. wc['profile'] = {'groups': {'group_span': {'monitors': members, 'layout': 1}}}
  43. wc['selectedwallpapers']['group_span'] = {'file': scene}
  44. else:
  45. for i in range(8):
  46. wc['selectedwallpapers']['Monitor%d' % i] = {'file': scene}
  47. general['wallpaperconfig'] = wc
  48. json.dump(config, open(path, 'w'), indent='\t')
  49. PY
  50. cd $P/we28
  51. : > log.txt
  52. EXE=$S/wedesktop.exe
  53. if [ ! -f "$EXE" ] || [ "$HERE/wedesktop.c" -nt "$EXE" ]; then
  54. x86_64-w64-mingw32-gcc -O2 -municode -mwindows -o "$EXE" "$HERE/wedesktop.c" -luser32 -lgdi32 || exit 1
  55. fi
  56. nohup $WINE "$EXE" > $P/wedesktop.log 2>&1 &
  57. timeout 4 tail -f /dev/null
  58. # no -control: openWallpaper rewrites wallpaperconfig without the layout, WE loads selectedwallpapers by itself
  59. nohup $WINE wallpaper64.exe > $P/we_run_last.log 2>&1 &
  60. timeout ${WE_WAIT:-20} tail -f /dev/null
  61. mkdir -p "$2"
  62. # the "Wallpaper UI" pop-up and WE's small helper windows cover the wallpaper
  63. DISPLAY=$X python3 - <<'PY'
  64. from Xlib import display
  65. d = display.Display(); root = d.screen().root
  66. for w in root.query_tree().children:
  67. try:
  68. cls = (w.get_wm_class() or ('', ''))[1]
  69. g = w.get_geometry()
  70. except Exception:
  71. continue
  72. if cls in ('wallpaperui.exe', 'explorer.exe') or (cls == 'wallpaper64.exe' and max(g.width, g.height) < 200):
  73. w.unmap()
  74. d.sync()
  75. PY
  76. DISPLAY=$X xwininfo -root -tree > "$2/windows.txt" 2>&1
  77. XDG_RUNTIME_DIR=$WLR SWAYSOCK=$(ls $WLR/sway-ipc.*.sock | head -1) swaymsg -t get_tree > "$2/sway_tree.json"
  78. python3 - "$2" "${3:-3}" "${4:-1}" "$WL" "$WLR" "$WE_SPAN_CURSOR" "$X" <<'PY'
  79. import glob, os, subprocess, sys, time
  80. out, count, interval, wl, runtime, cursor, x11 = sys.argv[1:8]
  81. count, interval = int(count), float(interval)
  82. env = dict(os.environ, WAYLAND_DISPLAY=wl, XDG_RUNTIME_DIR=runtime, SWAYSOCK=glob.glob(runtime + '/sway-ipc.*.sock')[0])
  83. points = [tuple(map(int, p.split(','))) for p in cursor.split()]
  84. t0 = time.time()
  85. for i in range(count):
  86. if points:
  87. # Wine's GetCursorPos asks the X server, an XTest warp moves that pointer (the headless seat has none)
  88. x, y = points[min(i, len(points) - 1)]
  89. xenv = dict(os.environ, DISPLAY=x11)
  90. for attempt in range(10):
  91. subprocess.run(['xdotool', 'mousemove', str(x), str(y)], env=xenv)
  92. where = subprocess.run(['xdotool', 'getmouselocation'], env=xenv, capture_output=True, text=True).stdout
  93. if where.startswith('x:%d y:%d ' % (x, y)):
  94. break
  95. time.sleep(0.1)
  96. else:
  97. print('pointer did not move to', x, y, file=sys.stderr)
  98. time.sleep(1)
  99. subprocess.run(['grim', '%s/f%03d_%.1f.png' % (out, i, time.time() - t0)], env=env, check=True)
  100. time.sleep(interval)
  101. PY
  102. cp $P/we28/log.txt "$2/we_log.txt"
  103. $WINESERVER -k 2>/dev/null