module ui_accesssource
Screen readers for pkg::alloy::ui (REFOCUS.md, R6f, question
3B): an app installs them, and from then on the platform's screen
readers see it, through the tree its widgets describe
(Widget::semantics).
import pkg::alloy::ui;
import pkg::alloy::ui_access as ui_access;
fn main() -> i32 {
return app(&WindowConfig::titled(&"Counter"), (ui) => {
ui_access::install(&var ui);
const count = ui.signal(0);
return ui.add(Button::text(&"Add one", (ui) => count.update(&var ui, (n) => n += 1)));
});
}
Installing lets the window's screen readers reach it (pkg::alloy::window's
install_access: AT-SPI on Linux, UI Automation on Windows,
NSAccessibility on macOS, the page's accessibility layer behind its
"Turn on accessibility" button); once one asks, each frame drawn sends
the window the nodes changed (access.alloy), fields and texts of
several lines with the maps screen readers read them by
(text_maps.alloy), and what screen readers ask comes back as the
elements' input. An app not installing them links none of it, and
screen readers find only a window.
## How it was built
Notes kept from each stage as it was finished, the sizes and numbers of their day; what changed since is in REVIEW.md and the history.
**R6f as built** (2026-10-26; REFOCUS.md, question 3B):
screen readers opt in, moved out of ui.
ui_access::install(&var ui)(the package importedas ui_access) installsAccess, an extension (ui's question 8A) holding whatUiheld: the nodes as last sent and the focus (sent,focus, fromaccess_sentandaccess_focus) and the text maps'revision(frommap_revision). ItseventtakesEvent::AccessRequested(the tree's start, everything laid out again with the maps, a frame asked for) andEvent::Action, which leftrunning.alloy; itsshow_incalls the window'sinstall_access, sends the tree's changes after a frame was drawn, asrunning.alloydid after rendering, and gives the window whatui.announcequeued; itstext_mapmakes the maps.ui.access_update()installs it when called, for tests.- Moved:
access.alloy(the walk, node ids, actions; 314 lines) andtext_maps.alloy(123) fromui, reaching the core through its inner modules'expnames (tree,events,scrolling,layers,extensions,fields' `text_map_of`, `languages`'spoken_languageandreading_flow). - What the core keeps:
Widget::semantics,partsand each widget's description, linked only where something walks them (this package, ui_app's forms and requests);ui.access_onandaccess_stale;Extension::text_mapwithTextLook, whichTextof several lines andTextFieldask whileaccess_on;ui.announce's queue, emptied after each event.ui.input_secret()readsTextField.secretrather than the semantics. Without the install the window's screen readers are never started: they find a window with nothing in it, and nothing announced is said. - Sizes, as
bench.shbuilds them: the counter 974,384 bytes natively and 671,036 of wasm with nothing installed (1,217,312 and 707,616 before); with screen readers (bench/access_counter.alloy,access_counter_native_bytes) 1,207,056 and 705,849: AT-SPI and text ranges 71 KB, the platform's part of it 37 KB, D-Bus 35 KB,ui's walk and descriptions 25 KB, std 17 KB, the words' tables 7.5 KB, this package 6.9 KB, Ryu's tables 10.7 KB, the settings portal 1.5 KB. - Tests (
tests.alloy, 13): the twelve ofui/tests.alloyreading the tree, its actions and the maps, installing first, and an app not installing that sends no tree, says nothing and takes no action though asked. ui_controls' and ui_app's tests import this package where they read the tree;tests/atspi,tests/automation,tests/readingandsamples/ticketsinstall it.
**F6a as built** (2026-10-13), the part ui_access holds since R6f (the rest in pkg::alloy::window's notes):
- Nothing is built until
AccessRequested; then each drawn frame walks the elements, compares each node with what was sent and sends those changed, gone, or the focus moved (access.alloy). The walk is every element per frame while a screen reader reads, which F6b can narrow to the elements renewed if it shows in the benchmarks. - Actions (
ui.access_action):Focusfocuses with the ring,ScrollIntoViewreveals,Clickis a click at the element's middle,IncrementandDecrementthe Up and Down keys, andSetValueandSetSelectioncome as the newInput::Action, whichSlider(a number) andTextFieldtake.
**F14b as built** (2026-10-20; decisions/F14.md, "Text for screen readers"), the part ui_access holds since R6f (the rest in pkg::alloy::ui's and pkg::alloy::window's notes):
- Maps (
text_maps.alloy, 5B, 6A): while a screen reader reads (ui.access_on), aTextFieldmakes itsTextMapas it is laid out and as its caret scrolls it (remap), kept inEditing.map, and aTextlaid out on more than one line keeps one inText.map(read only, a heading's said so);access.alloysends it with the node. Graphemes come from text's newLayout::graphemes_in_order, with the line breaks it draws nothing for at the end of their lines; words fromtext::word_starts; boxes at the Ui's scale; the format's family is the first face's PostScript name before its style, its language the Ui's. Each map takes the nextUi.map_revision, so the access walk sends a node again only when its map was made again: on an edit, a scroll or a new layout, never on a frame where nothing changed, and not during a composition (7A: the map before it, as the value). A secret field maps the dots it shows. The window asking for the tree lays everything out again, so maps exist from the first update. Never on the web (target()), whose browser reads its own elements.
fn installsource
exp fn install(ui: &var Ui)
Lets the platform's screen readers see the app, from now on.