atspi

package
v1.17.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atspi is the accessibility bridge for Linux desktops (SPEC §8.10): it mirrors the framework's semantics tree as AT-SPI2 objects on the accessibility bus, so that screen readers such as Orca can read the app and act on it.

The bridge is enabled only while a screen reader is on (the property org.a11y.Status.ScreenReaderEnabled of the session bus), so the semantics tree costs nothing otherwise. The model of the tree (model.go) and the mapping of roles and states (roles.go) do not touch the bus; the bridge (bridge.go) puts them on it.

Flutter: no counterpart (Flutter's accessibility bridge for Linux is the GTK embedder's)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge mirrors the semantics trees of the views as AT-SPI2 objects while a screen reader is on. Its methods are for the UI thread, except Close.

Flutter: no counterpart

func New

func New(opts Options) *Bridge

New creates a bridge that does nothing until Start.

Flutter: no counterpart

func (*Bridge) Close

func (b *Bridge) Close()

Close stops the bridge and takes the objects off the bus.

func (*Bridge) RemoveView

func (b *Bridge) RemoveView(view ui.ViewID)

RemoveView forgets the tree of a view that closed.

func (*Bridge) SetWindow

func (b *Bridge) SetWindow(view ui.ViewID, title string, active bool)

SetWindow tells the title of the window of the view, which names its frame, and whether it has the focus.

func (*Bridge) Start

func (b *Bridge) Start(ctx context.Context, host Host)

Start follows the screen reader flag of the session bus in the background, until ctx ends or Close is called. A desktop without the accessibility service is not an error: the bridge stays off (and says so in the debug log).

func (*Bridge) UpdateSemantics

func (b *Bridge) UpdateSemantics(view ui.ViewID, update *ui.SemanticsUpdate)

UpdateSemantics takes the changes of the semantics tree of a view.

type Change

type Change struct {
	Kind     ChangeKind
	Ref      NodeRef
	Parent   NodeRef
	Child    NodeRef
	Index    int
	State    State
	On       bool
	Property string
	Value    string
	Length   int
	Number   float64
}

Change is one change that Apply or the window setters made.

type ChangeKind

type ChangeKind int

ChangeKind says what a Change is.

const (
	// ChangeNodeAdded: a node appeared and has to be exported.
	ChangeNodeAdded ChangeKind = iota + 1
	// ChangeNodeRemoved: a node went away and has to be unexported.
	ChangeNodeRemoved
	// ChangeChildAdded: Child was added to the children of Parent, at Index. A Parent
	// with View -1 is the application.
	ChangeChildAdded
	// ChangeChildRemoved: Child was removed from the children of Parent, which had it at Index.
	ChangeChildRemoved
	// ChangeState: the state State of Ref is now On.
	ChangeState
	// ChangeProperty: the property Property ("accessible-name" or "accessible-description")
	// of Ref changed to Value.
	ChangeProperty
	// ChangeWindow: the window of View became active (On) or inactive.
	ChangeWindow
	// ChangeNodeUpdated: the node that exists was updated; its interfaces may have changed.
	ChangeNodeUpdated
	// ChangeText: Value was inserted (Property "insert") into the text of Ref at the
	// character Index, or deleted (Property "delete") from there; Length is the number
	// of characters.
	ChangeText
	// ChangeCaret: the caret of the text of Ref is now at the character Index.
	ChangeCaret
	// ChangeTextSelection: the selected part of the text of Ref changed.
	ChangeTextSelection
	// ChangeValue: the numeric value of Ref is now Number.
	ChangeValue
	// ChangeVisibleData: the position or the size of Ref changed.
	ChangeVisibleData
	// ChangeSelection: the selected children of Ref changed.
	ChangeSelection
)

The kinds of change.

type Extents

type Extents struct{ X, Y, Width, Height int32 }

Extents is a rectangle in pixels of the window.

func (Extents) Contains

func (e Extents) Contains(x, y int32) bool

Contains says whether the point is in the rectangle.

type Host

type Host interface {
	// ScreenReaderChanged tells that a screen reader started or stopped: the framework
	// then produces the semantics tree, or stops.
	ScreenReaderChanged(enabled bool)
	// PerformAction asks the framework to perform an action of a node, the request of
	// the assistive technology.
	PerformAction(event ui.SemanticsActionEvent)
}

Host is what the bridge needs of the app. The bridge calls it on the UI thread (through Options.Post).

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is the mirror of the semantics trees of the views of the app. It does not touch the bus: Apply says what changed, and the bridge turns that into events. A Model is not safe for concurrent use; the bridge locks it.

func NewModel

func NewModel() *Model

NewModel creates an empty model.

func (*Model) Apply

func (m *Model) Apply(view ui.ViewID, update *ui.SemanticsUpdate) []Change

Apply takes an update of the tree of a view and returns what changed. Nodes that the update leaves unreachable from the root are removed, as the engine does.

func (*Model) Children

func (m *Model) Children(n *Node) []NodeRef

Children are the refs of the children of the node, in traversal order; those that the tree does not have are left out.

func (*Model) Extents

func (m *Model) Extents(n *Node) Extents

Extents is the rectangle of the node in the pixels of its window: the rectangle of the node in its own coordinates, moved by the transforms of the node and of its ancestors up to the root (whose transform has the device pixel ratio).

func (*Model) HitTest

func (m *Model) HitTest(n *Node, x, y int32) *Node

HitTest is the deepest node under the point (in the pixels of the window) that is under the node, or nil. A hidden node and its children are not hit; the last children are tried first, as they are on top.

func (*Model) Name

func (m *Model) Name(n *Node) string

Name is the name of the node: its label; the frame of a window has the title of the window when it has no label.

func (*Model) Node

func (m *Model) Node(ref NodeRef) *Node

Node returns a node, or nil.

func (*Model) RemoveView

func (m *Model) RemoveView(view ui.ViewID) []Change

RemoveView forgets the tree of a view that closed and says what that changed.

func (*Model) Role

func (m *Model) Role(n *Node) Role

Role is the role of the node.

func (*Model) SetWindow

func (m *Model) SetWindow(view ui.ViewID, title string, active bool) []Change

SetWindow sets the title and whether the window of the view has the focus. The title is the name of the frame. It says what that changed.

func (*Model) States

func (m *Model) States(n *Node) StateSet

States are the states of the node.

func (*Model) Views

func (m *Model) Views() []ui.ViewID

Views are the views that have a tree, in the order of their IDs.

type Node

type Node struct {
	ui.SemanticsNodeUpdate
	// View is the view of the node.
	View ui.ViewID
	// Parent is the ID of the parent, or -1 for the root.
	Parent int
}

Node is a node of the mirrored tree: what the framework last said about it.

func (*Node) Ref

func (n *Node) Ref() NodeRef

Ref names the node.

type NodeRef

type NodeRef struct {
	View ui.ViewID
	ID   int
}

NodeRef names a node of a view.

func (NodeRef) IsApp

func (r NodeRef) IsApp() bool

IsApp says whether the ref is the application root.

type Options

type Options struct {
	// AppName is the name of the application, as the screen reader says it.
	AppName string
	// Version is the version of the toolkit; it defaults to "1.0".
	Version string
	// Post runs a function on the UI thread, from any goroutine. It is required.
	Post func(func())
	// OpenSession connects to the session bus; nil is dbus.Connect.
	OpenSession func(ctx context.Context) (dbus.Bus, error)
	// OpenA11y connects to the accessibility bus at the address that the session bus
	// gives; nil is dbus.ConnectAddress.
	OpenA11y func(ctx context.Context, address string) (dbus.Bus, error)
	// WindowOrigin is where the window is on the screen, for the coordinates of the
	// screen. Wayland does not tell, and the default is the origin.
	WindowOrigin func(view ui.ViewID) (x, y int)
	// Getenv reads the environment (for the locale); nil is os.Getenv.
	Getenv func(string) string
	// Logger gets the debug messages; nil is slog.Default().
	Logger *slog.Logger
}

Options are the parameters of New.

type Role

type Role uint32

Role is an AT-SPI2 role (AtspiRole of atspi-constants.h). Only the roles that the mapping uses are named.

const (
	RoleInvalid           Role = 0
	RoleAcceleratorLabel  Role = 1
	RoleAlert             Role = 2
	RoleAnimation         Role = 3
	RoleCheckBox          Role = 7
	RoleCheckMenuItem     Role = 8
	RoleColumnHeader      Role = 10
	RoleComboBox          Role = 11
	RoleDialog            Role = 16
	RoleFiller            Role = 20
	RoleFrame             Role = 23
	RoleImage             Role = 27
	RoleLabel             Role = 29
	RoleList              Role = 31
	RoleListItem          Role = 32
	RoleMenu              Role = 33
	RoleMenuBar           Role = 34
	RoleMenuItem          Role = 35
	RolePageTab           Role = 37
	RolePageTabList       Role = 38
	RolePanel             Role = 39
	RolePasswordText      Role = 40
	RoleProgressBar       Role = 42
	RolePushButton        Role = 43
	RoleRadioButton       Role = 44
	RoleRadioMenuItem     Role = 45
	RoleScrollBar         Role = 48
	RoleScrollPane        Role = 49
	RoleSeparator         Role = 50
	RoleSlider            Role = 51
	RoleSpinButton        Role = 52
	RoleStatusBar         Role = 54
	RoleTable             Role = 55
	RoleTableCell         Role = 56
	RoleTableColumnHeader Role = 57
	RoleText              Role = 61
	RoleToggleButton      Role = 62
	RoleToolTip           Role = 64
	RoleTree              Role = 65
	RoleWindow            Role = 69
	RoleHeader            Role = 71
	RoleFooter            Role = 72
	RoleParagraph         Role = 73
	RoleApplication       Role = 75
	RoleEntry             Role = 79
	RoleDocumentFrame     Role = 82
	RoleHeading           Role = 83
	RoleSection           Role = 85
	RoleForm              Role = 87
	RoleLink              Role = 88
	RoleTableRow          Role = 90
	RoleListBox           Role = 98
	RoleGrouping          Role = 99
	RoleNotification      Role = 101
	RoleLandmark          Role = 110
	RoleStatic            Role = 116
)

The roles that the mapping gives to nodes.

func (Role) Name

func (r Role) Name() string

Name is the English name of the role, such as "push button".

type State

type State uint32

State is an AT-SPI2 state (AtspiStateType): the number of a bit in the 64 bits of the two words that GetState returns.

const (
	StateActive         State = 1
	StateChecked        State = 4
	StateCollapsed      State = 5
	StateEditable       State = 7
	StateEnabled        State = 8
	StateExpandable     State = 9
	StateExpanded       State = 10
	StateFocusable      State = 11
	StateFocused        State = 12
	StateHasTooltip     State = 13
	StateModal          State = 16
	StateMultiLine      State = 17
	StateSelectable     State = 22
	StateSelected       State = 23
	StateSensitive      State = 24
	StateShowing        State = 25
	StateSingleLine     State = 26
	StateVisible        State = 30
	StateIndeterminate  State = 32
	StateRequired       State = 33
	StateInvalidEntry   State = 36
	StateSelectableText State = 38
	StateCheckable      State = 41
	StateReadOnly       State = 43
)

The states that the mapping sets.

func (State) Name

func (s State) Name() string

Name is the name of the state in the events, such as "focused".

type StateSet

type StateSet uint64

StateSet is a set of states.

func (StateSet) Has

func (s StateSet) Has(st State) bool

Has says whether the set has the state.

func (StateSet) With

func (s StateSet) With(st State) StateSet

With returns the set with the state added.

func (StateSet) Words

func (s StateSet) Words() []uint32

Words are the two 32-bit words of the set, as GetState returns them: the low word has the states 0 to 31.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL