From 594ca3486803296861fd7cdc16e764c4f0348d2d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Dec 2016 07:37:29 +0530 Subject: [PATCH] Implement next_layout() --- kitty/layout.py | 2 +- kitty/tabs.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kitty/layout.py b/kitty/layout.py index 911148d1c..b4c3f5dd5 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -35,7 +35,7 @@ class Layout: name = None needs_window_borders = True - def __init__(self, opts, border_width): + def __init__(self, opts, border_width, windows): self.opts = opts self.border_width = border_width diff --git a/kitty/tabs.py b/kitty/tabs.py index d1dff709b..f262ed23a 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -68,15 +68,15 @@ class Tab: self.opts, self.args = opts, args self.enabled_layouts = opts.enabled_layouts self.borders = Borders(opts) + self.windows = deque() if args.window_layout: if args.window_layout not in self.enabled_layouts: self.enabled_layouts.insert(0, args.window_layout) self.current_layout = all_layouts[args.window_layout] else: self.current_layout = all_layouts[self.enabled_layouts[0]] - self.windows = deque() self.active_window_idx = 0 - self.current_layout = self.current_layout(opts, self.borders.border_width) + self.current_layout = self.current_layout(opts, self.borders.border_width, self.windows) @property def is_visible(self): @@ -100,6 +100,15 @@ class Tab: self.current_layout(self.windows, self.active_window_idx) self.borders(self.windows, self.active_window, self.current_layout.needs_window_borders and len(self.windows) > 1) + def next_layout(self): + if len(self.opts.enabled_layouts) > 1: + idx = self.opts.enabled_layouts.index(self.current_layout.name) + nl = self.opts.enabled_layouts[(idx + 1) % len(self.opts.enabled_layouts)] + self.current_layout = all_layouts[nl](self.opts, self.borders.border_width, self.windows) + for w in self.windows: + w.is_visible_in_layout = True + self.relayout() + def launch_child(self, use_shell=False): if use_shell: cmd = [shell_path]