Files
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

31 lines
2.0 KiB
Plaintext

import ctypes as c, re, sys, time, os
from pathlib import Path
# Only the Xwayland display created by this specific hidden test process.
log=Path(sys.argv[1]);assert log.parent.name.startswith('err-held-pages-')
text=log.read_text(errors='replace');match=re.search(r'Starting Xwayland on (:\d+)',text);assert match
name=match[1];assert name!=os.environ.get('DISPLAY')
x=c.CDLL('libX11.so.6');t=c.CDLL('libXtst.so.6');P=c.c_void_p;U=c.c_ulong
x.XOpenDisplay.argtypes=[c.c_char_p];x.XOpenDisplay.restype=P
x.XKeysymToKeycode.argtypes=[P,U];x.XKeysymToKeycode.restype=c.c_uint
x.XFlush.argtypes=[P];x.XCloseDisplay.argtypes=[P]
t.XTestFakeKeyEvent.argtypes=[P,c.c_uint,c.c_int,U];t.XTestFakeKeyEvent.restype=c.c_int
d=x.XOpenDisplay(name.encode());assert d
x.XDefaultRootWindow.argtypes=[P];x.XDefaultRootWindow.restype=U
x.XQueryTree.argtypes=[P,U,c.POINTER(U),c.POINTER(U),c.POINTER(c.POINTER(U)),c.POINTER(c.c_uint)]
x.XFetchName.argtypes=[P,U,c.POINTER(c.c_char_p)]
x.XSetInputFocus.argtypes=[P,U,c.c_int,U];x.XFree.argtypes=[P]
root=x.XDefaultRootWindow(d);r=U();parent=U();children=c.POINTER(U)();n=c.c_uint()
x.XQueryTree(d,root,c.byref(r),c.byref(parent),c.byref(children),c.byref(n))
for i in range(n.value):
title=c.c_char_p();x.XFetchName(d,children[i],c.byref(title));caption=title.value.decode(errors='replace') if title.value else ''
if 'World Editor' in caption or 'WorldEditor' in caption:
x.XSetInputFocus(d,children[i],2,0);x.XFlush(d);print('Private test keyboard target:',caption,flush=True)
if title:x.XFree(title)
x.XFree(children)
sequence={'Right':[0xff53],'w':[ord('w')],'enter':[0xff0d],'Down':[0xff54],'m':[ord('m')],'page':[0xffb3,0xffb7,0xff0d],'index':[0xffb0,0xff8d]}[sys.argv[2]]
for key in sequence * (int(sys.argv[3]) if len(sys.argv)>3 else 1):
code=x.XKeysymToKeycode(d,key);assert code
assert t.XTestFakeKeyEvent(d,code,1,0);x.XFlush(d);time.sleep(.6 if sys.argv[2] in ('w','Right') else .09)
assert t.XTestFakeKeyEvent(d,code,0,0);x.XFlush(d);time.sleep(.14)
x.XCloseDisplay(d)