From 350a75f792156724a620ddfb987c27cfd767abbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20de=20la=20Rocha?= Date: Fri, 25 Mar 2022 14:40:56 -0300 Subject: Windows QPA: Avoid sending accessibility notifications before activation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When accessibility was activated after the application startup, it would send state update notifications for every accessible object, which for a large number of objects could result in a flood of UI Automation notifications and UI slowdown. This patch ignores these notifications until QAccessible is activated, which should avoid the slowdown and seems to cause no side effects with accessibility tools. Fixes: QTBUG-95114 Pick-to: 6.2 6.3 5.15 Change-Id: If1495d0aa846d7810b3d297b7e156563a7e5f6e6 Reviewed-by: Jan Arve Sæther --- .../platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp | 7 +++++++ .../platforms/windows/uiautomation/qwindowsuiaaccessibility.h | 2 ++ 2 files changed, 9 insertions(+) (limited to 'src/plugins/platforms/windows') diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp index 0903f5a618..5f87badd51 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.cpp @@ -58,6 +58,7 @@ QT_BEGIN_NAMESPACE using namespace QWindowsUiAutomation; +bool QWindowsUiaAccessibility::m_accessibleActive = false; QWindowsUiaAccessibility::QWindowsUiaAccessibility() { @@ -72,6 +73,7 @@ bool QWindowsUiaAccessibility::handleWmGetObject(HWND hwnd, WPARAM wParam, LPARA { // Start handling accessibility internally QGuiApplicationPrivate::platformIntegration()->accessibility()->setActive(true); + m_accessibleActive = true; // Ignoring all requests while starting up / shutting down if (QCoreApplication::startingUp() || QCoreApplication::closingDown()) @@ -131,6 +133,11 @@ void QWindowsUiaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event if (!event) return; + // Ignore events sent before the first UI Automation + // request or while QAccessible is being activated. + if (!m_accessibleActive) + return; + switch (event->type()) { case QAccessible::PopupMenuStart: playSystemSound(QStringLiteral("MenuPopup")); diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.h b/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.h index 48b4f9fa6a..ac01a51e76 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.h +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiaaccessibility.h @@ -56,6 +56,8 @@ public: virtual ~QWindowsUiaAccessibility(); static bool handleWmGetObject(HWND hwnd, WPARAM wParam, LPARAM lParam, LRESULT *lResult); void notifyAccessibilityUpdate(QAccessibleEvent *event) override; +private: + static bool m_accessibleActive; }; QT_END_NAMESPACE -- cgit v1.2.3