mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-19 14:45:29 +00:00
Fix single window border with draw_window_borders_for_single_window when margin is narrower than border
The layout did not reserve space for the border of a single window, so the border overlapped the margin and, when the margin was narrower than the border, extended past the edges of the OS window. The negative coordinates were then parsed as unsigned, which with rounded borders made the whole window be covered by the corner fill, hiding its contents. Reserve the border in layout_single_window_group whenever a full border is drawn around the window, including when a visible dock causes borders to be drawn, account for it in the initial OS window size in cells, and parse border rects as signed integers, clipping them to the OS window. Fixes #10899
This commit is contained in:
parent
f63baf9f0b
commit
cbdb3a59dd
6 changed files with 78 additions and 8 deletions
|
|
@ -133,6 +133,8 @@ Detailed list of changes
|
|||
|
||||
- Linux: Fix variable fonts that use axis values to substitute glyphs, such as the cursive axis of Annotation Mono, not rendering the substituted glyphs (:iss:`10897`)
|
||||
|
||||
- Fix a single window with :opt:`draw_window_borders_for_single_window` having no border, and with :opt:`window_border_radius` being hidden by an extra layer of background, when its margin is narrower than its border. Space for the border is now reserved between the margin and the window contents (:iss:`10899`)
|
||||
|
||||
0.51.0 [2026-11-18]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
|||
|
|
@ -373,6 +373,7 @@ class Layout:
|
|||
name: str = ''
|
||||
needs_window_borders = True
|
||||
must_draw_borders = False # can be overridden to customize behavior from kittens
|
||||
has_more_than_one_visible_group = False
|
||||
layout_opts = LayoutOpts({})
|
||||
only_active_window_visible = False
|
||||
drag_overlay_mode: ClassVar[DragOverlayMode] = DragOverlayMode.full
|
||||
|
|
@ -697,7 +698,9 @@ class Layout:
|
|||
lgd.central, self.tab_dock_placements = carve_docks(tab_area, all_windows.tab_docks, lgd.cell_width, lgd.cell_height)
|
||||
# Update lgd.draw_minimal_borders based on the current number of visible windows
|
||||
# and the draw_window_borders_for_single_window option
|
||||
lgd.draw_minimal_borders = effective_draw_minimal_borders(opts, all_windows.has_more_than_one_visible_group)
|
||||
# Visible docks count, as borders are drawn around them too
|
||||
self.has_more_than_one_visible_group = all_windows.has_more_than_one_visible_group
|
||||
lgd.draw_minimal_borders = effective_draw_minimal_borders(opts, self.has_more_than_one_visible_group)
|
||||
|
||||
def __call__(self, all_windows: WindowList) -> None:
|
||||
self._set_dimensions(all_windows)
|
||||
|
|
@ -836,7 +839,12 @@ class Layout:
|
|||
dock.set_geometry(window_geometry_from_layouts(x, y))
|
||||
|
||||
def layout_single_window_group(self, wg: WindowGroup) -> None:
|
||||
bw = 1 if self.must_draw_borders else 0
|
||||
# Reserve space for the border whenever a full border is drawn around
|
||||
# the window (see Tab.relayout_borders() and Borders), otherwise it
|
||||
# overlaps the margin and spills past the edges of the OS window when
|
||||
# the margin is narrower than the border
|
||||
draws_borders = get_options().draw_window_borders_for_single_window or (self.needs_window_borders and self.has_more_than_one_visible_group)
|
||||
bw = 1 if self.must_draw_borders or (draws_borders and not lgd.draw_minimal_borders) else 0
|
||||
xdecoration_pairs = (
|
||||
(
|
||||
wg.decoration('left', border_mult=bw, is_single_window=True),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class WindowSizeData(NamedTuple):
|
|||
window_margin_width: FloatEdges
|
||||
single_window_padding_width: FloatEdges
|
||||
window_padding_width: FloatEdges
|
||||
draw_window_borders_for_single_window: bool = False
|
||||
window_border_width: tuple[float, str] = (0, 'px')
|
||||
|
||||
|
||||
def sanitize_window_size(x: Any) -> int:
|
||||
|
|
@ -83,16 +85,24 @@ def initial_window_size_func(opts: WindowSizeData, cached_values: dict[str, Any]
|
|||
ans = getattr(opts.window_padding_width, which)
|
||||
return ans
|
||||
|
||||
def border(dpi: float) -> float:
|
||||
# The layout reserves space for the border around a single window
|
||||
# only when draw_window_borders_for_single_window is set
|
||||
if not opts.draw_window_borders_for_single_window:
|
||||
return 0
|
||||
val, unit = opts.window_border_width
|
||||
return 2 * (max(1 if val > 0 else 0, val * dpi / 72) if unit == 'pt' else val)
|
||||
|
||||
if w_unit == 'cells':
|
||||
spacing = effective_margin('left') + effective_margin('right')
|
||||
spacing += effective_padding('left') + effective_padding('right')
|
||||
width = cell_width * w / xscale + (dpi_x / 72) * spacing + 1
|
||||
width = cell_width * w / xscale + (dpi_x / 72) * spacing + border(dpi_x) + 1
|
||||
else:
|
||||
width = w
|
||||
if h_unit == 'cells':
|
||||
spacing = effective_margin('top') + effective_margin('bottom')
|
||||
spacing += effective_padding('top') + effective_padding('bottom')
|
||||
height = cell_height * h / yscale + (dpi_y / 72) * spacing + 1
|
||||
height = cell_height * h / yscale + (dpi_y / 72) * spacing + border(dpi_y) + 1
|
||||
else:
|
||||
height = h
|
||||
return int(width), int(height)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,14 @@ def get_os_window_sizing_data(opts: Options, session: Optional['Session'] = None
|
|||
sizes = session.os_window_size
|
||||
remember_window_size = False # a size specified in the session takes precedence over the remembered size
|
||||
return WindowSizeData(
|
||||
sizes, remember_window_size, opts.single_window_margin_width, opts.window_margin_width, opts.single_window_padding_width, opts.window_padding_width
|
||||
sizes,
|
||||
remember_window_size,
|
||||
opts.single_window_margin_width,
|
||||
opts.window_margin_width,
|
||||
opts.single_window_padding_width,
|
||||
opts.window_padding_width,
|
||||
opts.draw_window_borders_for_single_window,
|
||||
opts.window_border_width,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -774,10 +774,16 @@ pyset_borders_rects(PyObject *self UNUSED, PyObject *args) {
|
|||
unsigned long color;
|
||||
long long border_type;
|
||||
BorderRect *r = br->rect_buf + i;
|
||||
int horizontal, render;
|
||||
if (!PyArg_ParseTuple(
|
||||
pr, "IIIIkLppII", &r->px.left, &r->px.top, &r->px.right, &r->px.bottom, &color, &border_type, &horizontal, &render, &r->radius, &r->thickness))
|
||||
int horizontal, render, left, top, right, bottom;
|
||||
if (!PyArg_ParseTuple(pr, "iiiikLppII", &left, &top, &right, &bottom, &color, &border_type, &horizontal, &render, &r->radius, &r->thickness))
|
||||
return NULL;
|
||||
// Borders can extend past the edges of the OS window, for instance when
|
||||
// a window's margin is smaller than its border, so clip them to it.
|
||||
const int vw = (int)osw->viewport_width, vh = (int)osw->viewport_height;
|
||||
r->px.left = MIN(MAX(left, 0), vw);
|
||||
r->px.top = MIN(MAX(top, 0), vh);
|
||||
r->px.right = MIN(MAX(right, (int)r->px.left), vw);
|
||||
r->px.bottom = MIN(MAX(bottom, (int)r->px.top), vh);
|
||||
r->left = gl_pos_x(r->px.left, osw->viewport_width);
|
||||
r->top = gl_pos_y(r->px.top, osw->viewport_height);
|
||||
r->right = r->left + gl_size(r->px.right - r->px.left, osw->viewport_width);
|
||||
|
|
|
|||
|
|
@ -1141,6 +1141,43 @@ class TestReservedSpaces(BaseSplitGeometryTest):
|
|||
self.assertFalse(overlaps, f'{a} overlaps {b}')
|
||||
|
||||
|
||||
class ThickBorderWindow(Window):
|
||||
def effective_border(self):
|
||||
return 3
|
||||
|
||||
|
||||
class TestSingleWindowBorders(BaseSplitGeometryTest):
|
||||
def test_single_window_border_fits_in_central_area(self):
|
||||
# With draw_window_borders_for_single_window the border of a single
|
||||
# visible window must be reserved by the layout, it must not overlap
|
||||
# the margin, which can be narrower than the border.
|
||||
# A visible dock makes for more than one visible group, so borders are
|
||||
# drawn around the single layoutable group, unless they are minimal.
|
||||
central = Region((19, 47, 1518, 1146, 1500, 1100))
|
||||
for draw, has_dock, minimal in ((True, False, False), (False, False, False), (False, True, False), (False, True, True), (True, True, True)):
|
||||
self.set_options({'tab_bar_style': 'hidden', 'draw_window_borders_for_single_window': draw})
|
||||
for cls in (Tall, Fat, Grid, Horizontal, Vertical, Splits, Stack):
|
||||
for num in (1, 3):
|
||||
if num > 1 and cls is not Stack:
|
||||
continue
|
||||
layout = create_layout(cls)
|
||||
windows = create_windows(layout, num=num, window_class=ThickBorderWindow)
|
||||
self.stub_dimensions(layout, central, minimal=minimal)
|
||||
layout.has_more_than_one_visible_group = has_dock
|
||||
layout(windows)
|
||||
rects = []
|
||||
add_borders(rects, BorderColor.active, windows.active_group)
|
||||
frame = min(r.left for r in rects), min(r.top for r in rects), max(r.right for r in rects), max(r.bottom for r in rects)
|
||||
reserved = not minimal and (draw or (has_dock and cls is not Stack))
|
||||
with self.subTest(layout=cls.name, num=num, draw=draw, has_dock=has_dock, minimal=minimal):
|
||||
if reserved:
|
||||
# the margin of 1 is outside the border
|
||||
self.ae(frame, (central.left + 1, central.top + 1, central.left + central.width - 1, central.top + central.height - 1))
|
||||
else:
|
||||
# no space is reserved for the border, so it extends past the margin
|
||||
self.assertLess(frame[0], central.left)
|
||||
|
||||
|
||||
class WideMarginWindow(Window):
|
||||
def effective_margin(self, edge):
|
||||
return 5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue