Files
faumarayandClaude Sonnet 5.5 806f9c6f2e docs/ui: the shell and swatch pictures at 1440 by 960
The committed pictures were 1438 by 935 (and the form 1280 by 800): taken
on a screen as large as the window, where openbox fits the window and its
frame into the screen. Regenerated the five shell pictures and the two
swatch pictures on a headless X display of 3840 by 2160 (scripts/gpui-shot.sh
under spikes/gpui/headless.sh; the form with xdotool clicks and typing), all
exactly 1440 by 960 and truecolour. docs/ui.md and the script's header now say
the screen must be larger than the window, and how the form was taken.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-27 19:31:30 +03:00

105 lines
4.5 KiB
Bash
Executable File

#!/bin/sh
# Take a screenshot of the GPUI front end with development switches set,
# headless, and close its window the way a user would (docs/ui.md, "The GPUI
# front end"): the equivalent of scripts/shots.sh for `voelin-gpui`.
#
# scripts/gpui-shot.sh <out.png> [<VOELIN_OPEN> [<width>x<height>]]
#
# The window opens on a display of its own, never the desktop's: the script
# runs itself again under `xvfb-run` (Debian, Ubuntu, the CI image) unless
# GPUI_SHOT_HEADLESS=1 says the caller already did that, as on NixOS:
#
# GPUI_SHOT_HEADLESS=1 spikes/gpui/shell.sh spikes/gpui/headless.sh -- \
# scripts/gpui-shot.sh docs/ui/gpui-swatch-dark.png swatch 1440x960
#
# Needs xdotool, xwd (x11-apps) and ImageMagick. The screen must be larger
# than the window (headless.sh's is 3840x2160; xvfb-run gets twice the window):
# on one as large as the window the window manager fits the window and its
# frame into the screen, and the picture is smaller than the size asked for.
#
# Wayland is taken out of the environment (GPUI prefers it, so the window
# would open on the desktop), and so are the desktop's session bus and its
# portals; the app's state and the XDG directories are a temporary one.
# GPUI needs a Vulkan driver or OpenGL at run time: on a machine without a
# GPU, Mesa's lavapipe (`mesa-vulkan-drivers`) draws in software. Without a
# window manager (xvfb-run alone) the window is stopped with TERM, with one
# (openbox, as headless.sh starts) it gets a close request, which is what the
# last line says.
#
# VOELIN_BIN: the binary (default target/release/voelin-gpui, else
# target/debug); DELAY: seconds the window is shown before the picture
# (default 4). VOELIN_DEV_THEME, VOELIN_FONT_SCALE, VOELIN_DEMO_UI (the sample
# servers: a picture of the shell with one on screen) and the other switches of
# `src/dev.rs` are passed on as set.
set -eu
out=${1:?usage: gpui-shot.sh <out.png> [<VOELIN_OPEN> [<width>x<height>]]}
open=${2:-}
size=${3:-1440x960}
w=${size%x*}
h=${size#*x}
if [ "${GPUI_SHOT_HEADLESS:-}" != 1 ]; then
command -v xvfb-run >/dev/null || {
echo "gpui-shot.sh: no xvfb-run; start a display of your own and set GPUI_SHOT_HEADLESS=1" >&2
exit 2
}
GPUI_SHOT_HEADLESS=1 exec xvfb-run -a -s "-screen 0 $((w * 2))x$((h * 2))x24" "$0" "$@"
fi
[ -n "${DISPLAY:-}" ] || { echo "gpui-shot.sh: no DISPLAY" >&2; exit 2; }
# ImageMagick 7 has `magick`; the 6 of Debian and Ubuntu has `convert` and `identify`.
if command -v magick >/dev/null 2>&1; then
to_png() { magick xwd:- "png:$1"; }
size_of() { magick identify -format '%wx%h' "$1"; }
else
to_png() { convert xwd:- "png:$1"; }
size_of() { identify -format '%wx%h' "$1"; }
fi
root=$(cd "$(dirname "$0")/.." && pwd)
bin=${VOELIN_BIN:-}
if [ -z "$bin" ]; then
target=${CARGO_TARGET_DIR:-$root/target}
for kind in release debug; do
[ -x "$target/$kind/voelin-gpui" ] && { bin=$target/$kind/voelin-gpui; break; }
done
fi
[ -x "$bin" ] || { echo "gpui-shot.sh: no voelin-gpui binary (cargo build -p voelin-gpui --release)" >&2; exit 2; }
work=$(mktemp -d)
trap 'kill ${pid:-} 2>/dev/null || true; rm -rf "$work"' EXIT INT TERM
mkdir -p "$work/runtime"
chmod 700 "$work/runtime"
env -u WAYLAND_DISPLAY -u WAYLAND_SOCKET -u XDG_SESSION_TYPE -u DBUS_SESSION_BUS_ADDRESS \
XDG_RUNTIME_DIR="$work/runtime" XDG_CONFIG_HOME="$work/config" XDG_DATA_HOME="$work/data" \
XDG_CACHE_HOME="$work/cache" XDG_STATE_HOME="$work/state" VOELIN_DATA_DIR="$work/data/voelin" \
GPUI_X11_SCALE_FACTOR=1 VOELIN_FFMPEG=0 \
VOELIN_OPEN="$open" VOELIN_WINDOW_SIZE="$size" \
"$bin" >"$work/app.log" 2>&1 &
pid=$!
i=0
# The title is the app's name, and ` - <server>` once a server is on screen.
until win=$(xdotool search --name '^Voelin( - |$)' 2>/dev/null | head -1) && [ -n "$win" ]; do
i=$((i + 1))
kill -0 "$pid" 2>/dev/null || { echo "gpui-shot.sh: the app ended before its window:" >&2; tail -20 "$work/app.log" >&2; exit 1; }
[ $i -lt 300 ] || { echo "gpui-shot.sh: no window after 30 s:" >&2; tail -20 "$work/app.log" >&2; exit 1; }
sleep 0.1
done
sleep "${DELAY:-4}"
xwd -id "$win" -silent | to_png "$out"
echo "$out: $(size_of "$out")"
# Close it as a user does; with no window manager, ask the process to end.
xdotool windowactivate --sync "$win" 2>/dev/null || true
xdotool key alt+F4 2>/dev/null || true
i=0
while kill -0 "$pid" 2>/dev/null; do
i=$((i + 1))
if [ $i -ge 30 ]; then
kill -TERM "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
echo "stopped with TERM (no window manager closed it)"
exit 0
fi
sleep 0.1
done
status=0
wait "$pid" || status=$?
echo "closed by the window manager, exit code $status"
exit "$status"