#!/usr/bin/env python3 """Live regression probe; run inside a running Gamescope session. Requires Python 3, WAYLAND_DISPLAY, XDG_RUNTIME_DIR and access to Gamescope's /proc//fd. Creates only a temporary surface with the cursor role; it does not take pointer focus or change game/save files. Affected Gamescope retains all 20 SHM allocations; fixed Gamescope retains at most the current cursor buffer. """ import os import socket import struct import time import json import array import argparse from pathlib import Path def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--unassigned-control', action='store_true', help='verify that window buffers awaiting association remain queued') args = parser.parse_args() s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.settimeout(2) s.connect(os.path.join(os.environ['XDG_RUNTIME_DIR'], os.environ['WAYLAND_DISPLAY'])) U = lambda *v: struct.pack('<' + 'I' * len(v), *v) def string(v): b = v.encode() + b'\x00' return U(len(b)) + b + b'\x00' * (-len(b) % 4) def send(obj, op, p=b'', fd=None): b = U(obj, len(p) + 8 << 16 | op) + p if fd is None: s.sendall(b) else: s.sendmsg([b], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array('i', [fd]))]) nextid = 2 pids = [] for process in Path('/proc').iterdir(): if not process.name.isdigit(): continue try: if (process / 'comm').read_text().strip() == 'gamescope': pids.append(process) except (FileNotFoundError, PermissionError): pass assert len(pids) == 1, f'expected one Gamescope process, found {[p.name for p in pids]}' fd_dir = pids[0] / 'fd' def alloc(): nonlocal nextid nextid += 1 return nextid pending = b'' globals = {} def roundtrip(): nonlocal pending cb = alloc() send(1, 0, U(cb)) while True: while len(pending) >= 8: obj, h = struct.unpack_from('> 16 op = h & 65535 if len(pending) < n: break p = pending[8:n] pending = pending[n:] if obj == 1 and op == 0: raise RuntimeError('wayland error ' + repr(p)) if obj == 2 and op == 0: name, l = struct.unpack_from('