From 5158d497817571386a28962fbadcb782b439d51b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 16 May 2018 15:57:04 +0530 Subject: [PATCH] Generalize bias handling --- kitty/layout.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kitty/layout.py b/kitty/layout.py index 87ec6dc68..f808dff02 100644 --- a/kitty/layout.py +++ b/kitty/layout.py @@ -42,14 +42,15 @@ def layout_dimension(start_at, length, cell_length, number_of_windows=1, border_ inner_length = cells_in_window * cell_length return 2 * (border_length + margin_length) + inner_length - if bias is not None and number_of_windows == 2: - cells_per_window = int(bias * number_of_cells) - window_length = calc_window_length(cells_per_window) - yield pos, cells_per_window - pos += window_length - cells_per_window = number_of_cells - cells_per_window - window_length = calc_window_length(cells_per_window) - yield pos, cells_per_window + if bias is not None and number_of_windows > 1 and len(bias) == number_of_windows: + cells_map = [int(b * number_of_cells) for b in bias] + extra = number_of_cells - sum(cells_map) + if extra: + cells_map[-1] += extra + for cells_per_window in cells_map: + window_length = calc_window_length(cells_per_window) + yield pos, cells_per_window + pos += window_length return window_length = calc_window_length(cells_per_window) @@ -318,6 +319,7 @@ class Tall(Layout): except Exception: ans['bias'] = 0.5 ans['bias'] = max(0.1, min(ans['bias'], 0.9)) + ans['bias'] = ans['bias'], 1.0 - ans['bias'] return ans def do_layout(self, windows, active_window_idx):