From f06f85a9e064e2723cb222ebf4a3db1b7198cad7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Oct 2025 09:12:32 +0530 Subject: [PATCH] Cleanup previous PR --- docs/changelog.rst | 4 ++++ kitty/boss.py | 6 ++---- kitty/layout/base.py | 21 ++++++++++----------- kitty/tabs.py | 4 ++-- kitty/window_list.py | 6 ++++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 9e331a2af..3b7f2c7e0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -141,6 +141,10 @@ Detailed list of changes login shell at startup using the :opt:`env` directive in kitty.conf (:iss:`9042`) +- A new option :opt:`draw_window_borders_for_single_window` to force kitty to + always draw a window border even when only a single window is present + (:pull:`9112`) + - Fix a regression in 0.43.0 that caused a black flicker when closing a tab in the presence of a background image (:iss:`9060`) diff --git a/kitty/boss.py b/kitty/boss.py index a7b21ee50..f9fb707ee 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1857,10 +1857,8 @@ class Boss: # Redraw borders when focus changes if draw_window_borders_for_single_window is enabled # and there's only a single window (to show inactive border when OS window loses focus) opts = get_options() - if opts.draw_window_borders_for_single_window and tm.active_tab is not None: - # Only redraw if there's a single visible window - if tm.active_tab.windows.num_visble_groups == 1: - tm.active_tab.relayout_borders() + if opts.draw_window_borders_for_single_window and (tab := tm.active_tab) is not None and not tab.windows.has_more_than_one_visible_group: + tab.relayout_borders() def on_activity_since_last_focus(self, window: Window) -> None: os_window_id = window.os_window_id diff --git a/kitty/layout/base.py b/kitty/layout/base.py index 62ae4a3f7..8e55e893c 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -69,8 +69,15 @@ def idx_for_id(win_id: int, windows: Iterable[WindowType]) -> int | None: return None +def effective_draw_minimal_borders(opts: Options, has_more_than_one_visible_group: bool = True) -> bool: + ans = opts.draw_minimal_borders and sum(opts.window_margin_width) == 0 + if not has_more_than_one_visible_group and opts.draw_window_borders_for_single_window: + ans = False + return ans + + def set_layout_options(opts: Options) -> None: - lgd.draw_minimal_borders = opts.draw_minimal_borders and sum(opts.window_margin_width) == 0 + lgd.draw_minimal_borders = effective_draw_minimal_borders(opts) lgd.draw_active_borders = opts.active_border_color is not None lgd.alignment_x = -1 if opts.placement_strategy.endswith('left') else 1 if opts.placement_strategy.endswith('right') else 0 lgd.alignment_y = -1 if opts.placement_strategy.startswith('top') else 1 if opts.placement_strategy.startswith('bottom') else 0 @@ -354,20 +361,12 @@ class Layout: is_visible = window is active_window or (is_group_leader and not self.only_active_window_visible) window.set_visible_in_layout(is_visible) - def _set_dimensions(self, all_windows: WindowList | None = None) -> None: + def _set_dimensions(self, all_windows: WindowList) -> None: lgd.central, tab_bar, vw, vh, lgd.cell_width, lgd.cell_height = viewport_for_window(self.os_window_id) # Update lgd.draw_minimal_borders based on the current number of visible windows # and the draw_window_borders_for_single_window option opts = get_options() - base_draw_minimal = opts.draw_minimal_borders and sum(opts.window_margin_width) == 0 - if all_windows is not None and opts.draw_window_borders_for_single_window: - num_visible = all_windows.num_groups - if num_visible == 1: - lgd.draw_minimal_borders = False - else: - lgd.draw_minimal_borders = base_draw_minimal - else: - lgd.draw_minimal_borders = base_draw_minimal + lgd.draw_minimal_borders = effective_draw_minimal_borders(opts, all_windows.has_more_than_one_visible_group) def __call__(self, all_windows: WindowList) -> None: self._set_dimensions(all_windows) diff --git a/kitty/tabs.py b/kitty/tabs.py index 8bc2f0896..011dd5871 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -420,8 +420,8 @@ class Tab: # {{{ ly = self.current_layout opts = get_options() draw_borders = ( - (ly.needs_window_borders and self.windows.num_visble_groups > 1) or ly.must_draw_borders - or opts.draw_window_borders_for_single_window + ly.must_draw_borders or opts.draw_window_borders_for_single_window or + (ly.needs_window_borders and self.windows.has_more_than_one_visible_group) ) self.borders( all_windows=self.windows, diff --git a/kitty/window_list.py b/kitty/window_list.py index 48dde41c4..cde00d65e 100644 --- a/kitty/window_list.py +++ b/kitty/window_list.py @@ -513,9 +513,11 @@ class WindowList: return {gr.id: ((gr is ag and draw_active_borders) or gr.needs_attention) for gr in self.groups} @property - def num_visble_groups(self) -> int: + def has_more_than_one_visible_group(self) -> bool: ans = 0 for gr in self.groups: if gr.is_visible_in_layout: ans += 1 - return ans + if ans > 1: + return True + return False