From db5a2d2141ca5ad4c52258d6023d7034c821299b Mon Sep 17 00:00:00 2001 From: bdeshi Date: Sat, 7 Aug 2021 21:33:56 +0600 Subject: [PATCH] add `clear_all_mouse_shortcuts` option to clear mouse_maps --- kitty/config.py | 7 +++++-- kitty/options/definition.py | 8 ++++++++ kitty/options/parse.py | 7 +++++-- kitty/options/types.py | 2 ++ kitty/options/utils.py | 7 +++++++ kitty_tests/options.py | 2 ++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/kitty/config.py b/kitty/config.py index b6e7e30e7..e895493b0 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -123,9 +123,12 @@ def finalize_keys(opts: Options) -> None: def finalize_mouse_mappings(opts: Options) -> None: defns: List[MouseMapping] = [] for d in opts.mouse_map: - defns.append(d.resolve_and_copy(opts.kitty_mod, opts.kitten_alias)) - + if d is None: # clear_all_mouse_shortcuts + defns = [] # type: ignore + else: + defns.append(d.resolve_and_copy(opts.kitty_mod, opts.kitten_alias)) mousemap: MouseMap = {} + for defn in defns: is_no_op = defn.action.func in no_op_actions if is_no_op: diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 585c8e81b..beb7d8cf2 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -499,6 +499,14 @@ of URLs with a plain click:: automatically end it and no release event will be dispatched. ''') +opt('clear_all_mouse_shortcuts', 'no', + option_type='clear_all_mouse_shortcuts', + long_text=''' +You can have kitty remove all mouse shortcut definition seen up to this point. +Useful, for instance, to remove the default mouse shortcuts. +''' + ) + mma('Click the link under the mouse cursor when no selection is created', 'click_url_or_select left click ungrabbed mouse_click_url_or_select', ) diff --git a/kitty/options/parse.py b/kitty/options/parse.py index a9d87321b..05d5cc60c 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -8,8 +8,8 @@ from kitty.conf.utils import ( ) from kitty.options.utils import ( active_tab_title_template, adjust_baseline, adjust_line_height, allow_hyperlinks, - allow_remote_control, box_drawing_scale, clear_all_shortcuts, clipboard_control, - config_or_absolute_path, copy_on_select, cursor_text_color, + allow_remote_control, box_drawing_scale, clear_all_mouse_shortcuts, clear_all_shortcuts, + clipboard_control, config_or_absolute_path, copy_on_select, cursor_text_color, deprecated_hide_window_decorations_aliases, deprecated_macos_show_window_title_in_menubar_alias, deprecated_send_text, disable_ligatures, edge_width, env, font_features, hide_window_decorations, kitten_alias, macos_option_as_alt, macos_titlebar_color, optional_edge_width, parse_map, @@ -93,6 +93,9 @@ class Parser: def clear_all_shortcuts(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: clear_all_shortcuts(val, ans) + def clear_all_mouse_shortcuts(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: + clear_all_mouse_shortcuts(val, ans) + def click_interval(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['click_interval'] = float(val) diff --git a/kitty/options/types.py b/kitty/options/types.py index 7cd75cdb9..95af7a7ae 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -61,6 +61,7 @@ option_names = ( # {{{ 'bold_font', 'bold_italic_font', 'box_drawing_scale', + 'clear_all_mouse_shortcuts', 'clear_all_shortcuts', 'click_interval', 'clipboard_control', @@ -453,6 +454,7 @@ class Options: bold_font: str = 'auto' bold_italic_font: str = 'auto' box_drawing_scale: typing.Tuple[float, float, float, float] = (0.001, 1.0, 1.5, 2.0) + clear_all_mouse_shortcuts: bool = False clear_all_shortcuts: bool = False click_interval: float = -1.0 clipboard_control: typing.Tuple[str, ...] = ('write-clipboard', 'write-primary') diff --git a/kitty/options/utils.py b/kitty/options/utils.py index bf55a0a58..3c1a0c52a 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -696,6 +696,13 @@ def tab_bar_margin_height(x: str) -> TabBarMarginHeight: return TabBarMarginHeight(next(ans), next(ans)) +def clear_all_mouse_shortcuts(val: str, dict_with_parse_results: Optional[Dict[str, Any]] = None) -> bool: + ans = to_bool(val) + if ans and dict_with_parse_results is not None: + dict_with_parse_results['mouse_map'] = [None] + return ans + + def clear_all_shortcuts(val: str, dict_with_parse_results: Optional[Dict[str, Any]] = None) -> bool: ans = to_bool(val) if ans and dict_with_parse_results is not None: diff --git a/kitty_tests/options.py b/kitty_tests/options.py index 299401b99..76da10888 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -41,6 +41,8 @@ class TestConfParsing(BaseTest): self.assertFalse(opts.keymap) opts = p('clear_all_shortcuts y', 'map f1 next_window') self.ae(len(opts.keymap), 1) + opts = p('clear_all_mouse_shortcuts y', 'mouse_map left click ungrabbed mouse_click_url_or_select') + self.ae(len(opts.mousemap), 1) opts = p('strip_trailing_spaces always') self.ae(opts.strip_trailing_spaces, 'always') self.assertFalse(bad_lines)