Fix resizing window that is extra tall/wide because of left-over cells not working reliably
Fixes #4913
This commit is contained in:
parent
ab8a4c6b9f
commit
c40ef01445
@ -74,6 +74,9 @@ Detailed list of changes
|
||||
|
||||
- Fix :opt:`inactive_text_alpha` still being applied to the cursor hidden window after focus (:iss:`4928`)
|
||||
|
||||
- Fix resizing window that is extra tall/wide because of left-over cells not
|
||||
working reliably (:iss:`4913`)
|
||||
|
||||
|
||||
0.24.4 [2022-03-03]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@ -5,7 +5,7 @@ from functools import partial
|
||||
from itertools import repeat
|
||||
from typing import (
|
||||
Any, Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional,
|
||||
Sequence, Tuple
|
||||
Sequence, Tuple, Union
|
||||
)
|
||||
|
||||
from kitty.borders import BorderColor
|
||||
@ -78,7 +78,20 @@ def set_layout_options(opts: Options) -> None:
|
||||
lgd.align_top_left = opts.placement_strategy == 'top-left'
|
||||
|
||||
|
||||
def calculate_cells_map(bias: Optional[Sequence[float]], number_of_windows: int, number_of_cells: int) -> List[int]:
|
||||
def convert_bias_map(bias: Dict[int, float], number_of_windows: int, number_of_cells: int) -> Sequence[float]:
|
||||
cells_per_window, extra = divmod(number_of_cells, number_of_windows)
|
||||
cell_map = list(repeat(cells_per_window, number_of_windows))
|
||||
cell_map[-1] += extra
|
||||
base_bias = [x / number_of_cells for x in cell_map]
|
||||
return distribute_indexed_bias(base_bias, bias)
|
||||
|
||||
|
||||
def calculate_cells_map(
|
||||
bias: Union[None, Sequence[float], Dict[int, float]],
|
||||
number_of_windows: int, number_of_cells: int
|
||||
) -> List[int]:
|
||||
if isinstance(bias, dict):
|
||||
bias = convert_bias_map(bias, number_of_windows, number_of_cells)
|
||||
cells_per_window = number_of_cells // number_of_windows
|
||||
if bias is not None and number_of_windows > 1 and number_of_windows == len(bias) and cells_per_window > 5:
|
||||
cells_map = [int(b * number_of_cells) for b in bias]
|
||||
@ -100,7 +113,7 @@ def layout_dimension(
|
||||
start_at: int, length: int, cell_length: int,
|
||||
decoration_pairs: DecorationPairs,
|
||||
left_align: bool = False,
|
||||
bias: Optional[Sequence[float]] = None
|
||||
bias: Union[None, Sequence[float], Dict[int, float]] = None
|
||||
) -> LayoutDimension:
|
||||
number_of_windows = len(decoration_pairs)
|
||||
number_of_cells = length // cell_length
|
||||
@ -197,10 +210,6 @@ def distribute_indexed_bias(base_bias: Sequence[float], index_bias_map: Dict[int
|
||||
return normalize_biases(ans)
|
||||
|
||||
|
||||
def variable_bias(num_windows: int, candidate: Dict[int, float]) -> Sequence[float]:
|
||||
return distribute_indexed_bias(list(repeat(1/(num_windows), num_windows)), candidate)
|
||||
|
||||
|
||||
class Layout:
|
||||
|
||||
name: Optional[str] = None
|
||||
@ -334,7 +343,7 @@ class Layout:
|
||||
def xlayout(
|
||||
self,
|
||||
groups: Iterator[WindowGroup],
|
||||
bias: Optional[Sequence[float]] = None,
|
||||
bias: Union[None, Sequence[float], Dict[int, float]] = None,
|
||||
start: Optional[int] = None,
|
||||
size: Optional[int] = None,
|
||||
offset: int = 0,
|
||||
@ -353,7 +362,7 @@ class Layout:
|
||||
def ylayout(
|
||||
self,
|
||||
groups: Iterator[WindowGroup],
|
||||
bias: Optional[Sequence[float]] = None,
|
||||
bias: Union[None, Sequence[float], Dict[int, float]] = None,
|
||||
start: Optional[int] = None,
|
||||
size: Optional[int] = None,
|
||||
offset: int = 0,
|
||||
|
||||
@ -15,7 +15,7 @@ from kitty.window_list import WindowGroup, WindowList
|
||||
|
||||
from .base import (
|
||||
BorderLine, Layout, LayoutData, LayoutDimension, ListOfWindows,
|
||||
NeighborsMap, layout_dimension, lgd, variable_bias
|
||||
NeighborsMap, layout_dimension, lgd
|
||||
)
|
||||
from .tall import neighbors_for_tall_window
|
||||
|
||||
@ -61,7 +61,7 @@ class Grid(Layout):
|
||||
return layout_dimension(lgd.central.top, lgd.central.height, lgd.cell_height, decoration_pairs, bias=bias, left_align=lgd.align_top_left)
|
||||
|
||||
def variable_layout(self, layout_func: Callable[..., LayoutDimension], num_windows: int, biased_map: Dict[int, float]) -> LayoutDimension:
|
||||
return layout_func(num_windows, bias=variable_bias(num_windows, biased_map) if num_windows > 1 else None)
|
||||
return layout_func(num_windows, bias=biased_map if num_windows > 1 else None)
|
||||
|
||||
def apply_bias(self, idx: int, increment: float, all_windows: WindowList, is_horizontal: bool = True) -> bool:
|
||||
num_windows = all_windows.num_groups
|
||||
|
||||
@ -12,7 +12,7 @@ from kitty.window_list import WindowGroup, WindowList
|
||||
|
||||
from .base import (
|
||||
BorderLine, Layout, LayoutData, LayoutDimension, LayoutOpts, NeighborsMap,
|
||||
lgd, normalize_biases, safe_increment_bias, variable_bias
|
||||
lgd, normalize_biases, safe_increment_bias
|
||||
)
|
||||
from .vertical import borders
|
||||
|
||||
@ -96,7 +96,7 @@ class Tall(Layout):
|
||||
|
||||
def variable_layout(self, all_windows: WindowList, biased_map: Dict[int, float]) -> LayoutDimension:
|
||||
num = all_windows.num_groups - self.num_full_size_windows
|
||||
bias = variable_bias(num, biased_map) if num > 1 else None
|
||||
bias = biased_map if num > 1 else None
|
||||
return self.perp_axis_layout(all_windows.iter_all_layoutable_groups(), bias=bias, offset=self.num_full_size_windows)
|
||||
|
||||
def apply_bias(self, idx: int, increment: float, all_windows: WindowList, is_horizontal: bool = True) -> bool:
|
||||
|
||||
@ -10,7 +10,7 @@ from kitty.window_list import WindowGroup, WindowList
|
||||
|
||||
from .base import (
|
||||
BorderLine, Layout, LayoutData, LayoutDimension, NeighborsMap,
|
||||
lgd, variable_bias
|
||||
lgd
|
||||
)
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ class Vertical(Layout):
|
||||
|
||||
def variable_layout(self, all_windows: WindowList, biased_map: Dict[int, float]) -> LayoutDimension:
|
||||
num_windows = all_windows.num_groups
|
||||
bias = variable_bias(num_windows, biased_map) if num_windows else None
|
||||
bias = biased_map if num_windows > 1 else None
|
||||
return self.main_axis_layout(all_windows.iter_all_layoutable_groups(), bias=bias)
|
||||
|
||||
def fixed_layout(self, wg: WindowGroup) -> LayoutDimension:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user