Add configurable keyboard shortcuts to switch to a specific layout

Fixes #369
This commit is contained in:
Kovid Goyal 2018-03-10 23:34:47 +05:30
parent d7b2ac97b5
commit 4dfe1b664f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 19 additions and 3 deletions

View File

@ -111,6 +111,8 @@ def parse_key_action(action):
args = rest.split(' ', 2) args = rest.split(' ', 2)
elif func == 'goto_tab': elif func == 'goto_tab':
args = (max(0, int(rest)), ) args = (max(0, int(rest)), )
elif func == 'goto_layout':
args = [rest]
elif func in shlex_actions: elif func in shlex_actions:
args = shlex.split(rest) args = shlex.split(rest)
return KeyAction(func, args) return KeyAction(func, args)
@ -348,7 +350,7 @@ def parse_config(lines, check_keys=True):
Options, defaults = init_config(default_config_path, parse_config) Options, defaults = init_config(default_config_path, parse_config)
actions = frozenset(a.func for a in defaults.keymap.values()) | frozenset( 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() split()
) )
no_op_actions = frozenset({'noop', 'no-op', 'no_op'}) no_op_actions = frozenset({'noop', 'no-op', 'no_op'})

View File

@ -118,7 +118,7 @@ focus_follows_mouse no
# The enabled window layouts. A comma separated list of layout names. The special value * means # 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. # 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 * enabled_layouts *
# If enabled, the window size will be remembered so that new instances of kitty will have the same # 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. # 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 # Miscellaneous
map ctrl+shift+equal increase_font_size map ctrl+shift+equal increase_font_size
map ctrl+shift+minus decrease_font_size map ctrl+shift+minus decrease_font_size

View File

@ -17,7 +17,7 @@ from .fast_data_types import (
) )
from .layout import Rect, all_layouts from .layout import Rect, all_layouts
from .session import resolved_shell 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 from .window import Window, calculate_gl_geometry
TabbarData = namedtuple('TabbarData', 'title is_active is_last') TabbarData = namedtuple('TabbarData', 'title is_active is_last')
@ -116,6 +116,14 @@ class Tab: # {{{
self.current_layout = self.create_layout_object(nl) self.current_layout = self.create_layout_object(nl)
self.relayout() 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): def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None):
if cmd is None: if cmd is None:
if use_shell: if use_shell: