AtlatestRepositorysigil-wm

sigil-wm / tree / scriptstest-decorations

1#!/usr/bin/env bash
2set -euo pipefail
3cd "$(dirname "$0")/.."
4make -j2 all build/protocol-client
5mkdir -p build/receipts
6runtime_dir=$(mktemp -d /tmp/sigil-wm-decorations.XXXXXX)
7export XDG_RUNTIME_DIR="$runtime_dir" SIGIL_WM_REPL="$runtime_dir/repl"
8export WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_HEADLESS_OUTPUTS=1
9unset WAYLAND_DISPLAY DISPLAY
10server_pid= client_pid=
11cleanup() {
12 for child in "$client_pid" "$server_pid"; do
13 [[ -z $child ]] || kill "$child" 2>/dev/null || true
14 [[ -z $child ]] || wait "$child" 2>/dev/null || true
15 done
16 rm -rf "$runtime_dir"
18trap cleanup EXIT
19value() { bash scripts/msg "$SIGIL_WM_REPL" "$1"; }
20wait_value() {
21 for ((attempt=0; attempt<100; attempt++)); do
22 if value "$1" | grep -q '(value #t)'; then return; fi
23 sleep 0.05
24 done
25 cat build/receipts/decorations.log >&2
26 printf 'WAIT_FAILED=%s\n' "$1" >&2
27 return 1
29wait_count() {
30 local count
31 for ((attempt=0; attempt<200; attempt++)); do
32 count=$(grep -c "$2" "$1" 2>/dev/null || true)
33 if (( ${count:-0} >= $3 )); then return; fi
34 sleep 0.05
35 done
36 tail -20 "$1" >&2
37 return 1
39timeout 180 bash scripts/run-sigil -L src eval -f test/decorations.sgl > build/receipts/decorations.log 2>&1 &
40server_pid=$!
41wait_count build/receipts/decorations.log '^WAYLAND_SOCKET=' 1
42export WAYLAND_DISPLAY
43WAYLAND_DISPLAY=$(sed -n 's/^WAYLAND_SOCKET=//p' build/receipts/decorations.log | head -1)
44mkfifo "$runtime_dir/client-control"
45exec {client_control}<> "$runtime_dir/client-control"
46for variant in legacy-server legacy-client xdg; do
47 value '(begin (set! before-role #f) (set! unselected? #f))'
48 client_log="build/receipts/decoration-$variant.log"
49 SIGIL_WM_CLIENT_DECORATION="$variant" timeout 60 build/protocol-client green 36000 < "$runtime_dir/client-control" > "$client_log" 2>&1 &
50 client_pid=$!
51 wait_value '(and (= (length windows) 1) (= (length (dict-ref (host-snapshot host) decorations:)) 1) (> (dict-ref (car (dict-ref (host-snapshot host) decorations:)) window:) 0))'
52 if [[ $variant == legacy-* ]]; then
53 wait_count "$client_log" '^LEGACY_DEFAULT=2' 1
54 wait_value '(and before-role (= (dict-ref (car (dict-ref before-role decorations:)) window:) 0) (eq? (dict-ref (car (dict-ref before-role decorations:)) mode:) (quote server)))'
55 if [[ $variant == legacy-client ]]; then
56 wait_value '(eq? (dict-ref (car (dict-ref (host-snapshot host) decorations:)) mode:) (quote client))'
57 else
58 wait_value '(eq? (dict-ref (car (dict-ref (host-snapshot host) decorations:)) mode:) (quote server))'
59 fi
60 printf 'd\n' >&"$client_control"
61 wait_value '(eq? (dict-ref (car (dict-ref (host-snapshot host) decorations:)) mode:) (quote client))'
62 printf 's\n' >&"$client_control"
63 wait_value '(eq? (dict-ref (car (dict-ref (host-snapshot host) decorations:)) mode:) (quote server))'
64 wait_value '(and (= (dict-ref (car (dict-ref before-role decorations:)) window:) 0) (eq? (dict-ref (car (dict-ref before-role decorations:)) mode:) (quote server)))'
65 else
66 wait_count "$client_log" '^XDG_DECORATION_MODE=2' 1
67 wait_value '(and unselected? (eq? (dict-ref (car (dict-ref (host-snapshot host) decorations:)) mode:) (quote server)))'
68 fi
69 sleep 0.3
70 value '(define states-before states)'
71 serials=$(grep -c '^CLIENT_CONFIGURE_SERIAL=' "$client_log")
72 printf 'f\n' >&"$client_control"
73 wait_count "$client_log" '^CLIENT_FRAMES=' 1
74 frames_before=$(sed -n 's/^CLIENT_FRAMES=//p' "$client_log" | tail -1)
75 sleep 0.7
76 printf 'f\n' >&"$client_control"
77 wait_count "$client_log" '^CLIENT_FRAMES=' 2
78 frames_after=$(sed -n 's/^CLIENT_FRAMES=//p' "$client_log" | tail -1)
79 (( frames_after >= frames_before+10 ))
80 [[ $(grep -c '^CLIENT_CONFIGURE_SERIAL=' "$client_log") == "$serials" ]]
81 wait_value '(= states states-before)'
82 printf 'e\n' >&"$client_control"
83 wait_value '(and (null? (dict-ref (host-snapshot host) decorations:)) (= (length windows) 1))'
84 printf 'q\n' >&"$client_control"
85 wait "$client_pid"
86 client_pid=
87 wait_value '(and (null? windows) (= (host-statistic host 1) 0))'
88 printf 'DECORATION=PASS variant=%s pre-role copied association mode retirement quiet frames\n' "$variant"
89done
90value '(stop-host! host)'
91wait "$server_pid"
92server_pid=
93grep -q '^DECORATION_HOST=PASS' build/receipts/decorations.log
94echo 'DECORATIONS=PASS legacy defaults mode changes xdg explicit choice immutable snapshots no configure feedback ownership'