Implement next_layout()

This commit is contained in:
Kovid Goyal
2016-12-05 07:37:29 +05:30
parent 7cde189bf5
commit 594ca34868
2 changed files with 12 additions and 3 deletions

View File

@@ -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

View File

@@ -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]