If the engine exits with an error (no window found, the Wayland share dialog cancelled, a capture tool missing), the game now goes on without Enhance and summit run says so; a normal engine exit still stops both. Checked on Plasma 6.8 with --window class:nothing. Found there too: --width 0 --height 0 made summit run 'kscreen-doctor output.HDMI-A-1.mode.0x0@60' (kscreen-doctor refused it; the monitor stayed as it was); zeros now mean not set. The stand-in test window can go fullscreen on a named monitor.
65 lines
2.8 KiB
Python
65 lines
2.8 KiB
Python
"""A stand-in game for testing window capture on Wayland: a native Wayland window (GLFW's Wayland backend) with
|
|
moving bars, that prints each key it gets and each focus change, so a test can tell whether the game still has the
|
|
keyboard with the engine's picture over it.
|
|
|
|
python devtools/wayland_standin.py [--seconds 60] [--size 1280x720] [--title "Summit stand-in"] [--fullscreen DP-1]
|
|
"""
|
|
import argparse
|
|
import sys
|
|
import time
|
|
|
|
import glfw
|
|
from OpenGL import GL
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--seconds", type=float, default=60)
|
|
ap.add_argument("--size", default="1280x720")
|
|
ap.add_argument("--title", default="Summit stand-in (native Wayland)")
|
|
ap.add_argument("--fullscreen", default="", metavar="MONITOR", help="fullscreen on the monitor of that name")
|
|
a = ap.parse_args()
|
|
w, h = map(int, a.size.split("x"))
|
|
glfw.init_hint(glfw.PLATFORM, glfw.PLATFORM_WAYLAND)
|
|
if not glfw.init():
|
|
print("glfw init failed", flush=True)
|
|
return 1
|
|
print("platform:", "wayland" if glfw.get_platform() == glfw.PLATFORM_WAYLAND else glfw.get_platform(), flush=True)
|
|
mon = next((m for m in glfw.get_monitors() if a.fullscreen and a.fullscreen in glfw.get_monitor_name(m).decode()), None)
|
|
if mon is not None:
|
|
mode = glfw.get_video_mode(mon)
|
|
w, h = mode.size.width, mode.size.height
|
|
win = glfw.create_window(w, h, a.title, mon, None)
|
|
glfw.make_context_current(win)
|
|
glfw.swap_interval(1)
|
|
keys = []
|
|
glfw.set_key_callback(win, lambda _w, key, _sc, action, _m: action == glfw.PRESS and (
|
|
keys.append(key), print(f"key {glfw.get_key_name(key, 0) or key} at {time.time():.3f}", flush=True)))
|
|
glfw.set_window_focus_callback(win, lambda _w, f: print(f"focus {'in' if f else 'out'} at {time.time():.3f}", flush=True))
|
|
t0, frames = time.perf_counter(), 0
|
|
GL.glEnable(GL.GL_SCISSOR_TEST)
|
|
while not glfw.window_should_close(win) and time.perf_counter() - t0 < a.seconds:
|
|
t = time.perf_counter() - t0
|
|
fw, fh = glfw.get_framebuffer_size(win)
|
|
GL.glScissor(0, 0, fw, fh)
|
|
GL.glClearColor(0.08, 0.1, 0.16, 1)
|
|
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
|
|
x = int((t * 400) % max(1, fw - 120)) # a bar sweeping across, 400 px a second
|
|
GL.glScissor(x, 0, 120, fh)
|
|
GL.glClearColor(0.9, 0.5, 0.1, 1)
|
|
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
|
|
for i in range(len(keys) % 20): # one green block per key received (up to 19)
|
|
GL.glScissor(20 + i * 50, fh - 60, 40, 40)
|
|
GL.glClearColor(0.2, 0.9, 0.3, 1)
|
|
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
|
|
glfw.swap_buffers(win)
|
|
glfw.poll_events()
|
|
frames += 1
|
|
print(f"{frames} frames in {time.perf_counter() - t0:.1f} s, {len(keys)} keys", flush=True)
|
|
glfw.terminate()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|