joeylib2/scripts/verify-sdl3-icon.sh

54 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# verify-sdl3-icon.sh - an SDL3 program's icon on its window.
#
# make bakes every SDL3 program's icon into it (make/sdl3.mk: tools/iconBake.py
# c, SDL3_ICON_SIZE pixels square), and the backend gives it
# SDL_SetWindowIcon (HOSTED_WINDOW_ICON). DRAW (examples/draw) runs on a
# private Xvfb display through SDL's X11 driver, which hands the icon to X
# as the window's _NET_WM_ICON; that must be the program's picture as
# iconBake.py fits it (scripts/lib/netWmIcon.py).
#
# Usage: scripts/verify-sdl3-icon.sh
# Exit: 0 PASS, 1 FAIL, 2 SKIP (DRAW not built)
# Requires: Xvfb, xdotool, xprop, python3 + PIL; build/sdl3/bin/DRAW
# (make sdl3).
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
label=verify-sdl3-icon
program=$(joeyExampleProgram draw sdl3)
[ -x "$program" ] || { echo "$label: build DRAW first (make sdl3)" >&2; exit 2; }
# The picture DRAW's icon is baked from, and the size, as make has them.
read -r picture size < <(make -s -f "$repo/make/sdl3.mk" --eval 'iconOf: ; @echo $(call programIcon,DRAW) $(SDL3_ICON_SIZE)' iconOf)
work=$(mktemp -d -t joeylib-sdl3-icon.XXXXXX)
displayNum=$((RANDOM % 500 + 300))
cleanup() {
joeyStop "${drawPid:-}"
[ -n "${xvfbPid:-}" ] && kill "$xvfbPid" 2>/dev/null
rm -rf "$work"
}
trap cleanup EXIT
python3 "$repo/tools/iconBake.py" png "$picture" "$work/want.png" "${size}x${size}"
Xvfb ":$displayNum" -screen 0 1024x768x24 -nolisten tcp >/dev/null 2>&1 &
xvfbPid=$!
sleep 1
DISPLAY=":$displayNum" SDL_VIDEO_DRIVER=x11 SDL_AUDIO_DRIVER=dummy "$program" >"$work/draw.log" 2>&1 &
drawPid=$!
sleep 3
win=$(joeyFindWindow ":$displayNum" "$drawPid") || true
if [ -z "$win" ]; then
echo "$label: FAIL - DRAW's window not found" >&2
exit 1
fi
DISPLAY=":$displayNum" xprop -id "$win" -f _NET_WM_ICON 32c ' = $0+' _NET_WM_ICON > "$work/icon.txt" 2>&1
python3 "$repo/scripts/lib/netWmIcon.py" "$work/icon.txt" "$work/want.png" "$size" "$label"