diff --git a/docs/changelog.rst b/docs/changelog.rst index fd6137cd2..a45771522 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -494,6 +494,9 @@ Detailed list of changes - Sessions: Fix ``os_window_title`` having no effect on the first OS Window created when starting kitty with a session file (:iss:`10675`) +- Remote control: Fix :option:`kitten @ send-key --exclude-active` sending keys + to the active window instead of excluding it. + 0.49.2 [2026-10-01] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/rc/send_key.py b/kitty/rc/send_key.py index 8f5fc838a..70cc284e9 100644 --- a/kitty/rc/send_key.py +++ b/kitty/rc/send_key.py @@ -65,7 +65,8 @@ Do not send text to the active window, even if it is one of the matched windows. windows = self.windows_for_payload(boss, None, payload_get, window_match_name='match') keys = payload_get('keys') for w in windows: - w.send_key(*keys) + if not payload_get('exclude_active') or w is not boss.active_window: + w.send_key(*keys) return None diff --git a/kitty_tests/remote_control.py b/kitty_tests/remote_control.py index 6ed6c02b9..89e0dc1eb 100644 --- a/kitty_tests/remote_control.py +++ b/kitty_tests/remote_control.py @@ -57,6 +57,25 @@ class TestRemoteControl(BaseTest): setter.assert_called_once_with(11, '') + def test_send_key_excludes_active_window(self): + windows = [Window(1, 11), Window(2, 11)] + boss = Boss(windows) + cmd = command_for_name('send-key') + + for exclude_active in (False, True): + with ( + self.subTest(exclude_active=exclude_active), + patch.object(windows[0], 'send_key', create=True) as active, + patch.object(windows[1], 'send_key', create=True) as other, + ): + cmd.response_from_kitty(boss, windows[1], PayloadGetter(cmd, {'all': True, 'exclude_active': exclude_active, 'keys': ['ctrl+a', 'ctrl+b']})) + + other.assert_called_once_with('ctrl+a', 'ctrl+b') + if exclude_active: + active.assert_not_called() + else: + active.assert_called_once_with('ctrl+a', 'ctrl+b') + def test_set_colors_transparent_background_colors(self): from kitty.fast_data_types import Color from kitty.rc.base import RemoteControlErrorWithoutTraceback, parse_subcommand_cli