Files
cthulhu/STEAM_FOCUS.md

68 lines
3.8 KiB
Markdown

# Steam keyboard focus on Xorg
Steam Big Picture can retain its accessible focus while physical keyboard
events reach the outer Steam window instead of its embedded Chromium window.
In the reported game/workspace round trip, Escape stopped opening or closing
the menu, and switching browse/focus mode did not help. A delivery trace showed
both Escape edges reaching the outer window with no held modifiers. Restoring
native focus to the browser child recovered the open menu without restarting
Steam or Cthulhu. The original trigger remains unverified.
Cthulhu's Xorg command owner remembers the most recently focused, mapped
browser child of a Steam webhelper window. During the first second after that
window becomes foreground again, it allows Steam to restore its own focus.
Only if two consecutive focus samples still identify the outer window does it
attempt to restore the remembered child. A successful repair ends the attempt
for that activation.
The repair verifies the foreground window, Steam window class, process IDs,
child ancestry, and mapping state immediately before changing focus. It leaves
valid inner focus alone, including menus, search fields, and dialogs. It does
not run with keys held, reader modal input active, OCR active or pending, or
secure input active. Hidden, destroyed, unrelated, or unverified targets cause
it to leave focus unchanged. It does not guess another child or retain a
hard-coded window ID. The cache holds one Steam window and expires with the
command listener; restarting Cthulhu in an already broken session may require
fresh Steam focus before a valid child can be remembered.
This is an Xorg Steam workaround. Other applications and native Wayland focus
handling do not receive automatic keyboard-focus changes.
## Verification
The policy tests cover activation grace, remembered popup focus, bounded
attempts, process/window boundaries, and preservation of valid browser focus.
The native fixture verifies real Escape press/release delivery after repair and
rejects hidden or destroyed popups, unrelated children, changed process IDs,
held modifiers, other applications, and ordinary window classes.
```sh
GOCACHE=/tmp/cthulhu-go-cache GOPROXY=off go test -race ./internal/platform/xorg ./internal/app -count=1
xvfb-run -a env CTHULHU_NATIVE_STEAM_FOCUS=1 GOCACHE=/tmp/cthulhu-go-cache GOPROXY=off go test ./internal/platform/xorg -run '^TestNativeSteamFocusRepair$' -count=1 -v
CTHULHU_NATIVE_BROWSER_TESTS=keys,modes python3 tests/native_browser.py
python3 tests/native_x11.py
```
These checks passed for the initial patch. The existing native browser editing
check failed on both the patch and unchanged commit `9205e72`: its first typed
`c` was accompanied by `Cthulhu Browser Probe - Brave`. That separate title
announcement failure was not changed here.
Human review and live Steam acceptance remain required before submission:
1. Restart Cthulhu using the normal `cthulhu-go.sh -r` launcher, then start fresh
Steam Big Picture so the reader can observe a valid browser focus.
2. Verify Escape and game activation initially work. Launch a game, switch to
another workspace and back, and verify Escape and game activation again.
3. Repeat with the Steam menu open before switching away. Check Escape closes
it and arrows/Enter still select commands.
4. Type in Steam search, use Tab and Shift+Tab, and move away/back while search
or a dialog has focus. Check text entry, selection, and dialog buttons retain
their intended focus.
5. Switch to a normal browser and a GTK application. Check native typing,
browser structural navigation, and Cthulhu's XTerm/Fenrir handoff. Quit
Cthulhu and confirm normal application keys remain available.
Do not count a native fixture pass as audible speech, physical Braille, or
successful operation of Steam's actual Chromium/controller navigation.