summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Weghorn <[email protected]>2025-05-01 19:04:10 +0200
committerVolker Hilsheimer <[email protected]>2025-06-03 05:34:43 +0000
commit5e7891f73fb1ba33a08ac9bd3fbcdab01d8a1193 (patch)
tree78baa4fc19c7b5fb696c4da6341f51be331361f6
parente0130876ba376faf681b80d4a7dbb20a5e3c3bdb (diff)
a11y atspi: Set correct child index in children-changed:add eventHEADdev
When sending an object:children-changed:add AT-SPI2 event, set the actual index of the child instead of always using the child count of its parent. If the new child were added at the end, its index would be "[child count] - 1", but the new child doesn't necessarily have to have been added at the end. Therefore, use the actual child index either already used as loop variable or retrieved via QAccessibleInterface::indexOfChild instead. The mismatch could e.g. be demonstrated with a simple pyatspi script when typing Enter in LibreOffice Writer to create new paragraphs. Script: #!/usr/bin/python3 import pyatspi def listener(e): if not e.host_application.name.startswith('soffice'): return print(e) print(f'index in parent set in event: {e.detail1}') print(f'index in parent reported by child: {e.any_data.get_index_in_parent()}') pyatspi.Registry.registerEventListener(listener, "object:children-changed:add") pyatspi.Registry.start() Sample output without this commit in place: object:children-changed:add(4, 0, [paragraph | ]) source: [document frame | Untitled 1 - LibreOfficeDev Document] host_application: [application | soffice.bin] sender: [application | soffice.bin] index in parent set in event: 4 index in parent reported by child: 2 Sample output with this commit in place: object:children-changed:add(2, 0, [paragraph | ]) source: [document frame | Untitled 1 - LibreOfficeDev Document] host_application: [application | soffice.bin] sender: [application | soffice.bin] index in parent set in event: 2 index in parent reported by child: 2 Pick-to: 6.10 6.9 6.8 Change-Id: I30316c59f8ad6fd018089a8dca8e7a8d1d92d7ec Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/gui/accessible/linux/atspiadaptor.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/gui/accessible/linux/atspiadaptor.cpp b/src/gui/accessible/linux/atspiadaptor.cpp
index 62f92c2b1a8..915f104035c 100644
--- a/src/gui/accessible/linux/atspiadaptor.cpp
+++ b/src/gui/accessible/linux/atspiadaptor.cpp
@@ -1384,10 +1384,10 @@ void AtSpiAdaptor::sendFocusChanged(QAccessibleInterface *interface) const
void AtSpiAdaptor::childrenChanged(QAccessibleInterface *interface) const
{
QString parentPath = pathForInterface(interface);
- int childCount = interface->childCount();
- for (int i = 0; i < interface->childCount(); ++i) {
+ const int childCount = interface->childCount();
+ for (int i = 0; i < childCount; ++i) {
QString childPath = pathForInterface(interface->child(i));
- QVariantList args = packDBusSignalArguments("add"_L1, childCount, 0, childPath);
+ QVariantList args = packDBusSignalArguments("add"_L1, i, 0, childPath);
sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
}
}
@@ -1401,9 +1401,9 @@ void AtSpiAdaptor::notifyAboutCreation(QAccessibleInterface *interface) const
return;
}
QString path = pathForInterface(interface);
- int childCount = parent->childCount();
+ const int childIndex = parent->indexOfChild(interface);
QString parentPath = pathForInterface(parent);
- QVariantList args = packDBusSignalArguments("add"_L1, childCount, 0, variantForPath(path));
+ QVariantList args = packDBusSignalArguments("add"_L1, childIndex, 0, variantForPath(path));
sendDBusSignal(parentPath, ATSPI_DBUS_INTERFACE_EVENT_OBJECT ""_L1, "ChildrenChanged"_L1, args);
}