diff --git a/kitty/config.py b/kitty/config.py index 0f669f2f1..d97f4a2c0 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -241,6 +241,14 @@ def disable_ligatures_in(func, rest): return func, [where, strategy] +@func_with_args('layout_action') +def layout_action(func, rest): + parts = rest.split(maxsplit=1) + if not parts: + raise ValueError('layout_action must have at least one argument') + return func, [parts[0], tuple(parts[1:])] + + def parse_marker_spec(ftype, parts): flags = re.UNICODE if ftype in ('text', 'itext', 'regex', 'iregex'): diff --git a/kitty/layout.py b/kitty/layout.py index 1bf57e7d3..ca22ec717 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -457,6 +457,9 @@ class Layout: # {{{ yield all_borders else: yield no_borders + + def layout_action(self, action_name, args, all_windows, active_window_idx): + pass # }}} @@ -1363,6 +1366,27 @@ class Splits(Layout): else: p2.two = w1 + def layout_action(self, action_name, args, all_windows, active_window_idx): + if action_name == 'rotate': + args = args or ('90',) + try: + amt = int(args[0]) + except Exception: + amt = 90 + if amt not in (90, 180, 270): + amt = 90 + rotate = amt in (90, 270) + swap = amt in (180, 270) + w = all_windows[active_window_idx] + wid = w.overlay_for or w.id + pair = self.pairs_root.pair_for_window(wid) + if pair is not None and not pair.is_redundant: + if rotate: + pair.horizontal = not pair.horizontal + if swap: + pair.one, pair.two = pair.two, pair.one + return True + # }}} diff --git a/kitty/tabs.py b/kitty/tabs.py index d8ad5e43f..9a0cc08f9 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -236,6 +236,15 @@ class Tab: # {{{ if self.current_layout.remove_all_biases(): self.relayout() + def layout_action(self, action_name, args): + ret = self.current_layout.layout_action(action_name, args, self.windows, self.active_window_idx) + if ret is None: + ring_bell() + return + if isinstance(ret, int) and not isinstance(ret, bool): + self.active_window_idx = ret + self.relayout() + def launch_child(self, use_shell=False, cmd=None, stdin=None, cwd_from=None, cwd=None, env=None, allow_remote_control=False): if cmd is None: if use_shell: