Port another use of the old key API
This commit is contained in:
parent
eeacac227a
commit
78d45eb161
@ -11,8 +11,6 @@ from kitty.config import parse_send_text_bytes
|
|||||||
from kitty.key_encoding import (
|
from kitty.key_encoding import (
|
||||||
WindowSystemKeyEvent, decode_key_event_as_window_system_key
|
WindowSystemKeyEvent, decode_key_event_as_window_system_key
|
||||||
)
|
)
|
||||||
from kitty.keys import interpret_key_event
|
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, MatchError,
|
MATCH_TAB_OPTION, MATCH_WINDOW_OPTION, ArgsType, Boss, MatchError,
|
||||||
PayloadGetType, PayloadType, RCOptions, RemoteCommand, ResponseType,
|
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 window is not None:
|
||||||
if not exclude_active or window is not boss.active_window:
|
if not exclude_active or window is not boss.active_window:
|
||||||
if isinstance(data, WindowSystemKeyEvent):
|
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:
|
if kdata:
|
||||||
window.write_to_child(kdata)
|
window.write_to_child(kdata)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -23,9 +23,9 @@ from .constants import ScreenGeometry, WindowGeometry, appname, wakeup
|
|||||||
from .fast_data_types import (
|
from .fast_data_types import (
|
||||||
BGIMAGE_PROGRAM, BLIT_PROGRAM, CELL_BG_PROGRAM, CELL_FG_PROGRAM,
|
BGIMAGE_PROGRAM, BLIT_PROGRAM, CELL_BG_PROGRAM, CELL_FG_PROGRAM,
|
||||||
CELL_PROGRAM, CELL_SPECIAL_PROGRAM, DCS, DECORATION, DIM, GLFW_MOD_CONTROL,
|
CELL_PROGRAM, CELL_SPECIAL_PROGRAM, DCS, DECORATION, DIM, GLFW_MOD_CONTROL,
|
||||||
GRAPHICS_ALPHA_MASK_PROGRAM, GRAPHICS_PREMULT_PROGRAM, GRAPHICS_PROGRAM,
|
GLFW_PRESS, GRAPHICS_ALPHA_MASK_PROGRAM, GRAPHICS_PREMULT_PROGRAM,
|
||||||
MARK, MARK_MASK, OSC, REVERSE, SCROLL_FULL, SCROLL_LINE, SCROLL_PAGE,
|
GRAPHICS_PROGRAM, MARK, MARK_MASK, OSC, REVERSE, SCROLL_FULL, SCROLL_LINE,
|
||||||
STRIKETHROUGH, TINT_PROGRAM, Screen, add_timer, add_window,
|
SCROLL_PAGE, STRIKETHROUGH, TINT_PROGRAM, Screen, add_timer, add_window,
|
||||||
cell_size_for_window, compile_program, encode_key_for_tty, get_boss,
|
cell_size_for_window, compile_program, encode_key_for_tty, get_boss,
|
||||||
get_clipboard_string, init_cell_program, pt_to_px, set_clipboard_string,
|
get_clipboard_string, init_cell_program, pt_to_px, set_clipboard_string,
|
||||||
set_titlebar_color, set_window_padding, set_window_render_data,
|
set_titlebar_color, set_window_padding, set_window_render_data,
|
||||||
@ -881,16 +881,18 @@ class Window:
|
|||||||
if text:
|
if text:
|
||||||
set_clipboard_string(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:
|
def copy_or_interrupt(self) -> None:
|
||||||
text = self.text_for_selection()
|
text = self.text_for_selection()
|
||||||
if text:
|
if text:
|
||||||
set_clipboard_string(text)
|
set_clipboard_string(text)
|
||||||
else:
|
else:
|
||||||
data = encode_key_for_tty(
|
self.write_to_child(self.encoded_key(ord('c'), mods=GLFW_MOD_CONTROL))
|
||||||
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'))
|
|
||||||
|
|
||||||
def copy_and_clear_or_interrupt(self) -> None:
|
def copy_and_clear_or_interrupt(self) -> None:
|
||||||
self.copy_or_interrupt()
|
self.copy_or_interrupt()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user