Skip to content

Commit

Permalink
Update the Columns.align logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnes committed Oct 21, 2023
1 parent dff4963 commit 10dae36
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
17 changes: 3 additions & 14 deletions libqtile/layout/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,14 @@ def remove_column(self, col):
c.width += g

def add_client(self, client: Window) -> None:
# Default behaviour is to add to current column
c = self.cc

# Create a new column if we haven't yet reached number of
# required columns
if len(c) > 0 and len(self.columns) < self.num_columns:
c = self.add_column()

# Distribute windows fairly if requested
elif self.fair:
prepend = (self.align is Columns._left)
c = self.add_column(prepend=prepend)
if self.fair:
least = min(self.columns, key=len)
if len(least) < len(c):
c = least

# Add window to column based on align property
else:
index = 0 if self.align == Columns._left else -1
c = self.columns[index]

self.current = self.columns.index(c)
c.add_client(client)

Expand Down
38 changes: 25 additions & 13 deletions test/layouts/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ColumnsConfig(Config):
layout.Columns(num_columns=3),
layout.Columns(margin_on_single=10),
layout.Columns(margin_on_single=[10, 20, 30, 40]),
layout.Columns(align=layout.Columns._left),
]
floating_layout = libqtile.resources.default_config.floating_layout
keys = []
Expand All @@ -55,13 +54,20 @@ class ColumnsSingleBorderEnabledConfig(ColumnsConfig):
layouts = [layout.Columns(border_on_single=True, single_border_width=2, border_width=4)]


class ColumnsLeftAlign(ColumnsConfig):
layouts = [layout.Columns(align=layout.Columns._left, border_width=0)]


columns_config = pytest.mark.parametrize("manager", [ColumnsConfig], indirect=True)
columns_single_border_disabled_config = pytest.mark.parametrize(
"manager", [ColumnsSingleBorderDisabledConfig], indirect=True
)
columns_single_border_enabled_config = pytest.mark.parametrize(
"manager", [ColumnsSingleBorderEnabledConfig], indirect=True
)
columns_left_align = pytest.mark.parametrize(
"manager", [ColumnsLeftAlign], indirect=True
)


# This currently only tests the window focus cycle
Expand Down Expand Up @@ -200,22 +206,28 @@ def test_columns_single_border_enabled(manager):
assert_dimensions(manager, WIDTH / 2, 0, WIDTH / 2 - 8, HEIGHT - 8)


@columns_config
@columns_left_align
def test_columns_left_align(manager):
for _ in range(3):
manager.c.next_layout()

# window 1: fullscreen
manager.test_window("1")
info = manager.c.window.info()
assert info["x"] == 0
assert info["y"] == 0
assert info["width"] == WIDTH
assert info["height"] == HEIGHT

# window 2: left
manager.test_window("2")
manager.test_window("3")
info = manager.c.window.info()
assert info["x"] == 0
assert info["y"] == 0
assert info["width"] == WIDTH / 2
assert info["height"] == HEIGHT

# Window 3 should be on the left
# Insert position is above other windows:
# 3 | 2
# 1 |
# window 3: top left
manager.test_window("3")
info = manager.c.window.info()
print(info)
assert info["x"] == 0
assert info["y"] == 0
assert info["width"] == (WIDTH // 2) - 4 # remove border
assert info["height"] == (HEIGHT // 2) - 4 # remove border
assert info["width"] == WIDTH / 2
assert info["height"] == HEIGHT / 2

0 comments on commit 10dae36

Please sign in to comment.