diff --git a/README.md b/README.md index 3276674..4da08c3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Cthulhu is a Linux screen reader written in Go. - [Contributing](CONTRIBUTING.md): development, accessibility verification, licensing, and the AI-assisted contribution policy. - [LibreOffice support](LIBREOFFICE_SUPPORT.md): integration boundaries, initial Calc behavior, remaining work, and verification. - [Progress reporting](PROGRESS_BARS.md): web progress bars, Steam shader processing, and verification. -- [Steam keyboard focus](STEAM_FOCUS.md): Xorg workspace focus recovery and verification. +- [Steam keyboard focus](STEAM_FOCUS.md): Xorg workspace focus recovery, Big Picture overlays, notifications and verification. - [XTerm handoff](docs/testing/xterm-handoff.md): terminal reader keys, lock state, speech interruption, and verification. - [Graphical terminals](docs/testing/graphical-terminals.md): repaint coalescing, editing feedback, title animation, and verification. - [Messaging support](docs/testing/messaging.md): Pidgin and Mumble message review/copy shortcuts, application boundaries, and verification. diff --git a/STEAM_FOCUS.md b/STEAM_FOCUS.md index 37e0562..ed3e0cc 100644 --- a/STEAM_FOCUS.md +++ b/STEAM_FOCUS.md @@ -65,3 +65,41 @@ Human review and live Steam acceptance remain required before submission: 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 `_uid`, 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-` or `notificationtoasts__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. + +Known remaining issue: when Steam replaces page content (for example the +RECOMMENDED tab), browse-mode navigation can fail with "Could not find +current location" because the remembered native focus no longer exists and +`DocumentCursor.syncFocus` does not fall back to the reading place. diff --git a/internal/app/browser_mode.go b/internal/app/browser_mode.go index 98fac3b..eff6b84 100644 --- a/internal/app/browser_mode.go +++ b/internal/app/browser_mode.go @@ -15,6 +15,7 @@ import ( "git.stormux.org/storm/cthulhu/internal/input" "git.stormux.org/storm/cthulhu/internal/review" "git.stormux.org/storm/cthulhu/internal/sound" + "git.stormux.org/storm/cthulhu/internal/webscripts" ) type documentContextCapturer interface { @@ -52,6 +53,7 @@ type browserModeController struct { cancel context.CancelFunc done chan struct{} document atspi.ObjectID + focusProcess string // provider process of the latest native focus navigation atspi.ObjectID navigationDocument atspi.ObjectID navigationFocus atspi.ObjectID @@ -240,6 +242,11 @@ func (browser *browserModeController) accept(result browserModeResult, speech sp browser.mutex.Unlock() browser.state = review.DocumentModeState{} browser.state.SetSticky(browser.stickyModes[browser.document.BusName]) + // Steam popups own their arrow keys and close when focus leaves. + // Start them in focus mode; a manual toggle still clears this. + if browser.state.Sticky() == review.InactiveMode && gamepadPopupDocument(browser.focusProcess, result.owner) { + browser.state.SetSticky(review.FocusMode) + } } browser.ready = true modeInput := runtimeModeInput(result.owner) @@ -247,6 +254,16 @@ func (browser *browserModeController) accept(result browserModeResult, speech sp mode := browser.state.Update(modeInput, browser.modeSettings()) browser.set(mode, speech, false) } +func gamepadPopupDocument(process string, owner atspi.DocumentContext) bool { + document := owner.TopLevel.ID() + for _, ancestor := range owner.Ancestors { + if ancestor.ID() == document { + return webscripts.GamepadPopupDocument(process, ancestor.Name) + } + } + return false +} + func (browser *browserModeController) modeSettings() review.ModeSettings { if browser.settings != nil { return browser.settings() diff --git a/internal/app/browser_mode_test.go b/internal/app/browser_mode_test.go index 7227e96..29cd219 100644 --- a/internal/app/browser_mode_test.go +++ b/internal/app/browser_mode_test.go @@ -806,3 +806,56 @@ func TestStructuralNavigationAutomaticFocus(t *testing.T) { }) } } + +func steamDocumentContext(t *testing.T, documentPath, documentName string) atspi.DocumentContext { + t.Helper() + button := atspi.Snapshot{BusName: ":1.42", Path: documentPath + "/button", Role: "button", StatesKnown: true, Focusable: true} + doc := atspi.Snapshot{BusName: ":1.42", Path: documentPath, Name: documentName, Role: "document web", StatesKnown: true} + tree, err := atspi.NewAccessibleTree(doc.ID(), []atspi.TreeNode{{Snapshot: doc, Children: []atspi.ObjectID{button.ID()}}, {Snapshot: button}}) + if err != nil { + t.Fatal(err) + } + ref, _ := tree.Reference(button.ID()) + owner, err := tree.DocumentContext(ref) + if err != nil { + t.Fatal(err) + } + return owner +} + +func TestBrowserModeSteamPopupStartsInFocusMode(t *testing.T) { + keys := &modeKeys{} + browser := newBrowserModeController(nil, keys, nil) + queue := &fakeSpeechQueue{spoken: make(chan string, 16)} + main := steamDocumentContext(t, "/main", "Steam Big Picture Mode") + popup := steamDocumentContext(t, "/popup", "QuickAccess_uid2") + browser.focusProcess = "steamwebhelper" + + browser.follow(main.Ancestors[0].ID()) + browser.accept(browserModeResult{focus: main.Ancestors[0].ID(), generation: 1, owner: main}, queue) + if browser.mode != review.BrowseMode || !keys.enabled { + t.Fatalf("main Big Picture view mode = %v, want browse", browser.mode) + } + browser.follow(popup.Ancestors[0].ID()) + browser.accept(browserModeResult{focus: popup.Ancestors[0].ID(), generation: 2, owner: popup}, queue) + if browser.mode != review.FocusMode || keys.enabled { + t.Fatalf("Quick Access mode = %v, want focus so Steam keeps its arrow keys", browser.mode) + } + browser.toggle(queue) + if browser.mode != review.BrowseMode { + t.Fatal("manual toggle could not leave focus mode in a Steam popup") + } + browser.follow(main.Ancestors[0].ID()) + browser.accept(browserModeResult{focus: main.Ancestors[0].ID(), generation: 3, owner: main}, queue) + if browser.mode != review.BrowseMode { + t.Fatalf("returning to the main view kept mode %v", browser.mode) + } + + other := newBrowserModeController(nil, &modeKeys{}, nil) + other.focusProcess = "chrome" + other.follow(popup.Ancestors[0].ID()) + other.accept(browserModeResult{focus: popup.Ancestors[0].ID(), generation: 1, owner: popup}, queue) + if other.mode != review.BrowseMode { + t.Fatalf("non-Steam document named like a popup got mode %v", other.mode) + } +} diff --git a/internal/app/event_navigation_filters.go b/internal/app/event_navigation_filters.go index 26aa87d..0e30874 100644 --- a/internal/app/event_navigation_filters.go +++ b/internal/app/event_navigation_filters.go @@ -82,6 +82,7 @@ func (handler *accessibilityEventHandler) filterNavigationAndNames(event atspi.E } if browser != nil && isFocusEvent(event.Type) && !ownedAutocompletePopup(event) { browser.nativeButtonFocus(isFocusGainEvent(event) && (event.Source.Role == "button" || event.Source.Role == "push button" || event.Source.Role == "toggle button")) + browser.focusProcess = event.Source.ApplicationProcess browser.follow(event.Source.ID()) } else if browser != nil && event.Type == atspi.CaretEvent && !event.Source.Editable { browser.followCaret(event.Source.ID()) diff --git a/internal/atspi/adapter_event_callback_native.go b/internal/atspi/adapter_event_callback_native.go index a610da0..277022b 100644 --- a/internal/atspi/adapter_event_callback_native.go +++ b/internal/atspi/adapter_event_callback_native.go @@ -312,6 +312,10 @@ func (adapter *Adapter) enrichNativeWindowEvent(event *C.AtspiEvent, target *C.A focusEvent.ForegroundMismatch = !adapter.matchForeground(target, window, focusEvent.Window, &focusEvent.ForegroundCheck, false) } else { focusEvent.ForegroundMismatch = !adapter.matchForeground(target, window, focusEvent.Window, nil, focusedMenuItem) + if focusEvent.ForegroundMismatch && (eventType == FocusEvent || eventType == FocusedStateEvent) && snapshot.Focused && + adapter.matchSteamOverlayFocus(window) { + focusEvent.ForegroundMismatch = false + } } if !focusEvent.ForegroundMismatch && window != nil && (eventType == WindowActivatedEvent || snapshot.Role == "table" || snapshot.Role == "table cell") { diff --git a/internal/atspi/adapter_event_filter_native.go b/internal/atspi/adapter_event_filter_native.go index b868f7c..f5218a6 100644 --- a/internal/atspi/adapter_event_filter_native.go +++ b/internal/atspi/adapter_event_filter_native.go @@ -9,6 +9,8 @@ package atspi */ import "C" +import "git.stormux.org/storm/cthulhu/internal/webscripts" + // Reject routine background updates before resolving a selected descendant or // capturing text, attributes, values and geometry. Global lifecycle events and // supported notifications retain their existing handling. No new ownership is @@ -61,6 +63,10 @@ func (adapter *Adapter) filterNativeBackgroundEvent(event *C.AtspiEvent, eventTy if adapter.matchForeground(event.source, window, windowID, nil, focusedMenuItem) { return false } + if (eventType == FocusEvent || eventType == FocusedStateEvent && event.detail1 != 0) && + adapter.matchSteamOverlayFocus(window) { + return false + } if origin.BusName == adapter.foregroundWindow.BusName { // Browser suggestions and tooltips can occupy a different top-level // without taking X11 focus. Preserve their existing event-loop checks; @@ -83,3 +89,26 @@ func (adapter *Adapter) filterNativeBackgroundEvent(event *C.AtspiEvent, eventTy } return true } + +// matchSteamOverlayFocus checks fresh frame state for a Steam overlay focus +// gain. It never changes the correlated foreground window: the main Big +// Picture frame keeps that role and reclaims focus when the overlay closes. +func (adapter *Adapter) matchSteamOverlayFocus(window *C.AtspiAccessible) bool { + if window == nil { + return false + } + process := adapter.applicationProcess(window) + if webscripts.MatchProcess(process) != webscripts.Steam { + return false + } + pid := adapter.foregroundProcessID(int(C.atspi_accessible_get_process_id(window, nil))) + C.atspi_accessible_clear_cache_single(window) + states := C.atspi_accessible_get_state_set(window) + if states == nil { + return false + } + showing := C.atspi_state_set_contains(states, C.ATSPI_STATE_SHOWING) != 0 + iconified := C.atspi_state_set_contains(states, C.ATSPI_STATE_ICONIFIED) != 0 + C.g_object_unref(C.gpointer(states)) + return steamOverlayFocusMatches(adapter.Foreground().Client, process, pid, true, showing, iconified) +} diff --git a/internal/atspi/foreground.go b/internal/atspi/foreground.go index 3e4fe27..7f79538 100644 --- a/internal/atspi/foreground.go +++ b/internal/atspi/foreground.go @@ -9,6 +9,7 @@ import ( "slices" "git.stormux.org/storm/cthulhu/internal/platform/xorg" + "git.stormux.org/storm/cthulhu/internal/webscripts" ) // The native caller supplies a complete, fresh, bounded application window @@ -37,6 +38,16 @@ func preferencesForegroundMatches(client xorg.Foreground, pid int, preferencesPI int64(pid) == preferencesPID && client.PID == pid } +// Steam Big Picture draws overlays such as Quick Access and the main menu as +// separate Chromium frames inside its one X11 window. Steam moves focus into +// them but never marks their frame active, so the normal active-frame check +// discards that focus. Accept only a confirmed focus gain in a showing frame +// owned by the X11 foreground process itself. +func steamOverlayFocusMatches(client xorg.Foreground, process string, pid int, focusGain, showing, iconified bool) bool { + return focusGain && showing && !iconified && webscripts.MatchProcess(process) == webscripts.Steam && + client.Known && client.Window != 0 && client.PID > 0 && pid == client.PID +} + func foregroundWindowMatches(client xorg.Foreground, pid int, bounds Rectangle) bool { if client.PID > 0 && pid > 0 && client.PID != pid { return false diff --git a/internal/atspi/foreground_test.go b/internal/atspi/foreground_test.go index 6572e2d..fc01d6b 100644 --- a/internal/atspi/foreground_test.go +++ b/internal/atspi/foreground_test.go @@ -216,3 +216,30 @@ func TestForegroundWindowReplacement(t *testing.T) { }) } } + +func TestSteamOverlayFocusMatchesForegroundProcessOnly(t *testing.T) { + client := xorg.Foreground{Known: true, Window: 83886130, PID: 111, Width: 1920, Height: 1080} + if !steamOverlayFocusMatches(client, "steamwebhelper", 111, true, true, false) { + t.Fatal("Quick Access focus in the foreground Steam process was rejected") + } + cases := map[string]struct { + client xorg.Foreground + process string + pid int + focusGain, showing, iconified bool + }{ + "other application": {client, "chrome", 111, true, true, false}, + "other process": {client, "steamwebhelper", 222, true, true, false}, + "not a focus gain": {client, "steamwebhelper", 111, false, true, false}, + "hidden overlay": {client, "steamwebhelper", 111, true, false, false}, + "iconified overlay": {client, "steamwebhelper", 111, true, true, true}, + "no foreground window": {xorg.Foreground{Known: true, PID: 111}, "steamwebhelper", 111, true, true, false}, + "unknown foreground": {xorg.Foreground{Window: 83886130, PID: 111}, "steamwebhelper", 111, true, true, false}, + "unknown foreground pid": {xorg.Foreground{Known: true, Window: 83886130}, "steamwebhelper", 0, true, true, false}, + } + for name, test := range cases { + if steamOverlayFocusMatches(test.client, test.process, test.pid, test.focusGain, test.showing, test.iconified) { + t.Errorf("%s: accepted Steam overlay focus", name) + } + } +} diff --git a/internal/atspi/webscripts_native.go b/internal/atspi/webscripts_native.go index 85b8425..04d4993 100644 --- a/internal/atspi/webscripts_native.go +++ b/internal/atspi/webscripts_native.go @@ -93,9 +93,15 @@ func (adapter *Adapter) webNotification(event *C.AtspiEvent) *webscripts.Notific C.g_object_unref(C.gpointer(ancestor)) } }() + documentName, documentFound := "", false for current := C.web_ref(source); current != nil; { ancestors = append(ancestors, current) role := C.atspi_accessible_get_role(current, nil) + if role == C.ATSPI_ROLE_DOCUMENT_WEB && !documentFound { + name := C.atspi_accessible_get_name(current, nil) + documentName, documentFound = C.GoString(name), true + C.g_free(C.gpointer(name)) + } candidate := webscripts.NotificationCandidate{} switch role { case C.ATSPI_ROLE_NOTIFICATION: @@ -116,7 +122,7 @@ func (adapter *Adapter) webNotification(event *C.AtspiEvent) *webscripts.Notific current = C.atspi_accessible_get_parent(current, nil) } index := webscripts.NotificationRoot(candidates) - if index < 0 { + if index < 0 || candidates[index].Role == "" && !webscripts.ToastDocument(documentName) { return nil } root := ancestors[index] diff --git a/internal/version/version.go b/internal/version/version.go index 82e974c..0f189d7 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -21,7 +21,7 @@ import "strings" const Name = "Cthulhu" -const Version = "2026.11.24" +const Version = "2026.12.01" const Channel = "testing" var Build = Version diff --git a/internal/webscripts/steam.go b/internal/webscripts/steam.go index 3337d0b..1816c3f 100644 --- a/internal/webscripts/steam.go +++ b/internal/webscripts/steam.go @@ -16,6 +16,10 @@ const steamNotificationDelay = 500 * time.Millisecond var steamRelativeTime = regexp.MustCompile(`(?i)^(?:just now|now|\d+\s+(?:second|minute|hour|day|week|month|year)s?\s+ago)$`) +// Steam names each Big Picture popup browser "_uid", for +// example QuickAccess_uid2. The main view is "Steam Big Picture Mode". +var steamPopupDocument = regexp.MustCompile(`^[A-Za-z][A-Za-z0-9]*_uid\d+$`) + var steamShaderProgress = regexp.MustCompile(`^Processing Vulkan shaders \((\d{1,3})%\)$`) // ShaderProgress recognizes Steam's English shader status, which Chromium @@ -33,6 +37,20 @@ func ShaderProgress(processName, eventType, role, name string) (float64, bool) { return float64(percentage), err == nil && percentage <= 100 } +// GamepadPopupDocument reports a Steam Big Picture popup, such as Quick Access +// or the main menu. Steam drives these with its own arrow-key navigation and +// closes them when focus leaves, so browse-mode caret movement dismisses them. +func GamepadPopupDocument(processName, documentName string) bool { + return MatchProcess(processName) == Steam && steamPopupDocument.MatchString(strings.TrimSpace(documentName)) +} + +// ToastDocument reports Steam's toast popup, named notificationtoasts_uid- +// in Big Picture and notificationtoasts__desktop otherwise. Live regions +// elsewhere, such as the store's event calendar, are page content, not toasts. +func ToastDocument(documentName string) bool { + return strings.HasPrefix(strings.TrimSpace(documentName), "notificationtoasts_") +} + // NotificationRoot mirrors Python's Steam root selection: notification/alert // ancestors take precedence over inherited live-region attributes on a leaf. // Candidates are ordered from the event source towards its application root. diff --git a/internal/webscripts/steam_test.go b/internal/webscripts/steam_test.go index 0a02554..2c084f1 100644 --- a/internal/webscripts/steam_test.go +++ b/internal/webscripts/steam_test.go @@ -145,3 +145,32 @@ func TestSteamNotificationDeduplicationAndOwnership(t *testing.T) { t.Fatalf("reset presented pending content: %q", got) } } + +func TestGamepadPopupDocument(t *testing.T) { + for _, name := range []string{"QuickAccess_uid2", "MainMenu_uid12", " QuickAccess_uid2 "} { + if !GamepadPopupDocument("steamwebhelper", name) { + t.Errorf("%q was not a Steam popup", name) + } + } + for _, name := range []string{"Steam Big Picture Mode", "Steam", "", "QuickAccess_uid", "Quick Access_uid2"} { + if GamepadPopupDocument("steamwebhelper", name) { + t.Errorf("%q was treated as a Steam popup", name) + } + } + if GamepadPopupDocument("chrome", "QuickAccess_uid2") { + t.Error("another browser's document was treated as a Steam popup") + } +} + +func TestToastDocument(t *testing.T) { + for _, name := range []string{"notificationtoasts_uid2-41", "notificationtoasts_41_desktop"} { + if !ToastDocument(name) { + t.Errorf("%q was not a toast document", name) + } + } + for _, name := range []string{"Steam Big Picture Mode", "QuickAccess_uid2", ""} { + if ToastDocument(name) { + t.Errorf("%q was treated as a toast document", name) + } + } +}