Tighten terminal check for dropping.

This commit is contained in:
Storm Dragon
2026-05-25 23:06:07 -04:00
parent edc195c46b
commit 2d8980051f
2 changed files with 183 additions and 32 deletions
@@ -173,6 +173,97 @@ class InputEventManagerX11FocusRegressionTests(unittest.TestCase):
findActiveWindow.assert_not_called()
keyboardEvent.process.assert_not_called()
def test_lxterminal_does_not_pass_through_as_xterm(self):
manager = input_event_manager.InputEventManager()
window = mock.Mock()
window.get_class_group_name.return_value = "lxterminal"
window.get_class_instance_name.return_value = "lxterminal"
window.get_name.return_value = "LXTerminal"
window.get_class_group.return_value = None
window.get_pid.return_value = -1
with (
mock.patch.object(manager, "_get_active_x11_window", return_value=window),
mock.patch.object(input_event_manager.debug, "print_message"),
mock.patch.object(input_event_manager.debug, "print_tokens"),
):
result = manager._should_pass_through_for_active_xterm(None, None, None)
self.assertFalse(result)
def test_xterm_pass_through_stays_active_when_window_lookup_temporarily_fails(self):
manager = input_event_manager.InputEventManager()
focusManager = mock.Mock()
focusManager.get_active_window.return_value = None
focusManager.get_locus_of_focus.return_value = None
scriptManager = mock.Mock()
activeScript = mock.Mock(app=None)
scriptManager.get_active_script.return_value = activeScript
keyboardEvent = mock.Mock()
manager._scriptWithSuspendedGrabsForXterm = activeScript
with (
mock.patch.object(input_event_manager.cthulhu_state, "capturingKeys", False),
mock.patch.object(input_event_manager.cthulhu_state, "pendingSelfHostedFocus", None),
mock.patch.object(input_event_manager.focus_manager, "get_manager", return_value=focusManager),
mock.patch.object(input_event_manager.script_manager, "get_manager", return_value=scriptManager),
mock.patch.object(input_event_manager.input_event, "KeyboardEvent", return_value=keyboardEvent),
mock.patch.object(manager, "_active_x11_window_xterm_match", return_value=None),
mock.patch.object(input_event_manager.debug, "print_message"),
mock.patch.object(input_event_manager.debug, "print_tokens"),
):
result = manager.process_keyboard_event(
mock.Mock(),
True,
90,
65438,
0,
"KP_Insert",
)
self.assertFalse(result)
self.assertIs(manager._scriptWithSuspendedGrabsForXterm, activeScript)
activeScript.addKeyGrabs.assert_not_called()
keyboardEvent.process.assert_not_called()
def test_xterm_grabs_restore_when_active_window_is_positively_not_xterm(self):
manager = input_event_manager.InputEventManager()
focusManager = mock.Mock()
focusManager.get_active_window.return_value = None
focusManager.get_locus_of_focus.return_value = None
scriptManager = mock.Mock()
activeScript = mock.Mock(app=None)
scriptManager.get_active_script.return_value = activeScript
keyboardEvent = mock.Mock()
keyboardEvent.is_modifier_key.return_value = False
manager._scriptWithSuspendedGrabsForXterm = activeScript
with (
mock.patch.object(input_event_manager.cthulhu_state, "capturingKeys", False),
mock.patch.object(input_event_manager.cthulhu_state, "pendingSelfHostedFocus", None),
mock.patch.object(input_event_manager.focus_manager, "get_manager", return_value=focusManager),
mock.patch.object(input_event_manager.script_manager, "get_manager", return_value=scriptManager),
mock.patch.object(input_event_manager.input_event, "KeyboardEvent", return_value=keyboardEvent),
mock.patch.object(manager, "_active_x11_window_xterm_match", return_value=False),
mock.patch.object(input_event_manager.AXUtilities, "can_be_active_window", return_value=True),
mock.patch.object(manager, "last_event_was_keyboard", return_value=False),
mock.patch.object(input_event_manager.debug, "print_message"),
mock.patch.object(input_event_manager.debug, "print_tokens"),
):
result = manager.process_keyboard_event(
mock.Mock(),
True,
36,
65293,
0,
"Return",
)
self.assertTrue(result)
self.assertIsNone(manager._scriptWithSuspendedGrabsForXterm)
activeScript.addKeyGrabs.assert_called_once_with()
keyboardEvent.process.assert_called_once_with()
def test_finds_focused_atspi_window_for_active_x11_pid(self):
manager = input_event_manager.InputEventManager()
app = object()