diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 66ddd92d6f2..96387c542ad 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -565,6 +565,7 @@ qt_internal_extend_target(Gui CONDITION atspi_accessibility DBUS_INTERFACE_SOURCES accessible/linux/dbusxml/Bus.xml accessible/linux/dbusxml/Socket.xml + accessible/linux/dbusxml/org.freedesktop.DBus.Properties.xml DBUS_INTERFACE_FLAGS "-i" "QtGui/private/qspi_struct_marshallers_p.h" ) diff --git a/src/gui/accessible/linux/dbusconnection.cpp b/src/gui/accessible/linux/dbusconnection.cpp index 620575cc989..41e6cdeb901 100644 --- a/src/gui/accessible/linux/dbusconnection.cpp +++ b/src/gui/accessible/linux/dbusconnection.cpp @@ -10,7 +10,6 @@ #include #include -#include "bus_interface.h" #include #include @@ -49,12 +48,22 @@ QAtSpiDBusConnection::QAtSpiDBusConnection(QObject *parent) return; } + m_a11yStatus = new OrgA11yStatusInterface(A11Y_SERVICE, A11Y_PATH, c, this); + m_dbusProperties = new OrgFreedesktopDBusPropertiesInterface(A11Y_SERVICE, A11Y_PATH, c, this); + dbusWatcher = new QDBusServiceWatcher(A11Y_SERVICE, c, QDBusServiceWatcher::WatchForRegistration, this); - connect(dbusWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(serviceRegistered())); + connect(dbusWatcher, SIGNAL(checkEnabledState(QString)), this, SLOT(checkEnabledState())); // If it is registered already, setup a11y right away if (c.interface()->isServiceRegistered(A11Y_SERVICE)) - serviceRegistered(); + checkEnabledState(); + + // Subscribe to updates about a11y enabled state. + connect(m_dbusProperties, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, + this, [this](const QString &interface_name) { + if (interface_name == QLatin1StringView(OrgA11yStatusInterface::staticInterfaceName())) + checkEnabledState(); + }); if (QGuiApplication::platformName().startsWith("xcb"_L1)) { // In addition try if there is an xatom exposing the bus address, this allows applications run as root to work @@ -82,21 +91,14 @@ QString QAtSpiDBusConnection::getAddressFromXCB() return QString(); } -// We have the a11y registry on the session bus. -// Subscribe to updates about a11y enabled state. -// Find out the bus address -void QAtSpiDBusConnection::serviceRegistered() +void QAtSpiDBusConnection::checkEnabledState() { - // listen to enabled changes - QDBusConnection c = QDBusConnection::sessionBus(); - OrgA11yStatusInterface *a11yStatus = new OrgA11yStatusInterface(A11Y_SERVICE, A11Y_PATH, c, this); - //The variable was introduced because on some embedded platforms there are custom accessibility //clients which don't set Status.ScreenReaderEnabled to true. The variable is also useful for //debugging. static const bool a11yAlwaysOn = qEnvironmentVariableIsSet("QT_LINUX_ACCESSIBILITY_ALWAYS_ON"); - bool enabled = a11yAlwaysOn || a11yStatus->screenReaderEnabled() || a11yStatus->isEnabled(); + bool enabled = a11yAlwaysOn || m_a11yStatus->screenReaderEnabled() || m_a11yStatus->isEnabled(); if (enabled != m_enabled) { m_enabled = enabled; @@ -109,8 +111,6 @@ void QAtSpiDBusConnection::serviceRegistered() c.callWithCallback(m, this, SLOT(connectA11yBus(QString)), SLOT(dbusError(QDBusError))); } } - - // connect(a11yStatus, ); QtDbus doesn't support notifications for property changes yet } void QAtSpiDBusConnection::serviceUnregistered() diff --git a/src/gui/accessible/linux/dbusconnection_p.h b/src/gui/accessible/linux/dbusconnection_p.h index 98bd02741f8..d40d6d8fd4b 100644 --- a/src/gui/accessible/linux/dbusconnection_p.h +++ b/src/gui/accessible/linux/dbusconnection_p.h @@ -23,6 +23,9 @@ #include Q_MOC_INCLUDE() +#include "bus_interface.h" +#include "properties_interface.h" + QT_BEGIN_NAMESPACE class QDBusServiceWatcher; @@ -42,7 +45,7 @@ Q_SIGNALS: private Q_SLOTS: QString getAddressFromXCB(); - void serviceRegistered(); + void checkEnabledState(); void serviceUnregistered(); void connectA11yBus(const QString &address); @@ -52,6 +55,8 @@ private: QString getAccessibilityBusAddress() const; QDBusServiceWatcher *dbusWatcher; + OrgFreedesktopDBusPropertiesInterface *m_dbusProperties; + OrgA11yStatusInterface *m_a11yStatus; QDBusConnection m_a11yConnection; bool m_enabled; }; diff --git a/src/gui/accessible/linux/dbusxml/org.freedesktop.DBus.Properties.xml b/src/gui/accessible/linux/dbusxml/org.freedesktop.DBus.Properties.xml new file mode 100644 index 00000000000..684cdc072ab --- /dev/null +++ b/src/gui/accessible/linux/dbusxml/org.freedesktop.DBus.Properties.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +