diff --git a/src/qtile_bonsai/layout.py b/src/qtile_bonsai/layout.py index ddecc6f..32502cf 100644 --- a/src/qtile_bonsai/layout.py +++ b/src/qtile_bonsai/layout.py @@ -57,6 +57,8 @@ class LayoutOption: class Bonsai(Layout): + WindowHandler = Callable[[], BonsaiPane] + class AddClientMode(enum.Enum): restoration_in_progress = 1 normal = 2 @@ -104,21 +106,6 @@ class AddClientMode(enum.Enum): If `False`, the next (right/down) window will take up the free space. """, ), - LayoutOption( - "window.implicit_tabs", - False, - """ - (Experimental) - - If `True`, new windows are opened as tabs when not explicitly opened as a - split. - Handy for when we want any spawned GUI apps to open up as tabs, which may - otherwise open as a split if the previous window was opened as a split. - - Presently this can sometimes cause quickly opened split windows to open as - tabs instead. - """, - ), LayoutOption( "tab_bar.height", 20, @@ -240,8 +227,8 @@ def __init__(self, **config) -> None: self._tree: Tree self._focused_window: Window | None self._windows_to_panes: dict[Window, BonsaiPane] - self._on_next_window: Callable[[], BonsaiPane] self._add_client_mode: Bonsai.AddClientMode + self._pending_window_capture_ops: collections.deque[Bonsai.WindowHandler] self._restoration_window_id_to_pane_id: dict[int, int] = {} @@ -386,10 +373,6 @@ def previous(self, window) -> Window | None: return self.previous(window) def hide(self): - # While other layouts are active, ensure that any new windows are captured - # consistenty with the default tab layout here. - self._on_next_window = self._handle_default_next_window - self._tree.hide() # Use this opportunity for some cleanup @@ -452,8 +435,7 @@ def _handle_next_window(): target, axis, ratio=ratio, normalize=normalize, position=position ) - self._on_next_window = _handle_next_window - + self._pending_window_capture_ops.appendleft(_handle_next_window) self._spawn_program(program) @expose_command @@ -504,8 +486,7 @@ def _handle_next_window(): # `self.focused_pane` is in. return self._tree.tab(self.focused_pane) - self._on_next_window = _handle_next_window - + self._pending_window_capture_ops.appendleft(_handle_next_window) self._spawn_program(program) @expose_command @@ -973,7 +954,7 @@ def _init(self): def _handle_next_window(): return self._tree.tab() - self._on_next_window = _handle_next_window + self._pending_window_capture_ops = collections.deque() self._handle_initial_restoration_check() @@ -1122,15 +1103,12 @@ def _handle_add_client__restoration_in_progress(self, window: Window) -> BonsaiP return pane def _handle_add_client__normal(self, window: Window) -> BonsaiPane: - if self._tree.is_empty: - self._on_next_window = self._handle_default_next_window - - pane = self._on_next_window() - - if self._tree.get_config("window.implicit_tabs"): - self._on_next_window = self._handle_default_next_window + if self._pending_window_capture_ops: + handler = self._pending_window_capture_ops.pop() + else: + handler = self._handle_default_next_window - return pane + return handler() def _get_windows_to_panes_mapping_from_state(self, state: dict) -> dict: windows_to_panes = {}