Harden cthulhu's terminal release code.

This commit is contained in:
Storm Dragon
2026-07-03 02:58:40 -04:00
parent b08f7095cb
commit dfef847fb5
2 changed files with 91 additions and 6 deletions
+27 -6
View File
@@ -477,28 +477,49 @@ class InputEventManager:
return None
self._log_active_x11_window_for_xterm_check(window)
sawIdentifier = False
for attrName in ("get_class_group_name", "get_class_instance_name", "get_name"):
if self._identifier_is_xterm(self._safe_call(window, attrName)):
value = self._safe_call(window, attrName)
if self._identifier_is_xterm(value):
return True
if isinstance(value, str) and value.strip():
sawIdentifier = True
classGroup = self._safe_call(window, "get_class_group")
if classGroup is not None:
for attrName in ("get_name", "get_res_class"):
if self._identifier_is_xterm(self._safe_call(classGroup, attrName)):
value = self._safe_call(classGroup, attrName)
if self._identifier_is_xterm(value):
return True
if isinstance(value, str) and value.strip():
sawIdentifier = True
try:
pid = int(window.get_pid())
except Exception:
pid = -1
if pid < 1:
if not sawIdentifier:
msg = (
"INPUT EVENT MANAGER: XTerm matcher cannot identify active X11 window; "
"no usable identifiers or pid."
)
debug.print_message(debug.LEVEL_INFO, msg, True)
return None
return False
try:
with open(f"/proc/{pid}/cmdline", "rb") as cmdlineFile:
executable = cmdlineFile.read().split(b"\0", 1)[0].decode(errors="ignore")
except OSError:
if not sawIdentifier:
msg = (
"INPUT EVENT MANAGER: XTerm matcher cannot identify active X11 window; "
"pid disappeared before cmdline lookup."
)
debug.print_message(debug.LEVEL_INFO, msg, True)
return None
return False
return self._identifier_is_xterm(executable)
@@ -635,15 +656,15 @@ class InputEventManager:
) -> bool:
"""Returns True when XTerm is active and Cthulhu lacks matching AT-SPI context."""
if pendingFocus is not None:
msg = "INPUT EVENT MANAGER: XTerm matcher false; pending focus exists."
debug.print_message(debug.LEVEL_INFO, msg, True)
return False
match = self._active_x11_window_xterm_match()
tokens = ["INPUT EVENT MANAGER: XTerm matcher returned", match]
debug.print_tokens(debug.LEVEL_INFO, tokens, True)
if match is True:
return True
if pendingFocus is not None:
msg = "INPUT EVENT MANAGER: XTerm matcher false; pending focus exists."
debug.print_message(debug.LEVEL_INFO, msg, True)
return False
if match is None and self._scriptWithSuspendedGrabsForXterm is not None:
msg = (
"INPUT EVENT MANAGER: Keeping XTerm key-grab suspension; "