From 78d45eb161501d6862db15785349c57031a3618c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Jan 2021 07:29:13 +0530 Subject: [PATCH] Port another use of the old key API --- kitty/rc/send_text.py | 4 +--- kitty/window.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index 8149de50e..7cb82a88f 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -11,8 +11,6 @@ from kitty.config import parse_send_text_bytes from kitty.key_encoding import ( WindowSystemKeyEvent, decode_key_event_as_window_system_key ) -from kitty.keys import interpret_key_event - from .base import ( MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, MatchError, PayloadGetType, PayloadType, RCOptions, RemoteCommand, ResponseType, @@ -155,7 +153,7 @@ Do not send text to the active window, even if it is one of the matched windows. if window is not None: if not exclude_active or window is not boss.active_window: if isinstance(data, WindowSystemKeyEvent): - kdata = interpret_key_event(data.code, 0, data.mods, window, data.action) + kdata = window.encoded_key(data.code, mods=data.mods, action=data.action) if kdata: window.write_to_child(kdata) else: diff --git a/kitty/window.py b/kitty/window.py index d1c41b22f..09d720fe8 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -23,9 +23,9 @@ from .constants import ScreenGeometry, WindowGeometry, appname, wakeup from .fast_data_types import ( BGIMAGE_PROGRAM, BLIT_PROGRAM, CELL_BG_PROGRAM, CELL_FG_PROGRAM, CELL_PROGRAM, CELL_SPECIAL_PROGRAM, DCS, DECORATION, DIM, GLFW_MOD_CONTROL, - GRAPHICS_ALPHA_MASK_PROGRAM, GRAPHICS_PREMULT_PROGRAM, GRAPHICS_PROGRAM, - MARK, MARK_MASK, OSC, REVERSE, SCROLL_FULL, SCROLL_LINE, SCROLL_PAGE, - STRIKETHROUGH, TINT_PROGRAM, Screen, add_timer, add_window, + GLFW_PRESS, GRAPHICS_ALPHA_MASK_PROGRAM, GRAPHICS_PREMULT_PROGRAM, + GRAPHICS_PROGRAM, MARK, MARK_MASK, OSC, REVERSE, SCROLL_FULL, SCROLL_LINE, + SCROLL_PAGE, STRIKETHROUGH, TINT_PROGRAM, Screen, add_timer, add_window, cell_size_for_window, compile_program, encode_key_for_tty, get_boss, get_clipboard_string, init_cell_program, pt_to_px, set_clipboard_string, set_titlebar_color, set_window_padding, set_window_render_data, @@ -881,16 +881,18 @@ class Window: if text: set_clipboard_string(text) + def encoded_key(self, key: int, mods: int = 0, action: int = GLFW_PRESS) -> bytes: + return encode_key_for_tty( + key=key, mods=mods, key_encoding_flags=self.screen.current_key_encoding_flags(), + cursor_key_mode=self.screen.cursor_key_mode, action=action + ).encode('ascii') + def copy_or_interrupt(self) -> None: text = self.text_for_selection() if text: set_clipboard_string(text) else: - data = encode_key_for_tty( - key=ord('c'), mods=GLFW_MOD_CONTROL, key_encoding_flags=self.screen.current_key_encoding_flags(), - cursor_key_mode=self.screen.cursor_key_mode - ) - self.write_to_child(data.encode('ascii')) + self.write_to_child(self.encoded_key(ord('c'), mods=GLFW_MOD_CONTROL)) def copy_and_clear_or_interrupt(self) -> None: self.copy_or_interrupt()