diff --git a/kitty/layout/vertical.py b/kitty/layout/vertical.py index 1c24f2d67..c50d3b398 100644 --- a/kitty/layout/vertical.py +++ b/kitty/layout/vertical.py @@ -2,14 +2,16 @@ # vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal -from typing import Dict, Generator +from typing import Dict, Generator, List, Tuple +from kitty.borders import BorderColor +from kitty.constants import Edges from kitty.typing import WindowType -from kitty.window_list import WindowList +from kitty.window_list import WindowGroup, WindowList from .base import ( - Borders, Layout, LayoutDimension, NeighborsMap, all_borders, no_borders, - variable_bias + BorderLine, Borders, Layout, LayoutData, LayoutDimension, NeighborsMap, + lgd, variable_bias ) @@ -18,6 +20,7 @@ class Vertical(Layout): name = 'vertical' main_is_horizontal = False only_between_border = Borders(False, False, False, True) + no_minimal_window_borders = True main_axis_layout = Layout.ylayout perp_axis_layout = Layout.xlayout @@ -26,6 +29,9 @@ class Vertical(Layout): bias = variable_bias(num_windows, biased_map) if num_windows else None return self.main_axis_layout(all_windows.iter_all_layoutable_groups(), bias=bias) + def fixed_layout(self, wg: WindowGroup) -> LayoutDimension: + return self.perp_axis_layout(iter((wg,)), border_mult=0 if lgd.draw_minimal_borders else 1) + def remove_all_biases(self) -> bool: self.biased_map: Dict[int, float] = {} return True @@ -45,33 +51,60 @@ class Vertical(Layout): self.biased_map = candidate return True + def generate_layout_data(self, all_windows: WindowList) -> Generator[Tuple[WindowGroup, LayoutData, LayoutData], None, None]: + ylayout = self.variable_layout(all_windows, self.biased_map) + for wg, yl in zip(all_windows.iter_all_layoutable_groups(), ylayout): + xl = next(self.fixed_layout(wg)) + if self.main_is_horizontal: + xl, yl = yl, xl + yield wg, xl, yl + def do_layout(self, all_windows: WindowList) -> None: window_count = all_windows.num_groups if window_count == 1: self.layout_single_window_group(next(all_windows.iter_all_layoutable_groups())) return - - ylayout = self.variable_layout(all_windows, self.biased_map) - for i, (wg, yl) in enumerate(zip(all_windows.iter_all_layoutable_groups(), ylayout)): - xl = next(self.perp_axis_layout(iter((wg,)))) - if self.main_is_horizontal: - xl, yl = yl, xl + for wg, xl, yl in self.generate_layout_data(all_windows): self.set_window_group_geometry(wg, xl, yl) - def minimal_borders(self, all_windows: WindowList, needs_borders_map: Dict[int, bool]) -> Generator[Borders, None, None]: - last_i = all_windows.num_groups - 1 + def window_independent_borders(self, all_windows: WindowList) -> Generator[BorderLine, None, None]: + window_count = all_windows.num_groups + if window_count == 1 or not lgd.draw_minimal_borders: + return groups = tuple(all_windows.iter_all_layoutable_groups()) - for i, wg in enumerate(groups): - if needs_borders_map[wg.id]: - yield all_borders - continue - if i == last_i: - yield no_borders - break - if needs_borders_map[groups[i+1].id]: - yield no_borders + needs_borders_map = all_windows.compute_needs_borders_map(lgd.draw_active_borders) + bw = groups[0].effective_border() + if not bw: + return + borders: List[BorderLine] = [] + active_group = all_windows.active_group + + for wg, xl, yl in self.generate_layout_data(all_windows): + if self.main_is_horizontal: + e1 = Edges( + xl.content_pos - xl.space_before, yl.content_pos - yl.space_before, + xl.content_pos - xl.space_before + bw, yl.content_pos + yl.content_size + yl.space_after + ) + e2 = Edges( + xl.content_pos + xl.content_size + xl.space_after - bw, yl.content_pos - yl.space_before, + xl.content_pos + xl.content_size + xl.space_after, yl.content_pos + yl.content_size + yl.space_after + ) else: - yield self.only_between_border + e1 = Edges( + xl.content_pos - xl.space_before, yl.content_pos - yl.space_before, + xl.content_pos + xl.content_size + xl.space_after, yl.content_pos - yl.space_before + bw + ) + e2 = Edges( + xl.content_pos - xl.space_before, yl.content_pos + yl.content_size + yl.space_after - bw, + xl.content_pos + xl.content_size + xl.space_after, yl.content_pos + yl.content_size + yl.space_after + ) + color = BorderColor.inactive + if needs_borders_map.get(wg.id): + color = BorderColor.active if wg is active_group else BorderColor.bell + borders.append(BorderLine(e1, color)) + borders.append(BorderLine(e2, color)) + for x in borders[1:-1]: + yield x def neighbors_for_window(self, window: WindowType, all_windows: WindowList) -> NeighborsMap: wg = all_windows.group_for_window(window)