BlueGit

ict rusty-teams

chore(scripts): headless screenshots on a private Xvfb display

window-shot.ps1 typed into whatever window had focus on the Windows desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-08 · 7 weeks ago

Hash
9c639770b9a972768201bdd36e3eebdda4400d32
Parent
650e45d1
2 files changed +64 −0
README.md +1 −0
@@ -90,6 +90,7 @@ It signs you in through a real Teams web page and lets that page make the API ca
90 90 | Against Chrome on a debug port | `cargo run -p app -- --endpoint http://127.0.0.1:9222` |
91 91 | Windows exe from WSL/Linux | `scripts/build-windows.sh crates/app teams`, see [docs/build-windows.md](docs/build-windows.md) |
92 92 | Tests | `cargo test` |
93 | Screenshot without a desktop (Xvfb, xdotool, xclip, mesa-vulkan-drivers) | `cargo build -p app && scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello"` |
93 94
94 95 ## Docs
95 96
@@ -90,6 +90,7 @@ It signs you in through a real Teams web page and lets that page make the API ca
90| Against Chrome on a debug port | `cargo run -p app -- --endpoint http://127.0.0.1:9222` |
90| Against Chrome on a debug port | `cargo run -p app -- --endpoint http://127.0.0.1:9222` |
91| Windows exe from WSL/Linux | `scripts/build-windows.sh crates/app teams`, see [docs/build-windows.md](docs/build-windows.md) |
91| Windows exe from WSL/Linux | `scripts/build-windows.sh crates/app teams`, see [docs/build-windows.md](docs/build-windows.md) |
92| Tests | `cargo test` |
92| Tests | `cargo test` |
93| Screenshot without a desktop (Xvfb, xdotool, xclip, mesa-vulkan-drivers) | `cargo build -p app && scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello"` |
93
94
94## Docs
95## Docs
95
96
scripts/headless-shot.sh added +63 −0
@@ -0,0 +1,63 @@
1 #!/usr/bin/env bash
2 # Usage: scripts/headless-shot.sh OUT.png [--size 1280x800] [--wait 10] [--bin target/debug/teams] [--] [xdotool command]...
3 # Runs the Linux build with --demo on a private Xvfb display and saves a screenshot.
4 # Example: scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello" "paste ```\\ncode\\n```"
5 # `type` cannot send a backtick (X11 treats it as a dead key and input stops); use `paste`, which expands \n.
6 set -euo pipefail
7
8 out=${1:?output png}
9 shift
10 size=1280x800
11 wait_seconds=10
12 binary=target/debug/teams
13 while [[ $# -gt 0 ]]; do
14 case $1 in
15 --size) size=$2; shift 2 ;;
16 --wait) wait_seconds=$2; shift 2 ;;
17 --bin) binary=$2; shift 2 ;;
18 --) shift; break ;;
19 *) break ;;
20 esac
21 done
22
23 display_number=$((100 + RANDOM % 800))
24 Xvfb ":$display_number" -screen 0 "${size}x24" -nolisten tcp >/dev/null 2>&1 &
25 xvfb_pid=$!
26 app_pid=
27 cleanup() {
28 [[ -n $app_pid ]] && kill "$app_pid" 2>/dev/null || true
29 kill "$xvfb_pid" 2>/dev/null || true
30 }
31 trap cleanup EXIT
32 sleep 1
33
34 export DISPLAY=":$display_number"
35 unset WAYLAND_DISPLAY
36 export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json
37 "$binary" --demo >/dev/null 2>&1 &
38 app_pid=$!
39 sleep "$wait_seconds"
40
41 for command in "$@"; do
42 subcommand=${command%% *}
43 rest=${command#"$subcommand"}
44 rest=${rest# }
45 if [[ $subcommand == click ]]; then
46 # Xvfb has no window manager: keyboard focus only follows an explicit windowfocus.
47 eval "$(xdotool getmouselocation --shell)"
48 xdotool windowfocus --sync "$WINDOW"
49 fi
50 if [[ $subcommand == type ]]; then
51 xdotool type --delay 20 -- "$rest"
52 elif [[ $subcommand == paste ]]; then
53 printf '%b' "$rest" | xclip -selection clipboard
54 xdotool key ctrl+v
55 else
56 read -r -a arguments <<<"$rest"
57 xdotool "$subcommand" "${arguments[@]}"
58 fi
59 sleep 0.4
60 done
61 sleep 1
62 import -window root "$out"
63 echo "$out"
@@ -0,0 +1,63 @@
1#!/usr/bin/env bash
2# Usage: scripts/headless-shot.sh OUT.png [--size 1280x800] [--wait 10] [--bin target/debug/teams] [--] [xdotool command]...
3# Runs the Linux build with --demo on a private Xvfb display and saves a screenshot.
4# Example: scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello" "paste ```\\ncode\\n```"
5# `type` cannot send a backtick (X11 treats it as a dead key and input stops); use `paste`, which expands \n.
6set -euo pipefail
7
8out=${1:?output png}
9shift
10size=1280x800
11wait_seconds=10
12binary=target/debug/teams
13while [[ $# -gt 0 ]]; do
14 case $1 in
15 --size) size=$2; shift 2 ;;
16 --wait) wait_seconds=$2; shift 2 ;;
17 --bin) binary=$2; shift 2 ;;
18 --) shift; break ;;
19 *) break ;;
20 esac
21done
22
23display_number=$((100 + RANDOM % 800))
24Xvfb ":$display_number" -screen 0 "${size}x24" -nolisten tcp >/dev/null 2>&1 &
25xvfb_pid=$!
26app_pid=
27cleanup() {
28 [[ -n $app_pid ]] && kill "$app_pid" 2>/dev/null || true
29 kill "$xvfb_pid" 2>/dev/null || true
30}
31trap cleanup EXIT
32sleep 1
33
34export DISPLAY=":$display_number"
35unset WAYLAND_DISPLAY
36export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json
37"$binary" --demo >/dev/null 2>&1 &
38app_pid=$!
39sleep "$wait_seconds"
40
41for command in "$@"; do
42 subcommand=${command%% *}
43 rest=${command#"$subcommand"}
44 rest=${rest# }
45 if [[ $subcommand == click ]]; then
46 # Xvfb has no window manager: keyboard focus only follows an explicit windowfocus.
47 eval "$(xdotool getmouselocation --shell)"
48 xdotool windowfocus --sync "$WINDOW"
49 fi
50 if [[ $subcommand == type ]]; then
51 xdotool type --delay 20 -- "$rest"
52 elif [[ $subcommand == paste ]]; then
53 printf '%b' "$rest" | xclip -selection clipboard
54 xdotool key ctrl+v
55 else
56 read -r -a arguments <<<"$rest"
57 xdotool "$subcommand" "${arguments[@]}"
58 fi
59 sleep 0.4
60done
61sleep 1
62import -window root "$out"
63echo "$out"