diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 530631c79..5388960e0 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -41,6 +41,7 @@ object SessionFiles { "libblfastpath.so" to "usr/local/lib/libblfastpath.so", "libssbs.so" to "usr/local/lib/libssbs.so", "usr/local/bin/droiddeck-session" to "usr/local/bin/droiddeck-session", + "usr/local/bin/droiddeck-xwindows" to "usr/local/bin/droiddeck-xwindows", "usr/local/bin/steam-compatibility" to "usr/local/bin/steam-compatibility", "usr/local/bin/droiddeck-clipboard" to "usr/local/bin/droiddeck-clipboard", "usr/local/bin/droiddeck-steam-install" to "usr/local/bin/droiddeck-steam-install", diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index a699dc33c..1b5ac44c4 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -516,6 +516,26 @@ case $mode in v=${v# } echo "${v:-$2}" } + # What gamescope had to choose from when focus moved, and again as late windows map: + # the apps and windows it counts as focusable (window, app id, pid; on the client's + # server, for every server), the one it picked, and the client's base-layer order; then + # each server's top-level windows with the app id they carry (STEAM_GAME) and their + # WM_STATE (droiddeck-xwindows). A game window that opens behind the client and never + # takes focus shows here as missing from the focusable list, or listed with no app id. + focus_snapshot() { + local d + echo "== focus state (after $1 at $2s):" \ + $(xprop -root GAMESCOPE_FOCUSED_APP GAMESCOPE_FOCUSED_WINDOW GAMESCOPE_FOCUSABLE_APPS \ + GAMESCOPE_FOCUSABLE_WINDOWS GAMESCOPECTRL_BASELAYER_APPID 2>/dev/null | sed 's/(CARDINAL)//' | tr '\n' ' ') + for d in $(bl_displays); do droiddeck-xwindows "$d" 2>/dev/null; done + } + focus_snapshots() { + local at=0 t + for t in 0 5 15 30; do + nap $((t - at)); at=$t + focus_snapshot "$1" "$t" + done + } tmode= app= xprop -spy -root STEAM_TOUCH_CLICK_MODE GAMESCOPE_FOCUSED_APP 2>/dev/null | while read -r line; do case $line in @@ -530,6 +550,7 @@ case $mode in [ "$v" = "$app" ] && continue app=$v echo "== focused app: $app (touch mode ${tmode:-unset}) at $(date +%T)" + focus_snapshots "$app" & ;; esac done diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-xwindows b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xwindows new file mode 100755 index 000000000..af06247bb --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-xwindows @@ -0,0 +1,117 @@ +#!/usr/bin/python3 +# The top-level windows of one Xwayland server, one line each, for the session log: what gamescope +# had to pick focus from. Each line has the window, whether it is mapped, override-redirect, its +# geometry, the app id it carries (STEAM_GAME, which gamescope focuses by), its WM_STATE, pid and +# class. Windows that are neither mapped nor tagged with an app id are left out - wine keeps many +# hidden ones. The rootfs has xprop but no xwininfo, so this speaks the X protocol itself. +# +# droiddeck-xwindows :1 +import os +import socket +import struct +import sys + +MAP_STATE = ("unmapped", "unviewable", "viewable") +WM_STATES = {0: "Withdrawn", 1: "Normal", 3: "Iconic"} + + +class X: + def __init__(self, display): + num = display.lstrip(":").split(".")[0] + self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.s.settimeout(2) + self.s.connect("/tmp/.X11-unix/X" + num) + self.s.sendall(struct.pack(" 1 else os.environ.get("DISPLAY", ":0") + try: + x = X(display) + except OSError as e: + print("== %s: %s" % (display, e)) + return + atoms = {name: x.atom(name) for name in ("STEAM_GAME", "WM_STATE", "_NET_WM_PID", "WM_CLASS")} + for win in x.children(x.root): + attrs = x.attributes(win) + if not attrs: + continue + game = x.prop(win, atoms["STEAM_GAME"]) + if attrs[0] != 2 and not game: + continue + geo = x.geometry(win) + state = x.prop(win, atoms["WM_STATE"]) + pid = x.prop(win, atoms["_NET_WM_PID"]) + cls = x.prop(win, atoms["WM_CLASS"]) + print("== %s window 0x%x: %s%s %s app %s state %s pid %s class %s" % ( + display, win, MAP_STATE[attrs[0]] if attrs[0] < 3 else attrs[0], + " override-redirect" if attrs[1] else "", + "%dx%d+%d+%d" % (geo[2], geo[3], geo[0], geo[1]) if geo else "?", + game[0] if game else "-", + WM_STATES.get(state[0], state[0]) if state else "-", + pid[0] if pid else "-", + cls.split(b"\0")[-2].decode(errors="replace") if cls and b"\0" in cls else "-", + )) + + +main()