we_span.sh 5.4 KB

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