Skip to content

Commit

Permalink
feat(layout): ensure first window can be opened even if a split is re…
Browse files Browse the repository at this point in the history
…quested
  • Loading branch information
aravinda0 committed May 9, 2024
1 parent be07ddb commit 6318238
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/qtile_bonsai/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == "<empty>"

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
Expand Down

0 comments on commit 6318238

Please sign in to comment.