Repository: nvaccess/nvda

Issue:
Windows 11: a "pane" window gets focus when switching to certain apps, including Command Prompt
Hi,

Related: #12585 

The following was reported on Twitter, and a discussion about this took place between I, @CToth, and several users.

### Steps to reproduce:
With Windows 11 preview installed:

1. Open several apps.
2. Run Command Prompt, Windows Terminal, or other application, preferably running Windows Subsystem for Linux (WSL) 2 shell active.
3. Switch to a different app.
4. Switch to Command Prompt.

### Actual behavior:
Focus lands on "pane" window.

### Expected behavior:
Focus lands on Command Prompt.

### System configuration
#### NVDA installed/portable/running from source:
Installed

#### NVDA version:
2021.1, alpha-23336,9409b9dd

#### Windows version:
Windows 11 preview (build 22000.65)

#### Name and version of other software in use when reproducing the issue:
Command Prompt, Windows Terminal 1.9

#### Other information about your system:
A virtual machine running Insider Preview builds

### Other questions
#### Does the issue still occur after restarting your computer?
Yes

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Older versions such as 2020.4 behave the same.

#### If add-ons are disabled, is your problem still occurring?
Yes

#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Not applicable

### Additional context:
Currently a fix was deployed through Windows App Essentials, and @CToth points out that it should be part of NVDA to begin with as this is a basic user experience issue.

#### Developer info for the pane object:
name: ''
role: ROLE_PANE
roleText: None
states: STATE_FOCUSED
isFocusable: False
hasFocus: True
Python object: <NVDAObjects.UIA.UIA object at 0x06EEB5B0>
Python class mro: (<class 'NVDAObjects.UIA.UIA'>, <class 'NVDAObjects.window.Window'>, <class 'NVDAObjects.NVDAObject'>, <class 'documentBase.TextContainerObject'>, <class 'baseObject.ScriptableObject'>, <class 'baseObject.AutoPropertyObject'>, <class 'garbageHandler.TrackedObject'>, <class 'object'>)
description: ''
location: RectLTWH(left=0, top=0, width=1600, height=1152)
value: None
appModule: <'explorer' (appName 'explorer', process ID 5928) at address 6d0e890>
appModule.productName: 'Microsoft® Windows® Operating System'
appModule.productVersion: '10.0.22000.51'
TextInfo: <class 'NVDAObjects.NVDAObjectTextInfo'>
windowHandle: 853144
windowClassName: 'Windows.UI.Input.InputSite.WindowClass'
windowControlID: 0
windowStyle: 1342177280
extendedWindowStyle: 0
windowThreadID: 6424
windowText: ''
displayText: ''
UIAElement: <POINTER(IUIAutomationElement) ptr=0x397a728 at 701c120>
UIA automationID: 
UIA frameworkID: XAML
UIA runtimeID: (42, 853144)
UIA providerDescription: [pid:4556,providerId:0xD0498 Main:Nested [pid:5928,providerId:0xD0498 Main(parent link):Unidentified Provider (unmanaged:Windows.UI.Xaml.dll)]; Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:UIAutomationCore.dll)]
UIA className: Windows.UI.Input.InputSite.WindowClass
UIA patterns available: LegacyIAccessiblePattern

#### Proposed solution:
Let NvDA ignore UIA focus event for this window, which then allows NVDA to notice that Command Prompt was focused. The ideal solution should come from Microsoft, and since Windows 11 is in preview, things can change, making the PR a bit risky (we need to revert changes if Microsoft fixes this).

Thanks.


Discussion:
CC @CodeOfDusk because this may impact work on potential Windows 11 console support.
CC @Zersiax 
I can repro on latest Win11 insider build, filed as Windows bug 34627510 (Windows 11: accessibility focus lands on pane window when switching to conhost with alt+tab).
Keep your eyes peeled for a fix :)
Hi, thanks – looking forward to the in-flight entertainment i.e. testing the fixed CU.


No longer repros in Windows 11 insider builds after 22000.111. This issue should be closed as fixed externally.
Hi, note to observers: this issue will be closed once 22000.111 or later is released to Insiders. Thanks. 


No, not 22000.111, but a build *after* that.
Hi, thanks for clarifying.


Actually, I can still repro under co_refresh. Following up internally.
Hi,

Not resolved in 22000.160. I'll consider a quick pull request to fix this and "Task Switching" announcement issue if this problem is confirmed by release preview Insiders (coming soon).

Possible solution from NVDA side: editing gain focus event found in Explorer app module might suffice for now. Note that window class name should not be checked for "pane" announcement as shell elements are tagged as "Windows.UI.Input.InputSite.WindowClass" which will cause Taskbar items and other shell elements to not be announced if gain focus event is vetoed. For Task Switching window, window class name can be checked as it is an MSAA object, whereas input site window is a UIA element. Ideally the solution is seeing if this is resolved in cobalt refresh or nickel/copper dev semesters (eventually backported/cherry-picked into cobalt release/servicing branch) a.k.a. not editing NVDA source code.

Thanks.
> 22000.160

External dev builds will lag behind the cutting edge by at least a few weeks due to reverse-integration of changes. Sadly, I don't have access to the bug tracker any more due to the conclusion of my internship.

@DHowett did they mark [bug 34627510](https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmicrosoft.visualstudio.com%2FOS%2F_workitems%2Fedit%2F34627510&data=04%7C01%7Cv-vickileon%40microsoft.com%7C5562d3f14c5944db88e108d95eadb31d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637644922392513650%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=XtcFz7ulo73Af7GxbahCqpyRML6W0gpm%2Bodwckay51k%3D&reserved=0) as won't fix again? It severely affects all UIA clients on Cobalt.
Hi,

Since this problem also occurs in nickel build 22449 and Windows 11 official release date is set, I'll do everything I can to get the accompanying pull request into NVDA 2021.3 at the earliest. Also, after further testing, the solution is a lot simpler than I thought: treating "pane" windows as multitasking view frame from Windows 8.x/10 days.

Thanks.
> Since this problem also occurs in nickel build 22449

I'm still working on this from the MS side! If it still repros after the next nickel build (no longer have internal access) then we should seek an NVDA side resolution. Also hoping to see this RIed into cobalt.
Hi, note that the NVDA side resolution is already there – Windows App Essentials add-on – it is a matter of fitting the needed change into the File Explorer app module with explanatory comments. I remain hopeful that we don’t have to go down that road – let’s wait and see if build 22454 solves this. Thanks.


Hi,

Update: as the problem still exists in build 22000.258 (KB5006674), I will wait and see if build 22478 resolves this, and if not, I will take care of this problem as soon as I'm done with graduate school midterm this weekend (I'm bumping this to top priority for me).

Thanks.

Resolving patch:
diff --git a/source/appModules/explorer.py b/source/appModules/explorer.py
--- a/source/appModules/explorer.py
+++ b/source/appModules/explorer.py
@@ -1,6 +1,6 @@
 # -*- coding: UTF-8 -*-
 # A part of NonVisual Desktop Access (NVDA)
-# Copyright (C) 2006-2020 NV Access Limited, Joseph Lee, Łukasz Golonka, Julien Cochuyt
+# Copyright (C) 2006-2021 NV Access Limited, Joseph Lee, Łukasz Golonka, Julien Cochuyt
 # This file is covered by the GNU General Public License.
 # See the file COPYING for more details.
 
@@ -341,7 +341,13 @@ def chooseNVDAObjectOverlayClasses(self, obj, clsList):
 				clsList.insert(0, ImmersiveLauncher)
 			elif uiaClassName == "ListViewItem" and obj.UIAElement.cachedAutomationId.startswith('Suggestion_'):
 				clsList.insert(0, SuggestionListItem)
-			elif uiaClassName == "MultitaskingViewFrame" and role == controlTypes.Role.WINDOW:
+			# Multitasking view frame window
+			elif (
+				# Windows 10 and earlier
+				(uiaClassName == "MultitaskingViewFrame" and role == controlTypes.Role.WINDOW)
+				# Windows 11 where a pane window receives focus when switching tasks
+				or (uiaClassName == "Windows.UI.Input.InputSite.WindowClass" and role == controlTypes.Role.PANE)
+			):
 				clsList.insert(0, MultitaskingViewFrameWindow)
 			# Windows 10 task switch list
 			elif role == controlTypes.Role.LISTITEM and (


Test patch: