Dont keep increasing bias in Tall layout when it wont change the actual layout
Also refactor the bias code so that it is shared with the fat layout.
This commit is contained in:
parent
bc6a03a41b
commit
cddfe425e1
@ -364,7 +364,7 @@ enabled_layouts tall:bias=70
|
|||||||
This will make the tall window occupy `70%` of available width. `bias` can be
|
This will make the tall window occupy `70%` of available width. `bias` can be
|
||||||
any number between 10 and 90.
|
any number between 10 and 90.
|
||||||
|
|
||||||
Writing a new layout only requires about fifty lines of code, so if there is
|
Writing a new layout only requires about a hundred lines of code, so if there is
|
||||||
some layout you want, take a look at link:kitty/layout.py[layout.py] and submit
|
some layout you want, take a look at link:kitty/layout.py[layout.py] and submit
|
||||||
a pull request!
|
a pull request!
|
||||||
|
|
||||||
|
|||||||
@ -360,33 +360,49 @@ def distribute_indexed_bias(base_bias, index_bias_map):
|
|||||||
return normalize_biases(ans)
|
return normalize_biases(ans)
|
||||||
|
|
||||||
|
|
||||||
|
def variable_bias(num_windows, candidate):
|
||||||
|
return distribute_indexed_bias(list(repeat(1/(num_windows), num_windows)), candidate)
|
||||||
|
|
||||||
|
|
||||||
class Tall(Layout):
|
class Tall(Layout):
|
||||||
|
|
||||||
name = 'tall'
|
name = 'tall'
|
||||||
|
vlayout = Layout.ylayout
|
||||||
|
main_is_horizontal = True
|
||||||
|
|
||||||
def initialize_sub_class(self):
|
def initialize_sub_class(self):
|
||||||
self.remove_all_biases()
|
self.remove_all_biases()
|
||||||
|
|
||||||
def remove_all_biases(self):
|
def remove_all_biases(self):
|
||||||
self.x_bias = list(self.layout_opts['bias'])
|
self.main_bias = list(self.layout_opts['bias'])
|
||||||
self.biased_rows = {}
|
self.biased_map = {}
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def variable_layout(self, num_windows, biased_map):
|
||||||
|
num_windows -= 1
|
||||||
|
return self.vlayout(num_windows, bias=variable_bias(num_windows, biased_map) if num_windows > 1 else None)
|
||||||
|
|
||||||
def apply_bias(self, idx, increment, num_windows, is_horizontal):
|
def apply_bias(self, idx, increment, num_windows, is_horizontal):
|
||||||
if is_horizontal:
|
if self.main_is_horizontal == is_horizontal:
|
||||||
before = self.x_bias
|
before = self.main_bias
|
||||||
if idx == 0:
|
if idx == 0:
|
||||||
self.x_bias = [safe_increment_bias(self.x_bias[0], increment), safe_increment_bias(self.x_bias[1], -increment)]
|
self.main_bias = [safe_increment_bias(self.main_bias[0], increment), safe_increment_bias(self.main_bias[1], -increment)]
|
||||||
else:
|
else:
|
||||||
self.x_bias = [safe_increment_bias(self.x_bias[0], -increment), safe_increment_bias(self.x_bias[1], increment)]
|
self.main_bias = [safe_increment_bias(self.main_bias[0], -increment), safe_increment_bias(self.main_bias[1], increment)]
|
||||||
self.x_bias = normalize_biases(self.x_bias)
|
self.main_bias = normalize_biases(self.main_bias)
|
||||||
after = self.x_bias
|
after = self.main_bias
|
||||||
else:
|
else:
|
||||||
if idx == 0:
|
if idx == 0 or num_windows < 3:
|
||||||
return False
|
return False
|
||||||
idx -= 1
|
idx -= 1
|
||||||
before = self.biased_rows.get(idx, 0)
|
before_layout = list(self.variable_layout(num_windows, self.biased_map))
|
||||||
self.biased_rows[idx] = after = before + increment
|
candidate = self.biased_map.copy()
|
||||||
|
before = candidate.get(idx, 0)
|
||||||
|
candidate[idx] = after = before + increment
|
||||||
|
if before_layout == list(self.variable_layout(num_windows, candidate)):
|
||||||
|
return False
|
||||||
|
self.biased_map = candidate
|
||||||
|
|
||||||
return before != after
|
return before != after
|
||||||
|
|
||||||
def parse_layout_opts(self, layout_opts):
|
def parse_layout_opts(self, layout_opts):
|
||||||
@ -406,16 +422,12 @@ class Tall(Layout):
|
|||||||
windows[0].set_geometry(0, wg)
|
windows[0].set_geometry(0, wg)
|
||||||
self.blank_rects = blank_rects_for_window(windows[0])
|
self.blank_rects = blank_rects_for_window(windows[0])
|
||||||
return
|
return
|
||||||
xlayout = self.xlayout(2, bias=self.x_bias)
|
xlayout = self.xlayout(2, bias=self.main_bias)
|
||||||
xstart, xnum = next(xlayout)
|
xstart, xnum = next(xlayout)
|
||||||
ystart, ynum = next(self.ylayout(1))
|
ystart, ynum = next(self.vlayout(1))
|
||||||
windows[0].set_geometry(0, window_geometry(xstart, xnum, ystart, ynum))
|
windows[0].set_geometry(0, window_geometry(xstart, xnum, ystart, ynum))
|
||||||
xstart, xnum = next(xlayout)
|
xstart, xnum = next(xlayout)
|
||||||
if len(windows) > 2:
|
ylayout = self.variable_layout(len(windows), self.biased_map)
|
||||||
y_bias = distribute_indexed_bias(list(repeat(1/(len(windows) - 1), len(windows) - 1)), self.biased_rows)
|
|
||||||
else:
|
|
||||||
y_bias = None
|
|
||||||
ylayout = self.ylayout(len(windows) - 1, bias=y_bias)
|
|
||||||
for i, (w, (ystart, ynum)) in enumerate(zip(islice(windows, 1, None), ylayout)):
|
for i, (w, (ystart, ynum)) in enumerate(zip(islice(windows, 1, None), ylayout)):
|
||||||
w.set_geometry(i + 1, window_geometry(xstart, xnum, ystart, ynum))
|
w.set_geometry(i + 1, window_geometry(xstart, xnum, ystart, ynum))
|
||||||
# right bottom blank rect
|
# right bottom blank rect
|
||||||
@ -432,28 +444,8 @@ class Tall(Layout):
|
|||||||
class Fat(Tall):
|
class Fat(Tall):
|
||||||
|
|
||||||
name = 'fat'
|
name = 'fat'
|
||||||
|
vlayout = Layout.xlayout
|
||||||
def remove_all_biases(self):
|
main_is_horizontal = False
|
||||||
self.y_bias = list(self.layout_opts['bias'])
|
|
||||||
self.biased_columns = {}
|
|
||||||
return True
|
|
||||||
|
|
||||||
def apply_bias(self, idx, increment, num_windows, is_horizontal):
|
|
||||||
if not is_horizontal:
|
|
||||||
before = self.y_bias
|
|
||||||
if idx == 0:
|
|
||||||
self.y_bias = [safe_increment_bias(self.y_bias[0], increment), safe_increment_bias(self.y_bias[1], -increment)]
|
|
||||||
else:
|
|
||||||
self.y_bias = [safe_increment_bias(self.y_bias[0], -increment), safe_increment_bias(self.y_bias[1], increment)]
|
|
||||||
self.y_bias = normalize_biases(self.y_bias)
|
|
||||||
after = self.y_bias
|
|
||||||
else:
|
|
||||||
if idx == 0:
|
|
||||||
return False
|
|
||||||
idx -= 1
|
|
||||||
before = self.biased_columns.get(idx, 0)
|
|
||||||
self.biased_columns[idx] = after = before + increment
|
|
||||||
return before != after
|
|
||||||
|
|
||||||
def do_layout(self, windows, active_window_idx):
|
def do_layout(self, windows, active_window_idx):
|
||||||
self.blank_rects = []
|
self.blank_rects = []
|
||||||
@ -463,14 +455,10 @@ class Fat(Tall):
|
|||||||
self.blank_rects = blank_rects_for_window(windows[0])
|
self.blank_rects = blank_rects_for_window(windows[0])
|
||||||
return
|
return
|
||||||
xstart, xnum = next(self.xlayout(1))
|
xstart, xnum = next(self.xlayout(1))
|
||||||
ylayout = self.ylayout(2, bias=self.y_bias)
|
ylayout = self.ylayout(2, bias=self.main_bias)
|
||||||
ystart, ynum = next(ylayout)
|
ystart, ynum = next(ylayout)
|
||||||
windows[0].set_geometry(0, window_geometry(xstart, xnum, ystart, ynum))
|
windows[0].set_geometry(0, window_geometry(xstart, xnum, ystart, ynum))
|
||||||
if len(windows) > 2:
|
xlayout = self.variable_layout(len(windows), self.biased_map)
|
||||||
x_bias = distribute_indexed_bias(list(repeat(1/(len(windows) - 1), len(windows) - 1)), self.biased_columns)
|
|
||||||
else:
|
|
||||||
x_bias = None
|
|
||||||
xlayout = self.xlayout(len(windows) - 1, bias=x_bias)
|
|
||||||
ystart, ynum = next(ylayout)
|
ystart, ynum = next(ylayout)
|
||||||
for i, (w, (xstart, xnum)) in enumerate(zip(islice(windows, 1, None), xlayout)):
|
for i, (w, (xstart, xnum)) in enumerate(zip(islice(windows, 1, None), xlayout)):
|
||||||
w.set_geometry(i + 1, window_geometry(xstart, xnum, ystart, ynum))
|
w.set_geometry(i + 1, window_geometry(xstart, xnum, ystart, ynum))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user