Files
cthulhu/STEAM_FOCUS.md
T
2026-12-01 03:18:50 -05:00

7.2 KiB

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.

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.

Big Picture overlays and notifications

Big Picture draws Quick Access (F2), the Steam menu (F1) and the power menu as separate Chromium frames inside its one X11 window. Each popup document is named <Name>_uid<n>, for example QuickAccess_uid2; the main view is Steam Big Picture Mode. Steam moves focus into these frames but never marks them active, so the normal active-frame check discarded their focus and Cthulhu kept reading the library.

The atspi adapter now accepts a focus gain in a showing Steam frame owned by the X11 foreground process, without changing the correlated foreground window. Steam closes a popup when focus leaves it, and browse-mode caret movement did exactly that, so popup documents start in focus mode and Steam keeps its own arrow navigation. A manual mode toggle still works.

Steam notification live regions are announced only inside toast popups (notificationtoasts_uid<n>-<id> or notificationtoasts_<id>_desktop). Live regions in page content, such as the store's events calendar, are no longer spoken as dozens of "Steam:" notifications. Notification and alert roles still work anywhere.

Big Picture maps keys to controller buttons: F1 Steam menu, F2 Quick Access, F3 or Backspace secondary, F4 options, F6 and F7 bumpers, F8 select, F9 start, Enter OK, Escape back. In Quick Access, Up and Down move between tabs and Right enters the tab's contents.

Verified live on 2026-12-01: F2, then Notifications, then Right reached the hardware survey notification and the survey was completed; the Steam menu items spoke in focus mode. Automated: TestSteamOverlayFocusMatchesForegroundProcessOnly, TestBrowserModeSteamPopupStartsInFocusMode, TestGamepadPopupDocument, TestToastDocument, and the native TestNativeWebScriptNotificationCapture. The toast restriction has not yet been checked against a real toast.

Popup documents are announced by name ("Quick Access", "Main Menu") rather than Steam's internal QuickAccess_uid2, and Quick Access tabs without an aria-label (Friends) are named from their quickaccess_tab_<n> id.

When Steam replaces page content, the remembered native focus can die before any navigation adopts it (its loading spinner after a popup closes). The review worker first recaptures the current document and keeps its reading place, including the caret offset. Only if that document is confirmed missing may it try another retained document of the same provider, within a two-document limit. Timeouts, stale captures and other refresh failures do not switch documents. This avoids navigating an older page when the current page merely removed a temporary focused object. Document start and end choose again once if their target died before placement. Automated checks cover recovery in the current document, caret-offset retention, failed refreshes, popup disappearance and document-start retries. The original popup recovery and start retry were checked live in Steam and ChatGPT on 2026-12-01; the current-document preference still needs live acceptance.

The web-widgets browser proof checks the narrow native-focus context's summary tag and the unnamed tab's ID on its focus event, as well as full document traits. Run it with CTHULHU_NATIVE_BROWSER_TESTS=web-widgets python3 tests/native_browser.py. These metadata checks do not establish audible tab naming in the live Steam client. After building, check F2, move to Friends, and confirm its name is spoken; close the popup and verify browse navigation resumes at the saved place in the main view.