Tk Source Code

View Ticket
Login
Ticket UUID: 3b2c972f29b66f213a505b214c83c9927bf08efe
Title: X11 accessibility: a screen reader announces every widget twice when it gets the focus
Type: Bug Version: 9.1
Submitter: anonymous Created on: 2026-10-03 17:30:40
Subsystem: (unused) Assigned To: kevin_walzer
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-11 01:30:12
Resolution: Fixed Closed By: kevin_walzer
    Closed on: 2026-10-11 01:30:12
Description:
With Orca running, pressing Tab through a Tk 9.1 window on X11 makes Orca
announce each widget twice, once right after the other.

The ATK bridge follows every focus change with an
"active-descendant-changed" signal on the parent of the focused widget, in
four places in unix/tkUnixAccessibility.c: tk_grab_focus(),
RegisterWidgetRecursive(), UpdateAtkFocusChain() and
TkAtkAccessible_FocusHandler(). That signal is meant for containers that
manage their own items (lists, trees, tables, menus). A screen reader
presents the new "active descendant" when it receives it, so the widget it
has just announced for the focus event is announced again. The parents
here are ordinary frames and toplevels.

Reproducer: the attached repro.tcl (a ttk::button, ttk::entry,
ttk::checkbutton and ttk::label in a ttk::frame). Start Orca, run
"wish9.1 repro.tcl" and press Tab.

AT-SPI events for each focus change, stock 9.1.0 ("repro.tcl -tour", X11,
Tk built with the ATK bridge; the "unknown" source is the ttk::frame):

    object:state-changed:focused       on button 'Button'
    object:active-descendant-changed   on unknown '' -> button 'Button'
    object:state-changed:focused       on entry 'Entry'
    object:active-descendant-changed   on unknown '' -> entry 'Entry'
    object:state-changed:focused       on unknown 'Checkbutton'
    object:active-descendant-changed   on unknown '' -> unknown 'Checkbutton'

Proposed fix (01.patch): emit "active-descendant-changed" only when the
parent's role is list, list box, tree, tree table, table, menu or menu bar.
With it each focus change produces only the focus event:

    object:state-changed:focused       on button 'Button'
    object:state-changed:focused       on entry 'Entry'
    object:state-changed:focused       on unknown 'Checkbutton'

and Orca announces each widget once. We heard both the doubling and the
fix with Orca 48.1 (AT-SPI 2.56.2), in an application embedding Tk 9.1.0,
on a Debian 13 based amd64 system with MATE on X11.

Attachments: repro.tcl, 01.patch
User Comments: kevin_walzer added on 2026-10-11 01:30:12:
Merged fixes to trunk.

0xjnml added on 2026-10-07 20:40:32:
Confirmed with Orca 48.1 on a MATE desktop at [30d3e9a7b7]: tabbing
through the entry, check, radio and ttkbut demos of the widget demo, each
control is announced once ("Dismiss button.", "Safety Check check box
not checked."), where stock 9.1.0 announces each one twice. The script
and the details are on 74d973b49d.

As Serhiy noted, the window still has no parent: an AT-SPI client reads
the parent of the demo's toplevel as None (stock 9.1.0: None; with his
one-line fix: the application). In my earlier tests the parent fix alone
made Orca 48.1 silent, because Orca then requires the window to report
ATK_STATE_ACTIVE. The branch now reports that state, and the two work
together: with his line added to RegisterToplevelWindow (the
alt-toplevel-parent.patch attached on 74d973b49d), Orca still reads each
control once, and each window's title is announced once when it opens
instead of three times.

serhiy.storchaka added on 2026-10-05 12:28:20:

Confirmed in alt_x11_accessibility_fixes: each focus change now produces only one object:state-changed:focused, without active-descendant-changed. The toplevel accessible still has no parent, so the second change from my previous comment (atk_object_set_parent() for toplevels) is still needed for Orca's flat review.


kevin_walzer added on 2026-10-05 00:56:26:
This has been addressed in the alt_x11_accessibility_fixes branch - please confirm it works as expected.

serhiy.storchaka added on 2026-10-04 10:45:30:

Confirmed with Orca 50.2. Orca reacts to the extra event because the toplevel accessible has no parent: Orca cannot find the window of the focused widget, drops its focus after the announcement, and takes the following active-descendant-changed as a new focus. Setting the parent alone also removes the doubling, and makes Orca's flat review work:

--- unix/tkUnixAccessibility.c
+++ unix/tkUnixAccessibility.c
@@ -1107,6 +1107,7 @@
     if (Tk_IsTopLevel(tkwin)) {
 	parentAcc = tk_root_accessible;
 
+	atk_object_set_parent(accessible, parentAcc);
 	if (!g_list_find(toplevel_accessible_objects, accessible)) {
 	    toplevel_accessible_objects = g_list_append(toplevel_accessible_objects, accessible);
 	    gint index = g_list_index(toplevel_accessible_objects, accessible);

01.patch is right nevertheless, so both changes are worth applying.


Attachments: