Attachment "02.patch" to
ticket [74d973b4]
added by
anonymous
2026-10-03 17:34:23.
--- a/unix/tkUnixAccessibility.c
+++ b/unix/tkUnixAccessibility.c
@@ -71,6 +71,18 @@
/* Variables for managing ATK objects. */
static AtkObject *tk_root_accessible = NULL;
+
+/*
+ * The main window, for naming the application object by [tk appname]; reset
+ * when the main window is destroyed.
+ */
+static Tk_Window mainWindow = NULL;
+static void MainWindowEventProc(TCL_UNUSED(void *), XEvent *eventPtr)
+{
+ if (eventPtr->type == DestroyNotify) {
+ mainWindow = NULL;
+ }
+}
static GList *toplevel_accessible_objects = NULL;
static GHashTable *tk_to_atk_map = NULL;
extern Tcl_HashTable *TkAccessibilityObject;
@@ -484,28 +496,53 @@
if (!win) return NULL;
AtkRole role = GetAtkRoleForWidget(win);
+
+ /*
+ * The Windows and macOS bridges present the "description" attribute as
+ * the accessible name (accName, accessibilityLabel) and "help" as the
+ * hint; the class bindings in accessibility.tcl put the visible text in
+ * "description" and the role word in "name". Do the same here, so a
+ * button reads "Save, push button" rather than "Button, push button,
+ * Save". "name" remains the fallback (toplevels keep their title there).
+ */
+ Tcl_HashEntry *hPtr = Tcl_FindHashEntry(TkAccessibilityObject, (char *)win);
+ Tcl_HashTable *attrs = hPtr ? (Tcl_HashTable *)Tcl_GetHashValue(hPtr) : NULL;
+ if (attrs) {
+ Tcl_HashEntry *descEntry = Tcl_FindHashEntry(attrs, "description");
+ if (descEntry) {
+ const char *desc = Tcl_GetString((Tcl_Obj *)Tcl_GetHashValue(descEntry));
+ if (desc && desc[0]) return g_utf8_make_valid(desc, -1);
+ }
+ }
+
/* If label, return the value instead of the name so Orca does not say "label" twice. */
if (role == ATK_ROLE_LABEL) {
return GetAtkValueForWidget(win);
}
- Tcl_HashEntry *hPtr = Tcl_FindHashEntry(TkAccessibilityObject, (char *)win);
- if (!hPtr) return NULL;
-
- Tcl_HashTable *attrs = (Tcl_HashTable *)Tcl_GetHashValue(hPtr);
if (!attrs) return NULL;
Tcl_HashEntry *nameEntry = Tcl_FindHashEntry(attrs, "name");
if (!nameEntry) return NULL;
const char *name = Tcl_GetString((Tcl_Obj *)Tcl_GetHashValue(nameEntry));
- return name ? g_utf8_make_valid(name, -1) : NULL;
+ if (!name) return NULL;
+
+ /*
+ * The class bindings default "name" to the role word ("Entry", "Scale");
+ * the screen reader announces the role itself, so that is no name.
+ */
+ Tcl_HashEntry *roleEntry = Tcl_FindHashEntry(attrs, "role");
+ if (roleEntry && strcmp(name, Tcl_GetString((Tcl_Obj *)Tcl_GetHashValue(roleEntry))) == 0) {
+ return NULL;
+ }
+ return g_utf8_make_valid(name, -1);
}
static const gchar *tk_get_name(AtkObject *obj)
{
if (obj == tk_root_accessible) {
- return "Tk Application";
+ return mainWindow ? Tk_Name(mainWindow) : "Tk Application";
}
TkAtkAccessible *acc = (TkAtkAccessible *)obj;
@@ -532,7 +569,8 @@
Tcl_HashTable *attrs = (Tcl_HashTable *)Tcl_GetHashValue(hPtr);
if (!attrs) return NULL;
- Tcl_HashEntry *descriptionEntry = Tcl_FindHashEntry(attrs, "description");
+ /* The ATK description is the hint: "help", as on Windows and macOS. */
+ Tcl_HashEntry *descriptionEntry = Tcl_FindHashEntry(attrs, "help");
if (!descriptionEntry) return NULL;
const char *description = Tcl_GetString((Tcl_Obj *)Tcl_GetHashValue(descriptionEntry));
@@ -1959,6 +1997,8 @@
Tcl_SetResult(interp, "Failed to get main window", TCL_STATIC);
return TCL_ERROR;
}
+ mainWindow = mainWin;
+ Tk_CreateEventHandler(mainWin, StructureNotifyMask, MainWindowEventProc, NULL);
AtkObject *main_acc = TkCreateAccessibleAtkObject(interp, mainWin, Tk_PathName(mainWin));
if (!main_acc) {
--- a/library/accessibility.tcl
+++ b/library/accessibility.tcl
@@ -734,7 +734,7 @@
%W \
Canvas \
Canvas \
- Canvas \
+ {} \
{} \
{} \
{}\
@@ -763,7 +763,7 @@
%W \
Toggleswitch \
Toggleswitch \
- Toggleswitch \
+ {} \
[%W switchstate] \
{} \
{%W toggle}\
@@ -774,7 +774,7 @@
%W \
Combobox \
Combobox \
- Combobox \
+ {} \
[%W get] \
[%W cget -state] \
{} \
@@ -796,7 +796,7 @@
%W \
Entry \
Entry \
- Entry \
+ {} \
[%W get] \
[%W cget -state] \
{} \
@@ -807,7 +807,7 @@
%W \
Entry \
Entry \
- Entry \
+ {} \
[%W get] \
[%W state]\
{} \
@@ -819,7 +819,7 @@
%W \
Listbox \
Listbox \
- Listbox \
+ {} \
[%W get [%W curselection]] \
[%W cget -state]\
{%W invoke}\
@@ -830,7 +830,7 @@
%W \
Progressbar \
Progressbar \
- Progressbar \
+ {} \
[::tk::accessible::_getpbvalue %W] \
[%W state] \
{}\
@@ -861,7 +861,7 @@
%W \
Scale \
Scale \
- Scale \
+ {} \
[%W get] \
[%W cget -state]\
{%W set}\
@@ -870,7 +870,7 @@
%W \
Scale \
Scale \
- Scale \
+ {} \
[%W get] \
[%W cget -state] \
{%W set} \
@@ -1037,7 +1037,7 @@
%W \
Scrollbar \
Scrollbar \
- Scrollbar \
+ {} \
{} \
{} \
{}\
@@ -1046,7 +1046,7 @@
%W \
Scrollbar \
Scrollbar \
- Scrollbar \
+ {} \
{} \
{} \
{}\
@@ -1057,7 +1057,7 @@
%W \
Spinbox \
Spinbox \
- Spinbox \
+ {} \
[%W get] \
[%W cget -state] \
{%W cget -command}\
@@ -1066,7 +1066,7 @@
%W \
Spinbox \
Spinbox \
- Spinbox \
+ {} \
[%W get] \
[%W state] \
{%W cget -command}\
@@ -1089,7 +1089,7 @@
%W \
Text \
Text \
- Text \
+ {} \
[::tk::accessible::_gettext %W] \
[%W cget -state] \
{}\
@@ -1258,16 +1258,20 @@
# screen reader for vocalization. The help text here assists the user
# in switching to the standard keys for navigation as needed.
- bind Listbox <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use the standard Up-Arrow and Down-Arrow keys."}
- bind Treeview <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use the standard Up-Arrow and Down-Arrow keys. To open or close a tree node, click the Space key."}
- bind Entry <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use standard keyboard navigation. To hear the contents of the entry field, select all."}
- bind TEntry <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use standard keyboard navigation. To hear the contents of the entry field, select all."}
- bind Scale <Map> {+::tk::accessible::set_acc_help %W "Click the right or left arrows to move the scale."}
- bind TScale <Map> {+::tk::accessible::set_acc_help %W "Click the right or left arrows to move the scale."}
- bind Spinbox <Map> {+::tk::accessible::set_acc_help %W "Click the up or down arrows to change the value."}
- bind TSpinbox <Map> {+::tk::accessible::set_acc_help %W "Click the up or down arrows to change the value."}
- bind Canvas <Map> {+::tk::accessible::set_acc_help %W "The canvas widget is not accessible."}
- bind Scrollbar <Map> {+::tk::accessible::set_acc_help %W "Use the touchpad or mouse wheel to move the scrollbar."}
+ # On X11 these become the ATK description, which Orca reads on every
+ # focus change; the instructions are for mouse and trackpad users.
+ if {[tk windowingsystem] ne "x11"} {
+ bind Listbox <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use the standard Up-Arrow and Down-Arrow keys."}
+ bind Treeview <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use the standard Up-Arrow and Down-Arrow keys. To open or close a tree node, click the Space key."}
+ bind Entry <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use standard keyboard navigation. To hear the contents of the entry field, select all."}
+ bind TEntry <Map> {+::tk::accessible::set_acc_help %W "To navigate, click the mouse or trackpad and then use standard keyboard navigation. To hear the contents of the entry field, select all."}
+ bind Scale <Map> {+::tk::accessible::set_acc_help %W "Click the right or left arrows to move the scale."}
+ bind TScale <Map> {+::tk::accessible::set_acc_help %W "Click the right or left arrows to move the scale."}
+ bind Spinbox <Map> {+::tk::accessible::set_acc_help %W "Click the up or down arrows to change the value."}
+ bind TSpinbox <Map> {+::tk::accessible::set_acc_help %W "Click the up or down arrows to change the value."}
+ bind Canvas <Map> {+::tk::accessible::set_acc_help %W "The canvas widget is not accessible."}
+ bind Scrollbar <Map> {+::tk::accessible::set_acc_help %W "Use the touchpad or mouse wheel to move the scrollbar."}
+ }
bind TScrollbar <Map> {+::tk::accessible::set_acc_help %W "Use the touchpad or mouse wheel to move the scrollbar."}
bind Menubutton <Map> {+::tk::accessible::set_acc_help %W "Use the touchpad or mouse wheel to pop up the menu."}
bind TMenubutton <Map> {+::tk::accessible::set_acc_help %W "Use the touchpad or mouse wheel to pop up the menu."}