From df70d8661ac7625bf53ed353af429c38f32a24e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 30 Oct 2021 12:29:27 +0530 Subject: [PATCH] Pass the peer id to commands --- kitty/boss.py | 8 ++++---- kitty/remote_control.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 554b41090..f2870cdd7 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -395,13 +395,13 @@ class Boss: self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen) self.window_id_map[window.id] = window - def _handle_remote_command(self, cmd: str, window: Optional[Window] = None, from_peer: bool = False) -> Optional[Dict[str, Any]]: + def _handle_remote_command(self, cmd: str, window: Optional[Window] = None, peer_id: int = 0) -> Optional[Dict[str, Any]]: from .remote_control import handle_cmd response = None window = window or None - if self.allow_remote_control == 'y' or from_peer or getattr(window, 'allow_remote_control', False): + if self.allow_remote_control == 'y' or peer_id > 0 or getattr(window, 'allow_remote_control', False): try: - response = handle_cmd(self, window, cmd) + response = handle_cmd(self, window, cmd, peer_id) except Exception as err: import traceback response = {'ok': False, 'error': str(err)} @@ -456,7 +456,7 @@ class Boss: terminator = b'\x1b\\' if msg_bytes.startswith(cmd_prefix) and msg_bytes.endswith(terminator): cmd = msg_bytes[len(cmd_prefix):-len(terminator)].decode('utf-8') - response = self._handle_remote_command(cmd, from_peer=True) + response = self._handle_remote_command(cmd, peer_id=peer_id) if response is None: return None return cmd_prefix + json.dumps(response).encode('utf-8') + terminator diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 1fd9c5733..cf36ab3e9 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -24,7 +24,7 @@ from .typing import BossType, WindowType from .utils import TTYIO, parse_address_spec -def handle_cmd(boss: BossType, window: Optional[WindowType], serialized_cmd: str) -> Optional[Dict[str, Any]]: +def handle_cmd(boss: BossType, window: Optional[WindowType], serialized_cmd: str, peer_id: int) -> Optional[Dict[str, Any]]: cmd = json.loads(serialized_cmd) v = cmd['version'] no_response = cmd.get('no_response', False) @@ -34,6 +34,7 @@ def handle_cmd(boss: BossType, window: Optional[WindowType], serialized_cmd: str return {'ok': False, 'error': 'The kitty client you are using to send remote commands is newer than this kitty instance. This is not supported.'} c = command_for_name(cmd['cmd']) payload = cmd.get('payload') or {} + payload['peer_id'] = peer_id try: ans = c.response_from_kitty(boss, window, PayloadGetter(c, payload))