Use new minimal borders style for vertical layouts
This commit is contained in:
parent
cf3f9d68b3
commit
7a2c2587ba
@ -2,14 +2,16 @@
|
|||||||
# 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
|
from typing import Dict, Generator, List, Tuple
|
||||||
|
|
||||||
|
from kitty.borders import BorderColor
|
||||||
|
from kitty.constants import Edges
|
||||||
from kitty.typing import WindowType
|
from kitty.typing import WindowType
|
||||||
from kitty.window_list import WindowList
|
from kitty.window_list import WindowGroup, WindowList
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
Borders, Layout, LayoutDimension, NeighborsMap, all_borders, no_borders,
|
BorderLine, Borders, Layout, LayoutData, LayoutDimension, NeighborsMap,
|
||||||
variable_bias
|
lgd, variable_bias
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +20,7 @@ class Vertical(Layout):
|
|||||||
name = 'vertical'
|
name = 'vertical'
|
||||||
main_is_horizontal = False
|
main_is_horizontal = False
|
||||||
only_between_border = Borders(False, False, False, True)
|
only_between_border = Borders(False, False, False, True)
|
||||||
|
no_minimal_window_borders = True
|
||||||
main_axis_layout = Layout.ylayout
|
main_axis_layout = Layout.ylayout
|
||||||
perp_axis_layout = Layout.xlayout
|
perp_axis_layout = Layout.xlayout
|
||||||
|
|
||||||
@ -26,6 +29,9 @@ class Vertical(Layout):
|
|||||||
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(all_windows.iter_all_layoutable_groups(), bias=bias)
|
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:
|
def remove_all_biases(self) -> bool:
|
||||||
self.biased_map: Dict[int, float] = {}
|
self.biased_map: Dict[int, float] = {}
|
||||||
return True
|
return True
|
||||||
@ -45,33 +51,60 @@ class Vertical(Layout):
|
|||||||
self.biased_map = candidate
|
self.biased_map = candidate
|
||||||
return True
|
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:
|
def do_layout(self, all_windows: WindowList) -> None:
|
||||||
window_count = all_windows.num_groups
|
window_count = all_windows.num_groups
|
||||||
if window_count == 1:
|
if window_count == 1:
|
||||||
self.layout_single_window_group(next(all_windows.iter_all_layoutable_groups()))
|
self.layout_single_window_group(next(all_windows.iter_all_layoutable_groups()))
|
||||||
return
|
return
|
||||||
|
for wg, xl, yl in self.generate_layout_data(all_windows):
|
||||||
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
|
|
||||||
self.set_window_group_geometry(wg, xl, yl)
|
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]:
|
def window_independent_borders(self, all_windows: WindowList) -> Generator[BorderLine, None, None]:
|
||||||
last_i = all_windows.num_groups - 1
|
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())
|
groups = tuple(all_windows.iter_all_layoutable_groups())
|
||||||
for i, wg in enumerate(groups):
|
needs_borders_map = all_windows.compute_needs_borders_map(lgd.draw_active_borders)
|
||||||
if needs_borders_map[wg.id]:
|
bw = groups[0].effective_border()
|
||||||
yield all_borders
|
if not bw:
|
||||||
continue
|
return
|
||||||
if i == last_i:
|
borders: List[BorderLine] = []
|
||||||
yield no_borders
|
active_group = all_windows.active_group
|
||||||
break
|
|
||||||
if needs_borders_map[groups[i+1].id]:
|
for wg, xl, yl in self.generate_layout_data(all_windows):
|
||||||
yield no_borders
|
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:
|
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:
|
def neighbors_for_window(self, window: WindowType, all_windows: WindowList) -> NeighborsMap:
|
||||||
wg = all_windows.group_for_window(window)
|
wg = all_windows.group_for_window(window)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user