mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-11 14:45:31 +03:00
Better integration point for keyboard mode change notification
This commit is contained in:
parent
9ea3f7b504
commit
95c44cac01
@ -377,7 +377,7 @@ def __init__(
|
||||
set_boss(self)
|
||||
self.args = args
|
||||
self.mouse_handler: Optional[Callable[[WindowSystemMouseEvent], None]] = None
|
||||
self.mappings = Mappings(global_shortcuts)
|
||||
self.mappings = Mappings(global_shortcuts, self.refresh_active_tab_bar)
|
||||
if is_macos:
|
||||
from .fast_data_types import cocoa_set_notification_activated_callback
|
||||
cocoa_set_notification_activated_callback(notification_activated)
|
||||
@ -1390,17 +1390,13 @@ def refresh_active_tab_bar(self) -> bool:
|
||||
End the current keyboard mode switching to the previous mode.
|
||||
''')
|
||||
def pop_keyboard_mode(self) -> bool:
|
||||
try:
|
||||
return self.mappings.pop_keyboard_mode()
|
||||
finally:
|
||||
self.refresh_active_tab_bar()
|
||||
return self.mappings.pop_keyboard_mode()
|
||||
|
||||
@ac('misc', '''
|
||||
Switch to the specified keyboard mode, pushing it onto the stack of keyboard modes.
|
||||
''')
|
||||
def push_keyboard_mode(self, new_mode: str) -> None:
|
||||
self.mappings.push_keyboard_mode(new_mode)
|
||||
self.refresh_active_tab_bar()
|
||||
|
||||
def dispatch_possible_special_key(self, ev: KeyEvent) -> bool:
|
||||
return self.mappings.dispatch_possible_special_key(ev)
|
||||
@ -1453,7 +1449,6 @@ def visual_window_select_action(
|
||||
self.mappings._push_keyboard_mode(km)
|
||||
redirect_mouse_handling(True)
|
||||
self.mouse_handler = self.visual_window_select_mouse_handler
|
||||
self.refresh_active_tab_bar()
|
||||
else:
|
||||
self.visual_window_select_action_trigger(self.current_visual_select.window_ids[0] if self.current_visual_select.window_ids else 0)
|
||||
if get_options().enable_audio_bell:
|
||||
@ -1469,7 +1464,6 @@ def visual_window_select_mouse_handler(self, ev: WindowSystemMouseEvent) -> None
|
||||
def trigger(window_id: int = 0) -> None:
|
||||
self.visual_window_select_action_trigger(window_id)
|
||||
self.mappings.pop_keyboard_mode_if_is('__visual_select__')
|
||||
self.refresh_active_tab_bar()
|
||||
|
||||
if ev.button == GLFW_MOUSE_BUTTON_LEFT and ev.action == GLFW_PRESS and ev.window_id:
|
||||
w = self.window_id_map.get(ev.window_id)
|
||||
|
@ -2,7 +2,7 @@
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from gettext import gettext as _
|
||||
from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Optional
|
||||
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator, List, Optional
|
||||
|
||||
from .constants import is_macos
|
||||
from .fast_data_types import (
|
||||
@ -63,9 +63,10 @@ class Mappings:
|
||||
|
||||
' Manage all keyboard mappings '
|
||||
|
||||
def __init__(self, global_shortcuts:Optional[Dict[str, SingleKey]] = None) -> None:
|
||||
def __init__(self, global_shortcuts:Optional[Dict[str, SingleKey]] = None, callback_on_mode_change: Callable[[], Any] = lambda: None) -> None:
|
||||
self.keyboard_mode_stack: List[KeyboardMode] = []
|
||||
self.update_keymap(global_shortcuts)
|
||||
self.callback_on_mode_change = callback_on_mode_change
|
||||
|
||||
@property
|
||||
def current_keyboard_mode_name(self) -> str:
|
||||
@ -83,8 +84,11 @@ def update_keymap(self, global_shortcuts:Optional[Dict[str, SingleKey]] = None)
|
||||
km.pop(sc, None)
|
||||
|
||||
def clear_keyboard_modes(self) -> None:
|
||||
had_mode = bool(self.keyboard_mode_stack)
|
||||
self.keyboard_mode_stack = []
|
||||
self.set_ignore_os_keyboard_processing(False)
|
||||
if had_mode:
|
||||
self.callback_on_mode_change()
|
||||
|
||||
def pop_keyboard_mode(self) -> bool:
|
||||
passthrough = True
|
||||
@ -93,6 +97,7 @@ def pop_keyboard_mode(self) -> bool:
|
||||
if not self.keyboard_mode_stack:
|
||||
self.set_ignore_os_keyboard_processing(False)
|
||||
passthrough = False
|
||||
self.callback_on_mode_change()
|
||||
return passthrough
|
||||
|
||||
def pop_keyboard_mode_if_is(self, name: str) -> bool:
|
||||
@ -103,6 +108,7 @@ def pop_keyboard_mode_if_is(self, name: str) -> bool:
|
||||
def _push_keyboard_mode(self, mode: KeyboardMode) -> None:
|
||||
self.keyboard_mode_stack.append(mode)
|
||||
self.set_ignore_os_keyboard_processing(True)
|
||||
self.callback_on_mode_change()
|
||||
|
||||
def push_keyboard_mode(self, new_mode: str) -> None:
|
||||
mode = self.keyboard_modes[new_mode]
|
||||
@ -204,6 +210,7 @@ def dispatch_possible_special_key(self, ev: KeyEvent) -> bool:
|
||||
if consumed and not is_root_mode and mode.on_action == 'end':
|
||||
if mode_pos < len(self.keyboard_mode_stack) and self.keyboard_mode_stack[mode_pos] is mode:
|
||||
del self.keyboard_mode_stack[mode_pos]
|
||||
self.callback_on_mode_change()
|
||||
if not self.keyboard_mode_stack:
|
||||
self.set_ignore_os_keyboard_processing(False)
|
||||
return consumed
|
||||
|
Loading…
Reference in New Issue
Block a user