Skip to content

Commit

Permalink
fix(core/tree): ensure pruning properly happens in sc_tc_t case when …
Browse files Browse the repository at this point in the history
…bar is hidden
  • Loading branch information
aravinda0 committed Dec 21, 2023
1 parent 68743e6 commit cb97d0f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/qtile_bonsai/core/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,10 @@ def _prune_sc_tc_t(
sc = n3.children[0]

# n3's T can only have a single SC child. The sc can now either match the n1
# SC orientation or be different.
if sc.axis == n1.axis:
# SC orientation or be different. Alternatively, the sc could also have been
# holding a sole pane under the final tab of a lower level TC. In all cases,
# we perform the appropriate merging.
if (sc.axis == n1.axis) or sc.has_single_child:
for child in sc.children:
child.parent = n1
n1.children.insert(n2_position, child)
Expand Down
39 changes: 38 additions & 1 deletion tests/unit/core/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import mock

import pytest

from qtile_bonsai.core.geometry import Rect
from qtile_bonsai.core.tree import (
Pane,
Expand Down Expand Up @@ -2368,6 +2369,40 @@ def test_when_tab_bar_is_hidden_and_t_child_and_n1_have_same_orientation_then_su
mock.call([p3, sc, t, sc2, t2, tc]),
]

@pytest.mark.parametrize("tab_bar_hide_when", ["always", "single_tab"])
def test_when_tab_bar_is_hidden_and_t_child_has_its_own_sole_child_then_subtab_level_is_eliminated_with_t_child_descendents_absorbed_into_n1(
self, make_tree_with_subscriber, tab_bar_hide_when
):
tree, callback = make_tree_with_subscriber(TreeEvent.node_removed)
tree.set_config("tab_bar.hide_when", tab_bar_hide_when)

p1 = tree.tab()
p2 = tree.split(p1, "x")
p3 = tree.split(p2, "y")
p4 = tree.tab(p3, new_level=True)

sc, t, tc, _, _, _, _ = p4.get_ancestors()
sc2, t2, _, _, _, _, _ = p3.get_ancestors()

tree.remove(p4)

assert tree_matches_str(
tree,
"""
- tc:1
- t:2
- sc.x:3
- p:4 | {x: 0, y: 0, w: 200, h: 300}
- sc.y:6
- p:5 | {x: 200, y: 0, w: 200, h: 150}
- p:7 | {x: 200, y: 150, w: 200, h: 150}
""",
)

assert callback.mock_calls == [
mock.call([p4, sc, t, sc2, t2, tc]),
]

@pytest.mark.parametrize("tab_bar_hide_when", ["always", "single_tab"])
def test_when_tab_bar_is_hidden_and_t_child_and_n1_have_different_orientation_then_subtab_level_is_eliminated_with_t_child_absorbed_into_t1(
self, make_tree_with_subscriber, tab_bar_hide_when
Expand Down Expand Up @@ -2452,10 +2487,12 @@ def test_when_n1_n2_n3_chain_is_t_sc_p_then_no_pruning_happens(
mock.call([p2]),
]

def test_when_n1_n2_n3_chain_is_sc_tc_t_then_no_pruning_happens(
def test_when_n1_n2_n3_chain_is_sc_tc_t_and_tab_bar_is_visible_then_no_pruning_happens(
self, make_tree_with_subscriber
):
tree, callback = make_tree_with_subscriber(TreeEvent.node_removed)
tree.set_config("tab_bar.hide_when", "never")

p1 = tree.tab()
p2 = tree.split(p1, "x")
p3 = tree.tab(p2, new_level=True)
Expand Down

0 comments on commit cb97d0f

Please sign in to comment.