#!/usr/bin/env python3 """Drive the focus-routing gate: 3 windows, type markers, verify routing. Connects to the QEMU monitor once and keeps the socket open (the per-call scripts/sendkeys.py pattern loses the socket when the monitor resets). Usage: python3 scripts/test-focus.py /tmp/qmon.sock """ import socket import sys import time sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(sys.argv[1] if len(sys.argv) > 1 else "/tmp/sysboot-mon.sock") def sk(k, d=0.35): sock.sendall(f"sendkey {k}\n".encode()) time.sleep(d) def line(txt, d=0.8): for ch in txt: if ch == " ": sk("spc", 0.1) elif ch.isupper(): sk("shift-" + ch.lower(), 0.12) else: sk(ch, 0.12) sk("ret", d) time.sleep(0.5) # Home is focused at boot. line("windows") # expect: home + nothing (or existing windows) time.sleep(1.5) # F1 -> term1 (focused on creation) sk("f1", 1.5) line("echo TERM1MARK") time.sleep(1.0) # F1 -> term2 (focused on creation) sk("f1", 1.5) line("echo TERM2MARK") time.sleep(1.0) # F2 cycles z-order: term2 -> term1 sk("f2", 0.8) line("echo CYCLED") time.sleep(1.0) # F2 again: term1 -> home (window 0, oldest) sk("f2", 0.8) line("windows")