Tk Source Code

View Ticket
Login
Ticket UUID: 25e7db2d8767ce2267d776b1e9464661983a3482
Title: Windows accessibility: with Narrator running, Tk applications stop responding for seconds after focus changes
Type: Bug Version: 9.1
Submitter: 0xjnml Created on: 2026-10-04 16:49:53
Subsystem: (unused) Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2026-10-05 01:40:35
Resolution: None Closed By: nobody
    Closed on:
Description:
With Narrator running on Windows 11, pressing Tab in a Tk window that has
check or radio buttons makes the window stop responding ("Not responding",
the window greyed out) for several seconds after most focus changes. It
recovers by itself; sometimes the focus then jumps back to the first
control. Reproduced with stock wish 9.1.0 built from the release tarball
(mingw-w64, static) and the attached narrator-repro.tcl: a ttk::button,
two ttk::entry, two ttk::checkbutton, two ttk::radiobutton, a ttk::label
and a text widget. Start Narrator, run "wish91s narrator-repro.tcl" and
press Tab a few times.

While the window does not respond, its main thread is not waiting but busy:
sampled every 0.5 s, its CPU time grows by about 0.6 s per 0.6 s.

The cause is a loop between TkRootAccessible_get_accChild and
ComputeAndCacheCheckedState in win/tkWinAccessibility.c:

- get_accChild clears and rebuilds the toplevel's child-ID table on every
  call (ClearChildIdTableForToplevel, AssignChildIdsRecursive).
- AssignChildIdsRecursive calls ComputeAndCacheCheckedState for every
  window, and for each check button, radio button and toggleswitch that
  caches the state and then always sends EVENT_OBJECT_VALUECHANGE and
  EVENT_OBJECT_STATECHANGE, whether or not anything changed.
- Narrator answers each of those events by fetching the object again,
  through get_accChild, which rebuilds the table and sends two more events
  for every check and radio button.

With a trace added to these functions, stock wish sent 319,480
value/state notifications in 166 s of tabbing through the window above
(four check and radio buttons), and get_accChild was called 79,866 times.

Proposed fix (08.patch): ComputeAndCacheCheckedState notifies only when the
cached state actually changed. With it, the same session sent 2
notifications in 104 s, the window never stopped responding, the focus
moved as expected, and Narrator read every control. We also checked it in an
application embedding Tk 9.1.0. Rebuilding the whole table on every
get_accChild call is costly in itself; the patch leaves that alone.

Found while reading the same file, not observed (no call in our traces came
from another thread): RunOnMainThreadSync and ExecuteOnMainThreadSync free
the queued event themselves. ExecuteOnMainThreadSync calls Tcl_Free(event)
and returns 1, after which Tcl_ServiceEvent reads evPtr->nextPtr and frees
the event again; RunOnMainThreadSync reads event->doneEvent after the main
thread may have freed it, and on a timeout frees the event while it is still
in the queue, then closes its handle twice.
User Comments: kevin_walzer added on 2026-10-05 01:40:35:
I have also corrected some stale reporting of check/radiobutton state in Windows.

kevin_walzer added on 2026-10-05 00:46:05:
Patch applied in the alt_x11_accessibility_fixes branch - please confirm it addresses the reported issue.

Attachments: