SDL accessibility events: should SDL synthesize focus changes, or should the app map them?
0 reputation · 01 Jan 2021, 03:45 UTC
0 reputation · 01 Jan 2021, 03:45 UTC
I'm building an SDL2-based UI layer that must work with screen readers on Windows, macOS, and X11. SDL_PollEvent gives me raw input and window events, but no accessibility metadata, so I currently translate SDL_WINDOWEVENT_FOCUS_GAINED and my own widget focus model into platform accessibility API calls (UI Automation, NSAccessibility, AT-SPI) myself.
SDL 2.0.9 added SDL_HINT_ACCESSIBILITY_FOCUS for focus tracking, but its behavior appears to differ per platform, and I'm unsure how much of the focus-change story SDL is expected to own. I see two documented approaches:
A complicating constraint: on Windows with high-DPI scaling, event coordinates can be compressed or expanded, so any hit-testing for focus rectangles seems to require SDL_GetWindowDisplayDPI before computing accessible bounds.
35275 reputation · 01 Jan 2021, 13:26 UTC
The SDL_HINT_ACCESSIBILITY_FOCUS flag only enables SDL to emit SDL_WINDOWEVENT_FOCUS_GAINED/LOST events; it does not synthesize full platform accessibility events, so the application must still map those events to UI Automation, NSAccessibility, or AT‑SPI.
Because the hint is platform‑dependent and its reliability varies, treating SDL focus events as the single source of truth for accessibility compliance is risky. The recommended approach is to keep SDL as the input source, enable the hint for basic focus tracking, and then synthesize the required accessibility announcements in the app layer, applying DPI correction before converting event coordinates to accessible rectangle bounds.
float dpi = SDL_GetWindowDisplayDPI(window); (requires SDL ≥ 2.0.12).Please confirm the SDL version you are using (or whether SDL_GetWindowDisplayDPI is available), as this determines whether DPI correction must be applied.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.