From c600451bb8d480de38a19b46b10fc63e51e704ec Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 Jan 2025 08:37:07 +0530 Subject: [PATCH] Splits layout: Allow setting the bias of the current split using layout_action bias Fixes #8222 --- docs/changelog.rst | 6 ++++++ docs/layouts.rst | 6 ++++++ kitty/layout/splits.py | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 26adec100..c4759b015 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -84,6 +84,12 @@ consumption to do the same tasks. Detailed list of changes ------------------------------------- +0.39.1 [future] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- Splits layout: Allow setting the bias of the current split using ``layout_action bias`` (:iss:`8222`) + + 0.39.0 [2025-01-16] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/layouts.rst b/docs/layouts.rst index 1e29af667..46154d181 100644 --- a/docs/layouts.rst +++ b/docs/layouts.rst @@ -179,6 +179,12 @@ define a few extra key bindings in :file:`kitty.conf`:: map ctrl+up neighboring_window up map ctrl+down neighboring_window down + # Set the bias of the split containing the currently focused window. The + # currently focused window will take up the specified percent of its parent + # window's size. + map ctrl+. layout_action bias 80 + + Windows can be resized using :ref:`window_resizing`. You can swap the windows in a split using the ``rotate`` action with an argument of ``180`` and rotate and swap with an argument of ``270``. diff --git a/kitty/layout/splits.py b/kitty/layout/splits.py index 105c37afc..03ecbfb1c 100644 --- a/kitty/layout/splits.py +++ b/kitty/layout/splits.py @@ -288,6 +288,10 @@ class Pair: geom = window_geometry_from_layouts(xl, yl) self.apply_window_geometry(self.two, geom, id_window_map, layout_object) + def set_bias(self, window_id: int, bias: int) -> None: + b = max(0, min(bias, 100)) / 100 + self.bias = b if window_id == self.one else (1. - b) + def modify_size_of_child(self, which: int, increment: float, is_horizontal: bool, layout_object: 'Splits') -> bool: if is_horizontal == self.horizontal and not self.is_redundant: if which == 2: @@ -642,6 +646,15 @@ class Splits(Layout): new_root.two = wg.id self.pairs_root = new_root return True + elif action_name == 'bias': + args = args or ('50',) + bias = int(args[0]) + wg = all_windows.active_group + if wg is not None: + pair = self.pairs_root.pair_for_window(wg.id) + if pair is not None: + pair.set_bias(wg.id, bias) + return True return None