Recursive AI

Enable AT-SPI accessibility in a C# desktop app

OneApp is a free, open-source framework for apps in .NET whose UI is HTML and CSS, drawn natively with no web view on Windows, macOS, Linux, iOS and Android, and run in the browser, from Recursive AI. MIT or Apache-2.0, no native DLLs to ship.

The sample has one button, Save note. On Linux, set AccessibilityMode.On to expose it through AT-SPI, the interface screen readers such as Orca use. On desktop, OneApp runs on Linux (Wayland and X11), macOS (Apple silicon), and Windows.

The accessibility bus comes from at-spi2-core and is normally available in GNOME or KDE sessions. On Xvfb, we used dbus-run-session so D-Bus could start org.a11y.Bus on demand.

Terminal
dotnet add package RecursiveAI.OneApp

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneApp;
 
using var host = AppHost.Create(
    new AppOptions(
        "<button>Save note</button>")
    {
        Title = "Accessible Notes",
        Accessibility = AccessibilityMode.On
    });
host.AccessibilityStatusChanged += status =>
    Console.WriteLine(status.State);
host.Run();

Checked on Linux (X11), when the bridge connects:

Text
Active

Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.

Keep the window open. In a second terminal in the same graphical session, run the included inspect_button.py with Python 3, PyGObject and the AT-SPI introspection bindings installed (python3-gi and gir1.2-atspi-2.0 on Debian or Ubuntu):

Terminal
python3 inspect_button.py

The script reads a live accessible object, not the HTML file:

PYTHON
import gi
import time
 
gi.require_version('Atspi', '2.0')
from gi.repository import Atspi
 
 
def find(node):
    is_button = (node.get_role() ==
                 Atspi.Role.PUSH_BUTTON)
    if is_button:
        if node.get_name() == 'Save note':
            return node
    count = node.get_child_count()
    for index in range(count):
        child = node.get_child_at_index(index)
        if child and (match := find(child)):
            return match
    return None
 
 
Atspi.init()
for _ in range(20):
    button = find(Atspi.get_desktop(0))
    if button:
        role = button.get_role_name()
        print(f'{role}: {button.get_name()}')
        break
    time.sleep(0.25)
else:
    raise SystemExit('Button not found')

With English role names, the client prints:

Text
button: Save note

If the bridge reports Unavailable, read host.AccessibilityStatus.Reason to distinguish a missing session or accessibility bus from a connection failure. Setting On doesn’t create those buses.

Variations

For normal desktop use, let the desktop signal when it wants the bridge by changing the Accessibility setting in Program.cs:

C#
Accessibility = AccessibilityMode.Auto

Auto is the default. It can stay in Waiting until the desktop enables accessibility; use On to check what the app exports without relying on that preference.

The short answer

Set AppOptions.Accessibility to AccessibilityMode.On when creating the host. Keep host.Run() active and inspect the window from an AT-SPI client in the same Linux session. An active bridge confirms the connection; finding button: Save note confirms the role and name the client can actually read.

How do I turn on accessibility mode in a Linux app?

Use Auto if the app should follow the user’s desktop accessibility settings. In this mode OneApp watches the desktop’s IsEnabled and ScreenReaderEnabled flags and registers once either is true. On registers whenever the accessibility bus is available. Off doesn’t connect at all. These settings control what the app exports; they don’t start a screen reader or change anyone’s desktop preference.

Read the status after the event loop has had a chance to connect. Logging AccessibilityStatusChanged on the UI thread shows transitions instead of taking a single snapshot right after startup. In a desktop session where the accessibility bus is missing, you can still see the app window, but the client won’t see the exported controls.

How can I tell what a screen reader sees on Linux?

Inspect the live tree, not just the markup. OneApp exports windows and their page trees with roles, names, descriptions and states. The example uses a real <button> so its role comes from the element and its visible text supplies its name. The script walks the desktop tree, matches both role and name, and prints the match. For a fuller inspection, use an interactive AT-SPI client and open your app’s window node to see its controls.

A matching name and role is a useful first check, not a guarantee that a whole view is usable. For a form, also inspect the names of controls without visible text, watch focus move as you tab, and check that each control has the state you expect when it’s disabled or selected. The OneApp accessibility docs list the events and actions exported by the bridge.

All oneapp recipes