From 86ce11134ab1ba391add805f8584a6d3e274f3d5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 May 2021 06:55:25 +0530 Subject: [PATCH] Unicode input kitten: Fix a regression in 0.20.0 that broke keyboard handling when the num lock or caps lock modifiers were engaged. Fixes #3587 --- docs/changelog.rst | 7 +++++++ kittens/resize_window/main.py | 2 +- kittens/unicode_input/main.py | 4 ++-- kitty/key_encoding.py | 10 +++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7ddb04a9d..c4fcda438 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,13 @@ Changelog |kitty| is a feature-rich, cross-platform, *fast*, GPU based terminal. To update |kitty|, :doc:`follow the instructions `. +0.20.4 [future] +---------------------- + +- Unicode input kitten: Fix a regression in 0.20.0 that broke keyboard handling + when the num lock or caps lock modifiers were engaged. (:iss:`3587`) + + 0.20.3 [2021-05-06] ---------------------- diff --git a/kittens/resize_window/main.py b/kittens/resize_window/main.py index 7c252abe5..ab7a15c50 100644 --- a/kittens/resize_window/main.py +++ b/kittens/resize_window/main.py @@ -74,7 +74,7 @@ class Resize(Handler): if key_event.matches('esc'): self.quit_loop(0) return - if key_event.key in ('w', 'n', 't', 's') and key_event.mods == CTRL: + if key_event.key in ('w', 'n', 't', 's') and key_event.mods_without_locks == CTRL: self.do_window_resize(is_decrease=key_event.key in 'ns', is_horizontal=key_event.key in 'wn', multiplier=2) def on_resize(self, new_size: ScreenSize) -> None: diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py index 953780940..be712af7d 100644 --- a/kittens/unicode_input/main.py +++ b/kittens/unicode_input/main.py @@ -416,7 +416,7 @@ class UnicodeInput(Handler): self.refresh() def on_key(self, key_event: KeyEvent) -> None: - if self.mode is HEX and key_event.type is not EventType.RELEASE and not key_event.mods: + if self.mode is HEX and key_event.type is not EventType.RELEASE and not key_event.has_mods: try: val = int(self.line_edit.current_input, 16) except Exception: @@ -434,7 +434,7 @@ class UnicodeInput(Handler): self.line_edit.current_input = hex(val - 1)[2:] self.refresh() return - if self.mode is NAME and key_event.type is not EventType.RELEASE and not key_event.mods: + if self.mode is NAME and key_event.type is not EventType.RELEASE and not key_event.has_mods: if key_event.matches('shift+tab'): self.table.move_current(cols=-1) self.refresh() diff --git a/kitty/key_encoding.py b/kitty/key_encoding.py index f6617da7a..e4ed27ec2 100644 --- a/kitty/key_encoding.py +++ b/kitty/key_encoding.py @@ -216,7 +216,7 @@ class KeyEvent(NamedTuple): num_lock: bool = False def matches(self, spec: Union[str, ParsedShortcut], types: int = EventType.PRESS | EventType.REPEAT) -> bool: - mods = self.mods & ~(NUM_LOCK | CAPS_LOCK) + mods = self.mods_without_locks if not self.type & types: return False if isinstance(spec, str): @@ -228,6 +228,14 @@ class KeyEvent(NamedTuple): return True return False + @property + def mods_without_locks(self) -> int: + return self.mods & ~(NUM_LOCK | CAPS_LOCK) + + @property + def has_mods(self) -> bool: + return bool(self.mods_without_locks) + def as_window_system_event(self) -> WindowSystemKeyEvent: action = defines.GLFW_PRESS if self.type is EventType.REPEAT: