From 62fbda8c9ba9c46ab77df7f7f5d3d4067249d0a3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 Dec 2024 19:54:10 +0530 Subject: [PATCH] When re-attaching a detached tab preserve internal layout state such as biases and orientations Fixes #8106 --- docs/changelog.rst | 2 ++ kitty/layout/base.py | 10 +++++++--- kitty/tabs.py | 9 +++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index eef4a814b..13feb193d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -109,6 +109,8 @@ Detailed list of changes - Fix enlarging window when a long line is wrapped between the first line of the scrollback buffer and the screen inserting a spurious newline (:iss:`7033`) +- When re-attaching a detached tab preserve internal layout state such as biases and orientations (:iss:`8106`) + 0.37.0 [2024-10-30] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/layout/base.py b/kitty/layout/base.py index 7137cad36..e1b052b7f 100644 --- a/kitty/layout/base.py +++ b/kitty/layout/base.py @@ -223,9 +223,7 @@ class Layout: only_active_window_visible = False def __init__(self, os_window_id: int, tab_id: int, layout_opts: str = '') -> None: - self.os_window_id = os_window_id - self.tab_id = tab_id - self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id) + self.set_owner(os_window_id, tab_id) # A set of rectangles corresponding to the blank spaces at the edges of # this layout, i.e. spaces that are not covered by any window self.blank_rects: List[Rect] = [] @@ -234,6 +232,12 @@ class Layout: self.full_name = f'{self.name}:{layout_opts}' if layout_opts else self.name self.remove_all_biases() + def set_owner(self, os_window_id: int, tab_id: int) -> None: + # Useful when moving a layout from one tab to another typically a detached tab being re-attached + self.os_window_id = os_window_id + self.tab_id = tab_id + self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id) + def bias_increment_for_cell(self, all_windows: WindowList, is_horizontal: bool) -> float: self._set_dimensions() return self.calculate_bias_increment_for_a_single_cell(all_windows, is_horizontal) diff --git a/kitty/tabs.py b/kitty/tabs.py index ae673035f..f16aa7d0b 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -184,9 +184,14 @@ class Tab: # {{{ def take_over_from(self, other_tab: 'Tab') -> None: self.name, self.cwd = other_tab.name, other_tab.cwd self.enabled_layouts = list(other_tab.enabled_layouts) - if other_tab._current_layout_name: - self._set_current_layout(other_tab._current_layout_name) self._last_used_layout = other_tab._last_used_layout + if clname := other_tab._current_layout_name: + cl = other_tab.current_layout + other_tab._set_current_layout(clname) + cl.set_owner(self.os_window_id, self.id) + self.current_layout: Layout = cl + self._current_layout_name = clname + self.mark_tab_bar_dirty() for window in other_tab.windows: detach_window(other_tab.os_window_id, other_tab.id, window.id) self.windows = other_tab.windows