diff --git a/kitty/config.py b/kitty/config.py index a037906d7..829403a01 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -111,6 +111,8 @@ def parse_key_action(action): args = rest.split(' ', 2) elif func == 'goto_tab': args = (max(0, int(rest)), ) + elif func == 'goto_layout': + args = [rest] elif func in shlex_actions: args = shlex.split(rest) return KeyAction(func, args) @@ -348,7 +350,7 @@ def parse_config(lines, check_keys=True): Options, defaults = init_config(default_config_path, parse_config) actions = frozenset(a.func for a in defaults.keymap.values()) | frozenset( - 'combine send_text goto_tab new_tab_with_cwd new_window_with_cwd new_os_window_with_cwd'. + 'combine send_text goto_tab goto_layout new_tab_with_cwd new_window_with_cwd new_os_window_with_cwd'. split() ) no_op_actions = frozenset({'noop', 'no-op', 'no_op'}) diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 153b741db..268af8df6 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -118,7 +118,7 @@ focus_follows_mouse no # The enabled window layouts. A comma separated list of layout names. The special value * means # all layouts. The first listed layout will be used as the startup layout. -# For a list of available layouts, see the file layouts.py +# For a list of available layouts, see the README. enabled_layouts * # If enabled, the window size will be remembered so that new instances of kitty will have the same @@ -336,6 +336,12 @@ map ctrl+shift+, move_tab_backward # commands to run when using new_tab and use new_tab_with_cwd. +# Layout management +# You can create shortcuts to switch to specific layouts +# map ctrl+alt+1 goto_layout tall +# map ctrl+alt+2 goto_layout stack + + # Miscellaneous map ctrl+shift+equal increase_font_size map ctrl+shift+minus decrease_font_size diff --git a/kitty/tabs.py b/kitty/tabs.py index b71a3573b..6c6b51e1e 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -17,7 +17,7 @@ from .fast_data_types import ( ) from .layout import Rect, all_layouts from .session import resolved_shell -from .utils import color_as_int +from .utils import color_as_int, log_error from .window import Window, calculate_gl_geometry TabbarData = namedtuple('TabbarData', 'title is_active is_last') @@ -116,6 +116,14 @@ class Tab: # {{{ self.current_layout = self.create_layout_object(nl) self.relayout() + def goto_layout(self, layout_name): + layout_name = layout_name.lower() + if layout_name not in self.enabled_layouts: + log_error('Unknown or disabled layout: {}'.format(layout_name)) + return + self.current_layout = self.create_layout_object(layout_name) + self.relayout() + def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None): if cmd is None: if use_shell: