11# A part of NonVisual Desktop Access (NVDA)
2- # Copyright (C) 2008-2023 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler
2+ # Copyright (C) 2008-2024 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler
33# This file is covered by the GNU General Public License.
44# See the file COPYING for more details.
55
@@ -1015,12 +1015,12 @@ def IUIAutomationPropertyChangedEventHandler_HandlePropertyChangedEvent(
10151015
10161016 def IUIAutomationNotificationEventHandler_HandleNotificationEvent (
10171017 self ,
1018- sender ,
1019- NotificationKind ,
1020- NotificationProcessing ,
1021- displayString ,
1022- activityId ,
1023- ):
1018+ sender : UIA . IUIAutomationElement ,
1019+ NotificationKind : int ,
1020+ NotificationProcessing : int ,
1021+ displayString : str ,
1022+ activityId : str
1023+ ) -> None :
10241024 if _isDebug ():
10251025 log .debug (
10261026 "handleNotificationEvent called "
@@ -1037,8 +1037,39 @@ def IUIAutomationNotificationEventHandler_HandleNotificationEvent(
10371037 return
10381038 import NVDAObjects .UIA
10391039
1040+ # #16871: some elements do not report native window handle when in fact
1041+ # native window handle is shown via runtime ID.
1042+ # This is seen when handling Windows 11 Voice Access notifications.
1043+ if not (window := self .getNearestWindowHandle (sender )):
1044+ if _isDebug ():
1045+ log .debugWarning (
1046+ "HandleNotificationEvent: native window handle not found, consulting runtime ID: "
1047+ f"NotificationProcessing={ NotificationProcessing } "
1048+ f"displayString={ displayString } "
1049+ f"activityId={ activityId } "
1050+ )
1051+ if any (runtimeID := sender .getRuntimeID ()):
1052+ # Second item in runtime ID array is native window handle.
1053+ window = runtimeID [1 ]
1054+ if _isDebug ():
1055+ log .debugWarning (
1056+ f"HandleNotificationEvent: native window handle is { window } : "
1057+ f"NotificationProcessing={ NotificationProcessing } "
1058+ f"displayString={ displayString } "
1059+ f"activityId={ activityId } "
1060+ )
1061+ else :
1062+ # No runtime ID (tuple is empty).
1063+ if _isDebug ():
1064+ log .debugWarning (
1065+ "HandleNotificationEvent: native window handle not found in runtime ID: "
1066+ f"NotificationProcessing={ NotificationProcessing } "
1067+ f"displayString={ displayString } "
1068+ f"activityId={ activityId } "
1069+ )
1070+ return
10401071 try :
1041- obj = NVDAObjects .UIA .UIA (UIAElement = sender )
1072+ obj = NVDAObjects .UIA .UIA (windowHandle = window , UIAElement = sender )
10421073 except Exception :
10431074 if _isDebug ():
10441075 log .debugWarning (
0 commit comments