Replay browse keys when native focus leaves the document window

This commit is contained in:
Storm Dragon committed 2026-11-19 04:27:39 -05:00
1 parent 938847e6ae
commit 58d8f6bee1
7 files changed
+386 -2

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
# Browse keys during native focus transitions
Browse-only keys require both the recorded foreground client and native X11
input focus to belong to the document's window. A delayed `_NET_ACTIVE_WINDOW`
update must not let an old document consume typing in another window, including
another window of the browser's own process. The real grabbed event is replayed
to the focused application when ownership cannot be established.
Native focus inside a document's child windows retains browse navigation.
Verified GTK input-only grab windows retain their existing owner resolution:
the mapped transient popup, window group, and process metadata must agree.
Global reader commands keep their existing routing.
## Automated verification
```sh
python3 tests/native_test_session.py env GOWORK=off GOCACHE=/tmp/cthulhu-cache GOTMPDIR=/tmp CTHULHU_NATIVE_X11=1 go test ./internal/platform/xorg -run '^TestNativeBrowseFocusRouting$' -count=1 -v
CTHULHU_NATIVE_BROWSER_TESTS=focus-routing,keys,find,modes,menu,document python3 tests/native_browser.py
CTHULHU_FIREFOX_FIND=1 python3 tests/native_firefox.py
```
The browser menu proof requires Brave. The focused routing proof needs
`python-xlib`, as do the existing X11 window-group fixtures.
The routing fixture uses a private X11 connection and XTest events. It changes
input focus and sends keys in one server-grabbed batch, keeping the reader's
browse policy fixed to represent delayed accessibility updates. Application
receipt of an unbound F12 release is the ordered completion marker. Assertions
compare every received press/release and every reader command, checking for
lost, duplicated, misrouted, or incorrectly consumed input.
Cases include another window with current and stale EWMH state, returning to
the document before accessibility updates, child windows, input-only popup
grabs, and focus without an EWMH active-window property. The original code
consumed H, K, Right, and Return in the other window when EWMH still named the
document; this regression requires all eight events to reach that window.
These checks cover native key routing. They do not establish recovery from a
frozen reader process, kernel keyboard delivery, audible speech, or Braille.
## Verification results
On 2026-11-19, all ten routing cases passed five consecutive runs. The normal
`native_x11.py` command-listener selection, including the new test, passed with
a race-instrumented test binary. Input package tests, focused browser/document
app race tests, Xorg/input `go vet`, and Xorg package lint passed. Chromium and
Firefox Find, and Brave menu, document, key-transition, and mode checks passed.
The initial Brave mode run missed a Braille routing frame at
`document_native_test.go:965`. An isolated rerun with the original keyboard C
source through a Go overlay passed, and an isolated rerun with the fix passed.
The first failure remains unexplained. The complete app race run exceeded its
180-second total budget while constructing a Tentacle archive fixture; it is
not a full-suite pass. A direct bare-Xvfb run also failed
`TestNativeActiveWindowIsXTerm`, which is outside the normal harness selection
and expects EWMH active-window metadata. The intended native harness passed.
The subsequent pre-push review passed the complete `go test -race ./...` suite
with a 300-second per-package timeout, full `go vet` and lint, the native X11
listener selection, Firefox Find, and the clipboard, application chooser,
speech-history and voice-profile helper checks. Brave focus routing, key
transitions, Find, menus, document commands, dynamic and ticking navigation
passed. The Braille-frame failure at line 965 reproduced on unchanged commit
`8cc2931`, confirming that it also occurs without these changes. Another mode
run missed chrome key echo after Ctrl+L. Two later mode runs with the pending
changes passed; the intermittent failures remain unexplained.
## Live verification
After reviewing and building the change, switch rapidly between a webpage and
another window, including another window of the same browser. Check heading
and arrow navigation on the page, ordinary typing and Return elsewhere, and
return to browse navigation. Check Ctrl+F typing, browser menus, and native
buttons. Repeat with the physical keyboard and normal window manager; confirm
spoken output and Braille separately. No running reader is replaced by the
automated checks.