AtlatestRepositorysigil-wm

sigil-wm / tree / scriptstest-x11

1#!/usr/bin/env bash
2set -euo pipefail
3cd "$(dirname "$0")/.."
4make -j2 all build/x11-client build/readback
5runtime_dir=$(mktemp -d /tmp/sigil-wm-x11.XXXXXX)
6export XDG_RUNTIME_DIR=$runtime_dir
7export WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_HEADLESS_OUTPUTS=1
8export SIGIL_WM_REPL="$runtime_dir/repl"
9server_pid= managed_pid= menu_pid=
10cleanup() {
11 for child in "$menu_pid" "$managed_pid" "$server_pid"; do
12 [[ -z $child ]] || kill "$child" 2>/dev/null || true
13 [[ -z $child ]] || wait "$child" 2>/dev/null || true
14 done
15 rm -rf "$runtime_dir"
17trap cleanup EXIT
18wait_log() {
19 for ((attempt=0; attempt<300; attempt++)); do
20 if grep -q "$2" "$1"; then return; fi
21 sleep 0.05
22 done
23 cat "$1" >&2
24 return 1
26wait_value() {
27 for ((attempt=0; attempt<100; attempt++)); do
28 if bash scripts/msg "$SIGIL_WM_REPL" "$1" | grep -q '(value #t)'; then return; fi
29 sleep 0.1
30 done
31 cat build/receipts/x11.log >&2
32 return 1
34timeout 90 bash scripts/run-sigil -L src eval -f test/x11.sgl > build/receipts/x11.log 2>&1 &
35server_pid=$!
36wait_log build/receipts/x11.log '^X_DISPLAY=:'
37export DISPLAY
38DISPLAY=$(sed -n 's/^X_DISPLAY=//p' build/receipts/x11.log | head -1)
39timeout 80 build/x11-client normal > build/receipts/x11-managed.log 2>&1 &
40managed_pid=$!
41wait_value '(and managed #t)'
42wait_log build/receipts/x11-managed.log '^X11_FOCUS=1'
43wait_value '(and saw-client-move? saw-client-resize?)'
44timeout 80 build/x11-client override > build/receipts/x11-menu.log 2>&1 &
45menu_pid=$!
46wait_value '(and managed menu #t)'
47sleep 0.3
48bash scripts/msg "$SIGIL_WM_REPL" '(host-snapshot host)' > build/receipts/x11-snapshot
49bash scripts/msg "$SIGIL_WM_REPL" '(begin (emulate-key! host 1 30 #t) (emulate-key! host 1 30 #f))'
50wait_log build/receipts/x11-managed.log '^X11_KEY=38,0'
51bash scripts/msg "$SIGIL_WM_REPL" "(capture-output! host output-id \"$PWD/build/receipts/x11.ppm\")"
52for ((attempt=0; attempt<200; attempt++)); do
53 [[ ! -s build/receipts/x11.ppm ]] || break
54 sleep 0.05
55done
56sleep 0.2
57build/readback build/receipts/x11.ppm build/receipts/x11.png x11
58bash scripts/msg "$SIGIL_WM_REPL" '(close-window! host menu)'
59wait "$menu_pid"
60menu_pid=
61wait_value '(not menu)'
62bash scripts/msg "$SIGIL_WM_REPL" '(close-window! host managed)'
63wait "$managed_pid"
64managed_pid=
65wait_value '(null? windows)'
66bash scripts/msg "$SIGIL_WM_REPL" '(stop-host! host)'
67wait "$server_pid"
68server_pid=
69grep -q '^X11_HOST=PASS' build/receipts/x11.log
70if grep -q 'event handler failed' build/receipts/x11.log; then cat build/receipts/x11.log >&2; exit 1; fi
71echo 'X11=PASS managed override input explicit-placement capture teardown'