From 6318238feb421f6a0d815a40d9cdd116d34d6993 Mon Sep 17 00:00:00 2001 From: Aravinda Rao Date: Thu, 9 May 2024 18:25:43 +0530 Subject: [PATCH] feat(layout): ensure first window can be opened even if a split is requested --- src/qtile_bonsai/layout.py | 9 +++----- tests/integration/test_layout.py | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/qtile_bonsai/layout.py b/src/qtile_bonsai/layout.py index 5524207..1006515 100644 --- a/src/qtile_bonsai/layout.py +++ b/src/qtile_bonsai/layout.py @@ -451,11 +451,11 @@ def spawn_split( - `layout.spawn_split(my_terminal, "y", ratio=0.2, normalize=False)` - `layout.spawn_split(my_terminal, "x", position="previous")` """ - if self._tree.is_empty: - logger.warn("There are no windows yet to split") - return def _handle_next_window(): + if self._tree.is_empty: + return self._tree.tab() + target = self.focused_pane or self._tree.find_mru_pane() return self._tree.split( target, axis, ratio=ratio, normalize=normalize, position=position @@ -1144,9 +1144,6 @@ 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._next_window_handler = self._handle_default_next_window - pane = self._next_window_handler() if self._tree.get_config("window.default_add_mode") == "tab": diff --git a/tests/integration/test_layout.py b/tests/integration/test_layout.py index 373616e..e0a95b2 100644 --- a/tests/integration/test_layout.py +++ b/tests/integration/test_layout.py @@ -68,6 +68,42 @@ def test_when_floating_window_is_unfloated_then_it_is_added_back_to_layout( ) +class TestSpawnSplit: + def test_when_tree_is_empty_then_split_still_adds_first_window_as_tab( + self, manager, spawn_test_window_cmd + ): + assert manager.layout.info()["tree"] == "" + + manager.layout.spawn_split(spawn_test_window_cmd, "x") + time.sleep(0.5) + + assert tree_repr_matches_repr( + manager.layout.info()["tree"], + """ + - tc:1 + - t:2 + - sc.x:3 + - p:4 | {x: 0, y: 0, w: 800, h: 600} + """, + ) + + +class TestConfigOptions: + class TestWindowDefaultAddMode: + @pytest.mark.skip( + reason=""" + Need to figure out some things around parametrizing config to pass to chain + of fixtures so it reaches the qtile_x11 and qtile_wayland fixtures. + """ + ) + def test_when_tree_is_empty_and_first_window_was_added_as_a_tab_but_from_a_split_request_then_match_previous_still_respects_that_previous_request_was_for_a_split( + self, + manager, + spawn_test_window_cmd, + ): + raise + + class TestStateRestoration: def test_when_qtile_config_is_reloaded_then_state_is_restored( self, manager, spawn_test_window_cmd