From 5ab484cac21796af22a52bc038d82a5ef0719f03 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 20 Jul 2024 13:11:06 +0530 Subject: [PATCH] Implement --bias for the grid layout --- kitty/launch.py | 8 ++++++++ kitty/layout/grid.py | 23 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/kitty/launch.py b/kitty/launch.py index 2d7c95dee..61c3388e2 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -213,6 +213,14 @@ layout above. * Fat layout: Same as tall layout except it goes by rows instead of columns. +* Grid layout: The bias is interpreted the same way as for the Vertical and Horizontal +layouts, as something to be added/subtracted to the normal size. However, the +since in a grid layout there are rows *and* columns, the bias on the first window in a column +operates on the columns. Any later windows in that column operate on the row. +So, for example, if you bias the first window in a grid layout it will change the width +of the first column, the second window, the width of the second column, the third window, +the height of the second row and so on. + The bias option was introduced in kitty version 0.36.0. diff --git a/kitty/layout/grid.py b/kitty/layout/grid.py index 4376e90c5..65032d6ed 100644 --- a/kitty/layout/grid.py +++ b/kitty/layout/grid.py @@ -73,10 +73,27 @@ class Grid(Layout): row_num += 1 return 0, 0 + def bias_slot(self, all_windows: WindowList, idx: int, fractional_bias: float, cell_increment_bias_h: float, cell_increment_bias_v: float) -> bool: + num_windows = all_windows.num_groups + ncols, nrows, special_rows, special_col = calc_grid_size(num_windows) + row_num, col_num = self.position_for_window_idx(idx, num_windows, ncols, nrows, special_rows, special_col) + if row_num == 0: + b = self.biased_cols + layout_func = self.column_layout + bias_idx = col_num + increment = cell_increment_bias_h + else: + b = self.biased_rows + layout_func = self.row_layout + bias_idx = row_num + increment = cell_increment_bias_v + before_layout = tuple(self.variable_layout(layout_func, num_windows, b)) + b[bias_idx] = increment + return tuple(self.variable_layout(layout_func, num_windows, b)) == before_layout + def apply_bias(self, idx: int, increment: float, all_windows: WindowList, is_horizontal: bool = True) -> bool: num_windows = all_windows.num_groups ncols, nrows, special_rows, special_col = calc_grid_size(num_windows) - row_num, col_num = self.position_for_window_idx(idx, num_windows, ncols, nrows, special_rows, special_col) if is_horizontal: @@ -99,11 +116,11 @@ class Grid(Layout): def layout_func(windows: ListOfWindows, bias: Optional[Sequence[float]] = None) -> LayoutDimension: return self.row_layout(num_windows, bias=bias) - before_layout = list(self.variable_layout(layout_func, num_windows, b)) + before_layout = tuple(self.variable_layout(layout_func, num_windows, b)) candidate = b.copy() before = candidate.get(bias_idx, 0) candidate[bias_idx] = before + increment - if before_layout == list(self.variable_layout(layout_func, num_windows, candidate)): + if before_layout == tuple(self.variable_layout(layout_func, num_windows, candidate)): return False setattr(self, attr, candidate) return True