send-key: Honor --exclude-active

Exclude the active window before dispatching keys when requested. Add a
regression covering both values of the option with distinct active and
invoking windows, and update the changelog.
This commit is contained in:
Zhizhen He 2026-10-16 23:09:18 +08:00
parent f426c08f5d
commit 07ab3d3409
No known key found for this signature in database
GPG key ID: B5A215D74FCFD6A7
3 changed files with 24 additions and 1 deletions

View file

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -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

View file

@ -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