Skip to content

Commit e941b52

Browse files
Merge 310d89b into 9a4074b
2 parents 9a4074b + 310d89b commit e941b52

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

source/IAccessibleHandler/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@
126126

127127
from .orderedWinEventLimiter import MENU_EVENTIDS
128128

129-
MAX_WINEVENTS = 500
130-
131129
# Special Mozilla gecko MSAA constant additions
132130
NAVRELATION_LABEL_FOR = 0x1002
133131
NAVRELATION_LABELLED_BY = 0x1003
@@ -857,9 +855,14 @@ def pumpAll(): # noqa: C901
857855
fakeFocusEvent = None
858856
focus = eventHandler.lastQueuedFocusObject
859857

858+
alwaysAllowedObjects = []
859+
# winEvents for the currently focused object are special,
860+
# and should be never filtered out.
861+
if isinstance(focus, NVDAObjects.IAccessible.IAccessible) and focus.event_objectID is not None:
862+
alwaysAllowedObjects.append((focus.event_windowHandle, focus.event_objectID, focus.event_childID))
863+
860864
# Receive all the winEvents from the limiter for this cycle
861-
winEvents = winEventLimiter.flushEvents()
862-
winEvents = winEvents[0 - MAX_WINEVENTS:]
865+
winEvents = winEventLimiter.flushEvents(alwaysAllowedObjects)
863866

864867
for winEvent in winEvents:
865868
isEventOnCaret = winEvent[2] == winUser.OBJID_CARET

source/IAccessibleHandler/orderedWinEventLimiter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ def addEvent(
7575
self._genericEventCache[(eventID, window, objectID, childID, threadID)] = next(self._eventCounter)
7676
return True
7777

78-
def flushEvents(self):
78+
def flushEvents(self, alwaysAllowedObjects):
7979
"""Returns a list of winEvents that have been added.
8080
Due to limiting, it will not necessarily be all the winEvents that were originally added.
8181
They are definitely guaranteed to be in the correct order though.
82+
winEvents for objects listed in alwaysAllowedObjects will always be emitted,
83+
Even if the winEvent limit for that thread has been exceeded.
8284
@return Tuple[eventID,window,objectID,childID]
8385
"""
8486
if self._lastMenuEvent is not None:
@@ -88,11 +90,12 @@ def flushEvents(self):
8890
self._genericEventCache = {}
8991
threadCounters = {}
9092
for k, v in sorted(g.items(), key=lambda item: item[1], reverse=True):
91-
threadCount = threadCounters.get(k[-1], 0)
92-
if threadCount > MAX_WINEVENTS_PER_THREAD:
93-
continue
93+
if k[1:-1] not in alwaysAllowedObjects:
94+
threadCount = threadCounters.get(k[-1], 0)
95+
threadCounters[k[-1]] = threadCount + 1
96+
if threadCount > MAX_WINEVENTS_PER_THREAD:
97+
continue
9498
heapq.heappush(self._eventHeap, (v,) + k)
95-
threadCounters[k[-1]] = threadCount + 1
9699
f = self._focusEventCache
97100
self._focusEventCache = {}
98101
for k, v in sorted(f.items(), key=lambda item: item[1])[0 - self.maxFocusItems:]:

0 commit comments

Comments
 (0)