From 9334ed773ebfdbfb4421fdd17be0e7e16a672582 Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 19 Jan 2022 14:05:51 +0800 Subject: [PATCH 1/4] Adjust the order of modifier key names to match the config and docs --- kitty/debug_config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kitty/debug_config.py b/kitty/debug_config.py index 68d2bb9c3..7ab07262e 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -45,8 +45,9 @@ def mod_to_names(mods: int) -> Iterator[str]: GLFW_MOD_ALT, GLFW_MOD_CAPS_LOCK, GLFW_MOD_CONTROL, GLFW_MOD_HYPER, GLFW_MOD_META, GLFW_MOD_NUM_LOCK, GLFW_MOD_SHIFT, GLFW_MOD_SUPER ) - modmap = {'shift': GLFW_MOD_SHIFT, 'alt': GLFW_MOD_ALT, 'ctrl': GLFW_MOD_CONTROL, ('cmd' if is_macos else 'super'): GLFW_MOD_SUPER, - 'hyper': GLFW_MOD_HYPER, 'meta': GLFW_MOD_META, 'num_lock': GLFW_MOD_NUM_LOCK, 'caps_lock': GLFW_MOD_CAPS_LOCK} + modmap = {'ctrl': GLFW_MOD_CONTROL, 'shift': GLFW_MOD_SHIFT, ('opt' if is_macos else 'alt'): GLFW_MOD_ALT, + ('cmd' if is_macos else 'super'): GLFW_MOD_SUPER, 'hyper': GLFW_MOD_HYPER, 'meta': GLFW_MOD_META, + 'caps_lock': GLFW_MOD_CAPS_LOCK, 'num_lock': GLFW_MOD_NUM_LOCK} for name, val in modmap.items(): if mods & val: yield name From ff1efebf702ff78ef70acfb58ebcb77add3592b5 Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 19 Jan 2022 14:07:45 +0800 Subject: [PATCH 2/4] Fix mouse maps are indented with one more space --- kitty/debug_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kitty/debug_config.py b/kitty/debug_config.py index 7ab07262e..b5f417902 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -102,7 +102,7 @@ def compare_mousemaps(final: MouseMap, initial: MouseMap, print: Callable[..., N names = list(mod_to_names(trigger.mods)) + [f'b{trigger.button+1}'] when = {-1: 'repeat', 1: 'press', 2: 'doublepress', 3: 'triplepress'}.get(trigger.repeat_count, trigger.repeat_count) grabbed = 'grabbed' if trigger.grabbed else 'ungrabbed' - print('\t', '+'.join(names), when, grabbed, defn) + print('\t' + '+'.join(names), when, grabbed, defn) def print_changes(defns: MouseMap, changes: Set[MouseEvent], text: str) -> None: if changes: From 7bf7cc284d4841d8ffa2a8e6324044163c78841e Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 19 Jan 2022 14:12:39 +0800 Subject: [PATCH 3/4] Add the missing mouse triggers click (-2) and double-click (-3) --- kitty/debug_config.py | 19 +++++++++++++++---- kitty/options/utils.py | 6 ++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/kitty/debug_config.py b/kitty/debug_config.py index b5f417902..f2aec186b 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -20,10 +20,9 @@ from .constants import ( ) from .fast_data_types import Color, num_users from .options.types import Options as KittyOpts, defaults -from .options.utils import MouseMap +from .options.utils import MouseMap, SequenceMap, mouse_button_map, mouse_trigger_count_map from .rgb import color_as_sharp from .types import MouseEvent, SingleKey -from .typing import SequenceMap ShortcutMap = Dict[Tuple[SingleKey, ...], str] @@ -53,6 +52,18 @@ def mod_to_names(mods: int) -> Iterator[str]: yield name +def mouse_button_num_to_name(num: int) -> str: + button_map = {v: k for k, v in mouse_button_map.items()} + name = f'b{num+1}' + return button_map.get(name, name) + + +def mouse_trigger_count_to_name(count: int) -> str: + trigger_count_map = {str(v): k for k, v in mouse_trigger_count_map.items()} + k = str(count) + return trigger_count_map.get(k, k) + + def print_shortcut(key_sequence: Iterable[SingleKey], defn: str, print: Callable[..., None]) -> None: from .fast_data_types import glfw_get_key_name keys = [] @@ -99,8 +110,8 @@ def compare_mousemaps(final: MouseMap, initial: MouseMap, print: Callable[..., N changed = {k for k in set(final) & set(initial) if final[k] != initial[k]} def print_mouse_action(trigger: MouseEvent, defn: str) -> None: - names = list(mod_to_names(trigger.mods)) + [f'b{trigger.button+1}'] - when = {-1: 'repeat', 1: 'press', 2: 'doublepress', 3: 'triplepress'}.get(trigger.repeat_count, trigger.repeat_count) + names = list(mod_to_names(trigger.mods)) + [mouse_button_num_to_name(trigger.button)] + when = mouse_trigger_count_to_name(trigger.repeat_count) grabbed = 'grabbed' if trigger.grabbed else 'ungrabbed' print('\t' + '+'.join(names), when, grabbed, defn) diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 5e6227f08..d4d9848c1 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -42,6 +42,8 @@ character_key_name_aliases_with_ascii_lowercase: Dict[str, str] = character_key_ for x in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': character_key_name_aliases_with_ascii_lowercase[x] = x.lower() sequence_sep = '>' +mouse_button_map = {'left': 'b1', 'middle': 'b3', 'right': 'b2'} +mouse_trigger_count_map = {'doubleclick': -3, 'click': -2, 'release': -1, 'press': 1, 'doublepress': 2, 'triplepress': 3} FuncArgsType = Tuple[str, Sequence[Any]] func_with_args = KeyFuncWrapper[FuncArgsType]() DELETE_ENV_VAR = '_delete_this_env_var_' @@ -1054,13 +1056,13 @@ def parse_mouse_map(val: str) -> Iterable[MouseMapping]: obutton = parts[0].lower() mods = 0 try: - b = {'left': 'b1', 'middle': 'b3', 'right': 'b2'}.get(obutton, obutton)[1:] + b = mouse_button_map.get(obutton, obutton)[1:] button = getattr(defines, f'GLFW_MOUSE_BUTTON_{b}') except Exception: log_error(f'Mouse button: {xbutton} not recognized, ignoring') return try: - count = {'doubleclick': -3, 'click': -2, 'release': -1, 'press': 1, 'doublepress': 2, 'triplepress': 3}[event.lower()] + count = mouse_trigger_count_map[event.lower()] except KeyError: log_error(f'Mouse event type: {event} not recognized, ignoring') return From bac84f31b3b67e8de3acc0d77d046c266bb268a6 Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 19 Jan 2022 15:26:02 +0800 Subject: [PATCH 4/4] Refactor the print functions to make it easier to use in kitten --- kitty/debug_config.py | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/kitty/debug_config.py b/kitty/debug_config.py index f2aec186b..e504c2cd2 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -79,21 +79,43 @@ def print_shortcut(key_sequence: Iterable[SingleKey], defn: str, print: Callable print('\t' + ' > '.join(keys), defn) -def print_shortcut_changes(defns: ShortcutMap, text: str, changes: Set[Tuple[SingleKey, ...]], print: Callable[..., None]) -> None: +def print_mouse_action(trigger: MouseEvent, defn: str, print: Callable[..., None]) -> None: + names = list(mod_to_names(trigger.mods)) + [mouse_button_num_to_name(trigger.button)] + when = mouse_trigger_count_to_name(trigger.repeat_count) + grabbed = 'grabbed' if trigger.grabbed else 'ungrabbed' + print('\t' + '+'.join(names), when, grabbed, defn) + + +def print_shortcut_changes(defns: ShortcutMap, changes: Set[Tuple[SingleKey, ...]], text: str, print: Callable[..., None]) -> None: if changes: print(title(text)) + for k in sorted(changes): + print_shortcut(k, defns[k], print) - for k in sorted(changes): - print_shortcut(k, defns[k], print) + +def print_mousemap_changes(defns: MouseMap, changes: Set[MouseEvent], text: str, print: Callable[..., None]) -> None: + if changes: + print(title(text)) + for k in sorted(changes): + print_mouse_action(k, defns[k], print) def compare_keymaps(final: ShortcutMap, initial: ShortcutMap, print: Callable[..., None]) -> None: added = set(final) - set(initial) removed = set(initial) - set(final) changed = {k for k in set(final) & set(initial) if final[k] != initial[k]} - print_shortcut_changes(final, 'Added shortcuts:', added, print) - print_shortcut_changes(initial, 'Removed shortcuts:', removed, print) - print_shortcut_changes(final, 'Changed shortcuts:', changed, print) + print_shortcut_changes(final, added, 'Added shortcuts:', print) + print_shortcut_changes(initial, removed, 'Removed shortcuts:', print) + print_shortcut_changes(final, changed, 'Changed shortcuts:', print) + + +def compare_mousemaps(final: MouseMap, initial: MouseMap, print: Callable[..., None]) -> None: + added = set(final) - set(initial) + removed = set(initial) - set(final) + changed = {k for k in set(final) & set(initial) if final[k] != initial[k]} + print_mousemap_changes(final, added, 'Added mouse actions:', print) + print_mousemap_changes(initial, removed, 'Removed mouse actions:', print) + print_mousemap_changes(final, changed, 'Changed mouse actions:', print) def flatten_sequence_map(m: SequenceMap) -> ShortcutMap: @@ -104,28 +126,6 @@ def flatten_sequence_map(m: SequenceMap) -> ShortcutMap: return ans -def compare_mousemaps(final: MouseMap, initial: MouseMap, print: Callable[..., None]) -> None: - added = set(final) - set(initial) - removed = set(initial) - set(final) - changed = {k for k in set(final) & set(initial) if final[k] != initial[k]} - - def print_mouse_action(trigger: MouseEvent, defn: str) -> None: - names = list(mod_to_names(trigger.mods)) + [mouse_button_num_to_name(trigger.button)] - when = mouse_trigger_count_to_name(trigger.repeat_count) - grabbed = 'grabbed' if trigger.grabbed else 'ungrabbed' - print('\t' + '+'.join(names), when, grabbed, defn) - - def print_changes(defns: MouseMap, changes: Set[MouseEvent], text: str) -> None: - if changes: - print(title(text)) - for k in sorted(changes): - print_mouse_action(k, defns[k]) - - print_changes(final, added, 'Added mouse actions:') - print_changes(initial, removed, 'Removed mouse actions:') - print_changes(final, changed, 'Changed mouse actions:') - - def compare_opts(opts: KittyOpts, print: Callable[..., None]) -> None: from .config import load_config print()