Slice 1 of plan section 6 step 3 (docs/ui.md, "The GPUI front end"). The window
is the shell of ui/shells/desktop.slint, as entities that observe the root
state and tell the window only when what they show changed (they compare their
view of the state, so an engine event about a talker, a tick or a setting that
is not the theme's draws nothing):
- shell/rail.rs: the saved servers as avatars with their tints, initials,
presence dots, unread and live marks, the selection pill and ring, the plus
that adds a server and the settings button; a second click edits a server,
as the Slint rail's double click does.
- shell/sidebar.rs: the server on screen with its stats, the place of the
channel tree (slice 2), the voice card (disconnect, copy an invite, hold to
talk) while voice is connecting or connected, and the user card with the
microphone and sound buttons.
- shell/topbar.rs: the page's title, the search box and the settings button;
the last two are logged until their slices exist.
- shell/main_panel.rs: "No server selected" with the way to add one, or the
server on screen with Connect, Disconnect and Edit.
- shell/form.rs: the server form (address, name, nickname, password; Save,
Save and connect, Cancel, and a Remove that asks twice) in the place of the
main area until the dialogs slice.
- shell/toast.rs: the status line as a toast for a few seconds.
The eleven callbacks of bind/servers.rs that the shell has are GPUI actions
(shell/actions.rs: select, connect, disconnect, mute the microphone, mute the
sound, push to talk, edit, save, save and connect, delete, invite): a click
dispatches one, the window's root view handles it by asking the root state.
The window takes its title from the server on screen ("Voelin - Nightfall"),
keeps a focus of its own so that actions always find their handlers, tells the
root state where it is (ui.window), and opens where it was left (the size
always; the position where a screen still shows it and the window manager
honours one). The logo is served by the assets.
scripts/gpui-shot.sh finds the window by its title's prefix now that the title
follows the server.
Tests on GPUI's test platform draw the window and click it: a server added
appears in the rail, a click selects it and titles the window, a connect
reaches the engine, an engine event updates the rail and the cards, the form
adds, edits and removes, the toast goes, the window's place round-trips, an
idle window is not told, the sample servers fill the shell.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
102 lines
4.3 KiB
Bash
Executable File
102 lines
4.3 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.
|
|
#
|
|
# 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"
|