From ab8a4c6b9f801a9a832ffec5da5c3c4fc7ddc9e2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 8 Apr 2022 14:52:53 +0530 Subject: [PATCH] Make per cell bias calculation overridable more easily --- kitty/layout/base.py | 7 +++++-- kitty/tabs.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kitty/layout/base.py b/kitty/layout/base.py index 450db9df5..16f4a7585 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -80,7 +80,7 @@ def set_layout_options(opts: Options) -> None: def calculate_cells_map(bias: Optional[Sequence[float]], number_of_windows: int, number_of_cells: int) -> List[int]: cells_per_window = number_of_cells // number_of_windows - if bias is not None and 1 < number_of_windows == len(bias) and cells_per_window > 5: + if bias is not None and number_of_windows > 1 and number_of_windows == len(bias) and cells_per_window > 5: cells_map = [int(b * number_of_cells) for b in bias] while min(cells_map) < 5: maxi, mini = map(cells_map.index, (max(cells_map), min(cells_map))) @@ -221,8 +221,11 @@ class Layout: self.full_name = f'{self.name}:{layout_opts}' if layout_opts else self.name self.remove_all_biases() - def bias_increment_for_cell(self, is_horizontal: bool) -> float: + def bias_increment_for_cell(self, all_windows: WindowList, window_id: int, is_horizontal: bool) -> float: self._set_dimensions() + return self.calculate_bias_increment_for_a_single_cell(all_windows, window_id, is_horizontal) + + def calculate_bias_increment_for_a_single_cell(self, all_windows: WindowList, window_id: int, is_horizontal: bool) -> float: if is_horizontal: return (lgd.cell_width + 1) / lgd.central.width return (lgd.cell_height + 1) / lgd.central.height diff --git a/kitty/tabs.py b/kitty/tabs.py index 357291ad7..82d29d73c 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -306,7 +306,7 @@ class Tab: # {{{ self.goto_layout(layout_name) def resize_window_by(self, window_id: int, increment: float, is_horizontal: bool) -> Optional[str]: - increment_as_percent = self.current_layout.bias_increment_for_cell(is_horizontal) * increment + increment_as_percent = self.current_layout.bias_increment_for_cell(self.windows, window_id, is_horizontal) * increment if self.current_layout.modify_size_of_window(self.windows, window_id, increment_as_percent, is_horizontal): self.relayout() return None