diff --git a/kitty/layout/base.py b/kitty/layout/base.py index b5226caff..ed1f164ee 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -5,8 +5,8 @@ from functools import partial from itertools import repeat from typing import ( - Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional, Sequence, - Tuple + Any, Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional, + Sequence, Tuple ) from kitty.borders import BorderColor @@ -380,3 +380,6 @@ class Layout: def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList) -> Optional[bool]: pass + + def layout_state(self) -> Dict[str, Any]: + return {} diff --git a/kitty/layout/grid.py b/kitty/layout/grid.py index b1d0447ab..cadc25c63 100644 --- a/kitty/layout/grid.py +++ b/kitty/layout/grid.py @@ -6,7 +6,7 @@ from functools import lru_cache from itertools import repeat from math import ceil, floor from typing import ( - Callable, Dict, Generator, List, Optional, Sequence, Set, Tuple + Any, Callable, Dict, Generator, List, Optional, Sequence, Set, Tuple ) from kitty.borders import BorderColor @@ -294,3 +294,9 @@ class Grid(Layout): 'left': side(row, col, -1) if col else [], 'right': side(row, col, 1) if col < ncols - 1 else [], } + + def layout_state(self) -> Dict[str, Any]: + return { + 'biased_cols': self.biased_cols, + 'biased_rows': self.biased_rows + } diff --git a/kitty/layout/splits.py b/kitty/layout/splits.py index c7a8245fe..2dbc89f7f 100644 --- a/kitty/layout/splits.py +++ b/kitty/layout/splits.py @@ -3,7 +3,7 @@ # License: GPLv3 Copyright: 2020, Kovid Goyal from typing import ( - Collection, Dict, Generator, List, NamedTuple, Optional, Sequence, Tuple, + Any, Collection, Dict, Generator, List, NamedTuple, Optional, Sequence, Tuple, Union ) @@ -546,3 +546,21 @@ class Splits(Layout): if swap: pair.one, pair.two = pair.two, pair.one return True + + def layout_state(self) -> Dict[str, Any]: + + def add_pair(p: Pair) -> Dict[str, Any]: + ans: Dict[str, Any] = {} + ans['horizontal'] = p.horizontal + ans['bias'] = p.bias + if isinstance(p.one, Pair): + ans['one'] = add_pair(p.one) + elif p.one is not None: + ans['one'] = p.one + if isinstance(p.two, Pair): + ans['two'] = add_pair(p.two) + elif p.one is not None: + ans['two'] = p.two + return ans + + return {'pairs': add_pair(self.pairs_root)} diff --git a/kitty/layout/tall.py b/kitty/layout/tall.py index 1251b7880..db991ac55 100644 --- a/kitty/layout/tall.py +++ b/kitty/layout/tall.py @@ -3,7 +3,7 @@ # License: GPLv3 Copyright: 2020, Kovid Goyal from itertools import islice, repeat -from typing import Dict, Generator, List, Optional, Sequence, Tuple +from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple from kitty.borders import BorderColor from kitty.conf.utils import to_bool @@ -278,6 +278,13 @@ class Tall(Layout): ) yield from perp_borders[1:-1] + def layout_state(self) -> Dict[str, Any]: + return { + 'num_full_size_windows': self.num_full_size_windows, + 'main_bias': self.main_bias, + 'biased_map': self.biased_map + } + class Fat(Tall): diff --git a/kitty/layout/vertical.py b/kitty/layout/vertical.py index ced52e85d..70846120b 100644 --- a/kitty/layout/vertical.py +++ b/kitty/layout/vertical.py @@ -2,7 +2,7 @@ # vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal -from typing import Dict, Generator, Iterable, List, Tuple +from typing import Any, Dict, Generator, Iterable, List, Tuple from kitty.borders import BorderColor from kitty.types import Edges @@ -130,6 +130,9 @@ class Vertical(Layout): return {'left': before, 'right': after, 'top': [], 'bottom': []} return {'top': before, 'bottom': after, 'left': [], 'right': []} + def layout_state(self) -> Dict[str, Any]: + return {'biased_map': self.biased_map} + class Horizontal(Vertical): diff --git a/kitty/tabs.py b/kitty/tabs.py index 90bfbb896..94b0865bc 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -38,6 +38,7 @@ class TabDict(TypedDict): is_focused: bool title: str layout: str + layout_state: Dict[str, Any] windows: List[WindowDict] active_window_history: List[int] @@ -671,6 +672,7 @@ class TabManager: # {{{ 'is_focused': tab is active_tab, 'title': tab.name or tab.title, 'layout': str(tab.current_layout.name), + 'layout_state': tab.current_layout.layout_state(), 'windows': list(tab.list_windows(active_window, self_window)), 'active_window_history': list(tab.windows.active_window_history), }