mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
Splits layout: Allow setting the split_axis option to auto so that all new windows have their split axis chosen automatically unless explicitly specified in the launch command
Fixes #7887
This commit is contained in:
@@ -93,6 +93,8 @@ Detailed list of changes
|
|||||||
|
|
||||||
- Remote control: Fix ``--match state:self`` not working (:disc:`7886`)
|
- Remote control: Fix ``--match state:self`` not working (:disc:`7886`)
|
||||||
|
|
||||||
|
- Splits layout: Allow setting the ``split_axis`` option to ``auto`` so that all new windows have their split axis chosen automatically unless explicitly specified in the launch command (:iss:`7887`)
|
||||||
|
|
||||||
0.36.2 [2024-09-06]
|
0.36.2 [2024-09-06]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -184,11 +184,13 @@ in a split using the ``rotate`` action with an argument of ``180`` and rotate
|
|||||||
and swap with an argument of ``270``.
|
and swap with an argument of ``270``.
|
||||||
|
|
||||||
This layout takes one option, ``split_axis`` that controls whether new windows
|
This layout takes one option, ``split_axis`` that controls whether new windows
|
||||||
are placed into vertical or horizontal splits when a :option:`--location <launch
|
are placed into vertical or horizontal splits when a :option:`--location
|
||||||
--location>` is not specified. A value of ``horizontal`` (same as
|
<launch --location>` is not specified. A value of ``horizontal`` (same as
|
||||||
``--location=vsplit``) means when a new split is created the two windows will be
|
``--location=vsplit``) means when a new split is created the two windows will
|
||||||
placed side by side and a value of ``vertical`` (same as ``--location=hsplit``)
|
be placed side by side and a value of ``vertical`` (same as
|
||||||
means the two windows will be placed one on top of the other. By default::
|
``--location=hsplit``) means the two windows will be placed one on top of the
|
||||||
|
other. A value of ``auto`` means the axis of the split is chosen automatically
|
||||||
|
(same as ``--location=split``). By default::
|
||||||
|
|
||||||
enabled_layouts splits:split_axis=horizontal
|
enabled_layouts splits:split_axis=horizontal
|
||||||
|
|
||||||
|
|||||||
@@ -423,10 +423,14 @@ class Pair:
|
|||||||
|
|
||||||
class SplitsLayoutOpts(LayoutOpts):
|
class SplitsLayoutOpts(LayoutOpts):
|
||||||
|
|
||||||
default_axis_is_horizontal: bool = True
|
default_axis_is_horizontal: bool | None = True
|
||||||
|
|
||||||
def __init__(self, data: Dict[str, str]):
|
def __init__(self, data: Dict[str, str]):
|
||||||
self.default_axis_is_horizontal = data.get('split_axis', 'horizontal') == 'horizontal'
|
q = data.get('split_axis', 'horizontal')
|
||||||
|
if q == 'auto':
|
||||||
|
self.default_axis_is_horizontal = None
|
||||||
|
else:
|
||||||
|
self.default_axis_is_horizontal = q == 'horizontal'
|
||||||
|
|
||||||
def serialized(self) -> Dict[str, Any]:
|
def serialized(self) -> Dict[str, Any]:
|
||||||
return {'default_axis_is_horizontal': self.default_axis_is_horizontal}
|
return {'default_axis_is_horizontal': self.default_axis_is_horizontal}
|
||||||
@@ -439,14 +443,17 @@ class Splits(Layout):
|
|||||||
no_minimal_window_borders = True
|
no_minimal_window_borders = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_axis_is_horizontal(self) -> bool:
|
def default_axis_is_horizontal(self) -> bool | None:
|
||||||
return self.layout_opts.default_axis_is_horizontal
|
return self.layout_opts.default_axis_is_horizontal
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pairs_root(self) -> Pair:
|
def pairs_root(self) -> Pair:
|
||||||
root: Optional[Pair] = getattr(self, '_pairs_root', None)
|
root: Optional[Pair] = getattr(self, '_pairs_root', None)
|
||||||
if root is None:
|
if root is None:
|
||||||
self._pairs_root = root = Pair(horizontal=self.default_axis_is_horizontal)
|
horizontal = self.default_axis_is_horizontal
|
||||||
|
if horizontal is None:
|
||||||
|
horizontal = True
|
||||||
|
self._pairs_root = root = Pair(horizontal=horizontal)
|
||||||
return root
|
return root
|
||||||
|
|
||||||
@pairs_root.setter
|
@pairs_root.setter
|
||||||
@@ -508,7 +515,7 @@ class Splits(Layout):
|
|||||||
group_id = ag.id
|
group_id = ag.id
|
||||||
pair = self.pairs_root.pair_for_window(group_id)
|
pair = self.pairs_root.pair_for_window(group_id)
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
if location == 'split':
|
if location == 'split' or horizontal is None:
|
||||||
wwidth = aw.geometry.right - aw.geometry.left
|
wwidth = aw.geometry.right - aw.geometry.left
|
||||||
wheight = aw.geometry.bottom - aw.geometry.top
|
wheight = aw.geometry.bottom - aw.geometry.top
|
||||||
horizontal = wwidth >= wheight
|
horizontal = wwidth >= wheight
|
||||||
|
|||||||
Reference in New Issue
Block a user