#!/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-win32-input.sh - Typed-character acceptance gate for the Win32 port. # Runs KEYS.EXE under Wine (scripts/lib/wineGate.sh) at one window pixel per # stage pixel (JOEYLIB_SCALE=1, JOEYLIB_ASPECT=square), types the RetroNet # definition-of-done string with xdotool (real X key events through XTEST, # which Wine turns into WM_KEYDOWN/WM_CHAR), grabs the window, and decodes # the example's verification scanline (row 198) with tests/gate/keysRow.c. # Then the named keys a second key gives (scripts/lib/keysGate.sh): the # keypad's arrows and Enter, and the right Ctrl and Alt (the key messages' # extended bit), read off KEYS's cells (tests/gate/keysCells.c). # # Usage: scripts/verify-win32-input.sh # Requires: Wine (install.sh install emulator:win32), Xvfb, xdotool, # ImageMagick; build/win32/bin/KEYS.EXE # (make win32). set -euo pipefail repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) source "$repo/scripts/lib/joeyEnv.sh" source "$repo/scripts/lib/wineGate.sh" source "$repo/scripts/lib/keysGate.sh" label=verify-win32-input wineNeed target="192.168.1.10:6510" program=$(joeyExampleProgram keys win32) [ -f "$program" ] || { echo "$label: build KEYS.EXE first (make win32)" >&2; exit 2; } work=$(mktemp -d -t "joeylib-win32-input.XXXXXX") cleanup() { wineStop rm -rf "$work" } trap cleanup EXIT wineStart "$work" JOEYLIB_SCALE=1 JOEYLIB_ASPECT=square wineRun "$program" win=$(wineWindow KEYS) || { echo "$label: FAIL - KEYS window not found" >&2; exit 1; } sleep 2 xdotool windowfocus --sync "$win" xdotool type --delay 150 -- "$target" sleep 2 import -window "$win" "$work/keys.png" # The window's client area at one pixel a pixel: the row must be exactly at # (0,198) of the stage, wherever Wine put the client area in the grab. found=$("$(joeyTool keysRow)" "$work/keys.png" "$target" --scale 1) || { echo "$found"; echo "$label: FAIL" >&2; exit 1; } echo "$found" [[ "$found" =~ row\ at\ \(([0-9]+),([0-9]+)\) ]] stageAt="${BASH_REMATCH[1]},$((BASH_REMATCH[2] - 198))" # X's names for the keys (scripts/lib/keysGate.sh's). declare -A xKey=([up]=Up [kp8]=KP_Up [kp2]=KP_Down [kp4]=KP_Left [kp6]=KP_Right [kpenter]=KP_Enter [rctrl]=Control_R [ralt]=Alt_R) KEYS_LABEL=$label keysPress() { xdotool keydown "${xKey[$1]}" } keysRelease() { xdotool keyup "${xKey[$1]}" } keysRead() { import -window "$win" "$work/cells.png" "$(joeyTool keysCells)" "$work/cells.png" --at "$stageAt" } keysRunSteps kp8 kp2 kp4 kp6 kpenter rctrl ralt if [ -n "$KEYS_FAILS" ]; then echo "$label: FAIL - $KEYS_FAILS" >&2 exit 1 fi echo "$label: PASS (typed \"$target\", all ${#target} chars arrived via jlInputGetChar; $KEYS_STEPS named-key steps: the keypad's arrows and Enter, right Ctrl and Alt, Up held with its second key)"