Insure that browser keys are not sent when a browser is not focused.

This commit is contained in:
Storm Dragon
2026-06-18 03:12:49 -04:00
parent 43996e7b8c
commit bbef7473ee
2 changed files with 80 additions and 17 deletions
+19 -9
View File
@@ -590,6 +590,20 @@ class InputEventManager:
return result
def _clear_stale_atspi_context(self, manager: Any) -> None:
"""Clears cached input context after X11 positively contradicts AT-SPI."""
reason = "active X11 window not found in AT-SPI"
msg = (
"INPUT EVENT MANAGER: Clearing stale AT-SPI focus context; "
"X11 focus moved to an untracked window."
)
debug.print_message(debug.LEVEL_INFO, msg, True)
script_manager.get_manager().set_active_script(None, reason)
manager.clear_state(reason)
self._last_input_event = None
self._last_non_modifier_key_event = None
@staticmethod
def _get_active_script_app() -> Optional[Atspi.Accessible]:
"""Returns the app for the active script, if one is available."""
@@ -743,6 +757,11 @@ class InputEventManager:
manager.set_active_window(window)
else:
focus_window = self._get_top_level_window(pendingFocus or manager.get_locus_of_focus())
staleContext = focus_window or window or self._get_active_script_app()
if self._active_x11_window_differs_from(staleContext):
self._clear_stale_atspi_context(manager)
return False
if focus_window is not None:
window = focus_window
tokens = [
@@ -755,15 +774,6 @@ class InputEventManager:
# One example: Brave's popup menus live in frames which lack the active
# state. Failing to revalidate the window on a key press is inconclusive;
# do not wipe out the last known window and focus state.
focus = pendingFocus or manager.get_locus_of_focus()
staleContext = window or self._get_active_script_app()
if self._active_x11_window_differs_from(staleContext):
msg = (
"INPUT EVENT MANAGER: X11 focus moved to an untracked window; "
"preserving Cthulhu key handling."
)
debug.print_message(debug.LEVEL_INFO, msg, True)
tokens = [
"WARNING:",
window,