Port vertical/horz layouts to new groups API
This commit is contained in:
parent
01c0e8da93
commit
f801c47d1e
@ -2,14 +2,14 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from typing import Dict, Generator, Optional
|
from typing import Dict, Generator
|
||||||
|
|
||||||
from kitty.typing import WindowType
|
from kitty.typing import WindowType
|
||||||
from kitty.window_list import WindowList
|
from kitty.window_list import WindowList
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
Borders, NeighborsMap, Layout, LayoutDimension, ListOfWindows,
|
Borders, Layout, LayoutDimension, NeighborsMap, all_borders, no_borders,
|
||||||
all_borders, no_borders, variable_bias
|
variable_bias
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -21,61 +21,65 @@ class Vertical(Layout):
|
|||||||
main_axis_layout = Layout.ylayout
|
main_axis_layout = Layout.ylayout
|
||||||
perp_axis_layout = Layout.xlayout
|
perp_axis_layout = Layout.xlayout
|
||||||
|
|
||||||
def variable_layout(self, windows: ListOfWindows, biased_map: Dict[int, float]) -> LayoutDimension:
|
def variable_layout(self, all_windows: WindowList, biased_map: Dict[int, float]) -> LayoutDimension:
|
||||||
num_windows = len(windows)
|
num_windows = all_windows.num_groups
|
||||||
bias = variable_bias(num_windows, biased_map) if num_windows else None
|
bias = variable_bias(num_windows, biased_map) if num_windows else None
|
||||||
return self.main_axis_layout(windows, bias=bias)
|
return self.main_axis_layout(all_windows.iter_all_layoutable_groups(), bias=bias)
|
||||||
|
|
||||||
def remove_all_biases(self) -> bool:
|
def remove_all_biases(self) -> bool:
|
||||||
self.biased_map: Dict[int, float] = {}
|
self.biased_map: Dict[int, float] = {}
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def apply_bias(self, idx: int, increment: float, top_level_windows: ListOfWindows, is_horizontal: bool = True) -> bool:
|
def apply_bias(self, idx: int, increment: float, all_windows: WindowList, is_horizontal: bool = True) -> bool:
|
||||||
if self.main_is_horizontal != is_horizontal:
|
if self.main_is_horizontal != is_horizontal:
|
||||||
return False
|
return False
|
||||||
num_windows = len(top_level_windows)
|
num_windows = all_windows.num_groups
|
||||||
if num_windows < 2:
|
if num_windows < 2:
|
||||||
return False
|
return False
|
||||||
before_layout = list(self.variable_layout(top_level_windows, self.biased_map))
|
before_layout = list(self.variable_layout(all_windows, self.biased_map))
|
||||||
candidate = self.biased_map.copy()
|
candidate = self.biased_map.copy()
|
||||||
before = candidate.get(idx, 0)
|
before = candidate.get(idx, 0)
|
||||||
candidate[idx] = before + increment
|
candidate[idx] = before + increment
|
||||||
if before_layout == list(self.variable_layout(top_level_windows, candidate)):
|
if before_layout == list(self.variable_layout(all_windows, candidate)):
|
||||||
return False
|
return False
|
||||||
self.biased_map = candidate
|
self.biased_map = candidate
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def do_layout(self, windows: WindowList, active_window_idx: int) -> None:
|
def do_layout(self, all_windows: WindowList) -> None:
|
||||||
window_count = len(windows)
|
window_count = all_windows.num_groups
|
||||||
if window_count == 1:
|
if window_count == 1:
|
||||||
self.layout_single_window(windows[0])
|
self.layout_single_window_group(next(all_windows.iter_all_layoutable_groups()))
|
||||||
return
|
return
|
||||||
|
|
||||||
ylayout = self.variable_layout(windows, self.biased_map)
|
ylayout = self.variable_layout(all_windows, self.biased_map)
|
||||||
for i, (w, yl) in enumerate(zip(windows, ylayout)):
|
for i, (wg, yl) in enumerate(zip(all_windows.iter_all_layoutable_groups(), ylayout)):
|
||||||
xl = next(self.perp_axis_layout([w]))
|
xl = next(self.perp_axis_layout(iter((wg,))))
|
||||||
if self.main_is_horizontal:
|
if self.main_is_horizontal:
|
||||||
xl, yl = yl, xl
|
xl, yl = yl, xl
|
||||||
self.set_window_geometry(w, i, xl, yl)
|
self.set_window_group_geometry(wg, xl, yl)
|
||||||
|
|
||||||
def minimal_borders(self, windows: WindowList, active_window: Optional[WindowType], needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]:
|
def minimal_borders(self, all_windows: WindowList, needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]:
|
||||||
last_i = len(windows) - 1
|
last_i = all_windows.num_groups - 1
|
||||||
for i, w in enumerate(windows):
|
groups = tuple(all_windows.iter_all_layoutable_groups())
|
||||||
if needs_borders_map[w.id]:
|
for i, wg in enumerate(groups):
|
||||||
|
if needs_borders_map[wg.id]:
|
||||||
yield all_borders
|
yield all_borders
|
||||||
continue
|
continue
|
||||||
if i == last_i:
|
if i == last_i:
|
||||||
yield no_borders
|
yield no_borders
|
||||||
break
|
break
|
||||||
if needs_borders_map[windows[i+1].id]:
|
if needs_borders_map[groups[i+1].id]:
|
||||||
yield no_borders
|
yield no_borders
|
||||||
else:
|
else:
|
||||||
yield self.only_between_border
|
yield self.only_between_border
|
||||||
|
|
||||||
def neighbors_for_window(self, window: WindowType, windows: WindowList) -> NeighborsMap:
|
def neighbors_for_window(self, window: WindowType, all_windows: WindowList) -> NeighborsMap:
|
||||||
idx = windows.index(window)
|
wg = all_windows.group_for_window(window)
|
||||||
before = [] if window is windows[0] else [windows[idx-1].id]
|
assert wg is not None
|
||||||
after = [] if window is windows[-1] else [windows[idx+1].id]
|
groups = tuple(all_windows.iter_all_layoutable_groups())
|
||||||
|
idx = groups.index(wg)
|
||||||
|
before = [] if wg is groups[0] else [groups[idx-1].id]
|
||||||
|
after = [] if wg is groups[-1] else [groups[idx+1].id]
|
||||||
if self.main_is_horizontal:
|
if self.main_is_horizontal:
|
||||||
return {'left': before, 'right': after, 'top': [], 'bottom': []}
|
return {'left': before, 'right': after, 'top': [], 'bottom': []}
|
||||||
return {'top': before, 'bottom': after, 'left': [], 'right': []}
|
return {'top': before, 'bottom': after, 'left': [], 'right': []}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user