Skip to content

Selective UIA event handling#11214

Merged
michaelDCurran merged 21 commits into
nvaccess:masterfrom
LeonarddeR:selectiveUIAEventHandling
Jul 6, 2020
Merged

Selective UIA event handling#11214
michaelDCurran merged 21 commits into
nvaccess:masterfrom
LeonarddeR:selectiveUIAEventHandling

Conversation

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Link to issue number:

Closes #11209
fixes #11077
Improves #11002
Follow up of #8742

Summary of the issue:

NVDA is listening globally to many UIA elements. This causes a major performance hit when many events are received (#11109)

Description of how this pull request fixes the issue:

  1. This pr introduces an easier method for event registration by means of EventHandlerGroups. This feature was introduced in IUIAutomation6. I wrote a FakeEventHandlerGroup class to mimic this behavior on older versions of UIA. In short, this allows us to request for automation/ notification and property events in one call instead of three on newer versions of UIA.
  2. For some events, we still keep listening globally. However, for many of them, I switched to local event registration, with that I mean only to objects of interest. Currently, these are the focus object and its ancestors.
  3. When changing focus, we register for events fired at the focus object and its ancestors. This includes all focus changes, including these for non native UIA elements. This includes focus changes for IAccessible objects as well.

Testing performed:

Known issues with pull request:

  • @josephsl noted that announcements for modern input are somewhat broken, i.e. the announcement that the emoji panel is closed. I haven't yet looked into this. I'd like to have a basic review about the prototype and its performance improvements first.

Change log entry:

@LeonarddeR LeonarddeR added performance api/uia Feature or bug requires an understanding of UIA labels May 27, 2020
@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

Here is a try build

@lukaszgo1

Copy link
Copy Markdown
Contributor

@LeonarddeR I can confirm that the latest try build fixes my issues under Windows 7.

@josephsl

Copy link
Copy Markdown
Contributor

Hi,

Regarding emoji panel and other modern input features, the fundamental issue to consider is focus change. A few months ago I tried to resolve overlay focus issues by faking a focus change event when emoji panel opens, but this resulted in NVDA's notion of "focus" being trapped once the panel was closed i.e. previously focused window isn't announced once the panel closes. In theory, this issue would also impact touch keyboard support on Windows 8 and later if it also suffers from focus trap issue, along with a possible impact on UIA notification event handling for classic Edge. I'm looking into resolving emoji panel issue from the app module side and to test this PR at the same time.

Thanks.

@josephsl josephsl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out focus change handler will add or remove events every time focus changes. This is more so when moving focus to a different element inside the same foreground window/application. This might be something to optimize later.

Apart from modern input support not working well, this looks promising. Thanks.

@josephsl

Copy link
Copy Markdown
Contributor

Hi,

Found a way to restore emoji panel support - local event group must be added for input panel header. This means this PR must block #10378 - I'll package that PR and the follow-up one together.

Thanks.

@codeofdusk

codeofdusk commented May 28, 2020

Copy link
Copy Markdown
Contributor

Found a bug:

  1. In 21H1 (open) console with UIA, press alt+space to open the application menu.
  2. Press e to open the edit menu.
  3. Press p to paste.

Expected: auto-read continues functioning after this, with no need to switch windows.
Actual: a focus change is necessary to bring back autoread.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

@josephsl wrote:

It turns out focus change handler will add or remove events every time focus changes. This is more so when moving focus to a different element inside the same foreground window/application. This might be something to optimize later.

This is currently intentional. #8742 implemented per foreground event registration, but as @jcsteh noted in #8742 (comment) , it wouldn't fix property event bombarding within the same foreground window.

@codeofdusk wrote:

Actual: a focus change is necessary to bring back autoread.

This is really weird. It looks like the local event registration isn't triggered when focus is back on the terminal window. I will investigate this.

@josephsl

josephsl commented May 28, 2020 via email

Copy link
Copy Markdown
Contributor

@LeonarddeR

LeonarddeR commented May 28, 2020 via email

Copy link
Copy Markdown
Collaborator Author

@josephsl

josephsl commented May 28, 2020 via email

Copy link
Copy Markdown
Contributor

@LeonarddeR

LeonarddeR commented May 28, 2020 via email

Copy link
Copy Markdown
Collaborator Author

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

@codeofdusk It looks like the issue with the UIA implementation of cmd is exactly the same issue as that requires us to implement focusRedirect. I will investigate a fix.

@codeofdusk

Copy link
Copy Markdown
Contributor

More generally, I'd think you'd want to find a method of dealing with focus changes through redirects...

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

I will investigate whether it is possible to hide stuff behind a feature flag, so the initial version of this pull request can hopefully be merged sooner, with may be some issues remaining.

@AppVeyorBot

This comment has been minimized.

@josephsl

Copy link
Copy Markdown
Contributor

Hi,

By the way, in order to properly test this, one must:

  1. Change selective UIA events setting from Advanced settings panel.
  2. Reload UIA handler thread as follows:

Open Python console, then:
import UIAHandler
UIAHandler.terminate(); UIAHandler.initialize()

The import statement is not needed if UIA handler was already imported.

Thanks.

@josephsl

Copy link
Copy Markdown
Contributor

Hi,

My results so far:

  • Windows 7 and 8.1: no difference observed, although this was with no UIA intensive apps such as Microsoft 365 installed.
  • Windows 10 versions 1507 through 1709: no difference I can observe.
  • Windows 10 Version 1803: no hardware keyboard suggestions are announced when selective UIA events is on.
  • Windows 10 Version 1809 and later: no announcement of emoji panel categories when pressing tab from emoji panel.

Scenarios tested:

  • Opening, searching, and closing Start menu/screen.
  • Opening and closing Control Panel.
  • Opening, navigating, and closing Windows 10 Settings app.
  • File Explorer.
  • Modern input.

For hardware keyboard suggestions and emoji panel, one workaround is manually registering various UIA events for modern input apps. This does allow hardware keyboard suggestions to be announced and emoji categories to be heard when pressing Tab from emoji panel in 1809 and later.

Thanks.

@josephsl

josephsl commented Jun 27, 2020

Copy link
Copy Markdown
Contributor

Hi,

Another thing to consider: in Windows 10's Start menu, after selecting a search result or moving focus away from the screen itself, suggestions closed sound is not heard (this is the case with at least 20H2). This is caused by the fact that when a search result is selected, focused item isn't search box anymore (search box is responsible for raising UIA controller for event). I'm designing a potential fix from my end.

Thanks.

@michaelDCurran

Copy link
Copy Markdown
Member

@josephsl What specific UIA events are required for hardware keyboard and emoji selection support that was broken with this pr?

@josephsl

josephsl commented Jun 28, 2020 via email

Copy link
Copy Markdown
Contributor

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

Personally, I think we shouldn't make these issues block this pr from going through, as the new behavior isn't the default. Also, in 2004 it works fine for me, at least when pressing escape to close the start menu.

@josephsl

josephsl commented Jun 29, 2020 via email

Copy link
Copy Markdown
Contributor

@zstanecic

zstanecic commented Jun 29, 2020 via email

Copy link
Copy Markdown
Contributor

@zstanecic

Copy link
Copy Markdown
Contributor

How is situation with this?

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

i've been using this for the last month or so on a Windows 10 machine in production, as Visual Studio is almost unbearable without it.
Personally, if @michaelDCurran agrees with the current code, I'd appreciate a merge early in the 2020.3 alpha cycle so it can prove itself.

@LeonarddeR LeonarddeR requested a review from michaelDCurran July 3, 2020 07:10
@zstanecic

zstanecic commented Jul 3, 2020 via email

Copy link
Copy Markdown
Contributor

@josephsl

josephsl commented Jul 3, 2020 via email

Copy link
Copy Markdown
Contributor

@michaelDCurran

michaelDCurran commented Jul 3, 2020 via email

Copy link
Copy Markdown
Member

@codeofdusk

Copy link
Copy Markdown
Contributor

This feature has been disabled by default for several releases.

At this stage, what is blocking enabling by default?

seanbudd pushed a commit that referenced this pull request Aug 16, 2022
Link to issue number:
Partial mitigation for #11002.
Follow-up of #11214 and #13297.

Summary of the issue:
NVDA 2020.3 introduced support for selective registration for UIA events based on the currently-focused provider, but this is disabled by default due to bugs in the Windows 10 task manager and emoji panel.
These bugs have been fixed in Windows 11 SV2.

Description of how this pull request fixes the issue:
By default, enable selective UIA event registration on Windows 11 Sun Valley 2 (22H2).

Testing strategy:
Enable by default in master snapshots to allow for wider testing.
@LeonarddeR LeonarddeR deleted the selectiveUIAEventHandling branch August 23, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api/uia Feature or bug requires an understanding of UIA performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict most event processing to objects of interest to the user UIA: selective event registration

9 participants