Skip to content

Commit

Permalink
Fix bar positioning when not reserving space (#4570)
Browse files Browse the repository at this point in the history
Where a bottom/right bar is used, this was positioned to the
bottom/right of the available screen space which had been adjusted to
leave space for the bar. However, with the introduction of the
`reserve=False` configuration option, this logic fails as the available
screen space is not adjusted so the bar ends up being positioned off
screen. This PR corrects that logic.
  • Loading branch information
elParaguayo committed Nov 12, 2023
1 parent f76bbf5 commit 87f419d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
5 changes: 5 additions & 0 deletions libqtile/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ def _configure(self, qtile: Qtile, screen: Screen, reconfigure: bool = False) ->
else:
self.x -= margin[1] + self.border_width[1]

if screen.bottom is self and not self.reserve:
self.y -= self.height + self.margin[2]
elif screen.right is self and not self.reserve:
self.x -= self.width + self.margin[1]

self._reserved_space_updated = False

width = self.width + (self.border_width[1] + self.border_width[3])
Expand Down
53 changes: 38 additions & 15 deletions test/test_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,23 +634,36 @@ class UnsupportedConfig(BareConfig):
assert len(manager_nospawn.c.bar["top"].info()["widgets"]) == 0


class DontReserveBarConfig(GBConfig):
screens = [
libqtile.config.Screen(
top=libqtile.bar.Bar([libqtile.widget.Spacer()], 50, reserve=False),
)
]
layouts = [libqtile.layout.max.Max()]


dont_reserve_bar_config = pytest.mark.parametrize(
"manager", [DontReserveBarConfig], indirect=True
@pytest.fixture
def no_reserve_manager(manager_nospawn, request):
position = getattr(request, "param", "top")

class DontReserveBarConfig(GBConfig):
screens = [
libqtile.config.Screen(
**{position: libqtile.bar.Bar([libqtile.widget.Spacer()], 50, reserve=False)},
)
]
layouts = [libqtile.layout.max.Max()]

manager_nospawn.start(DontReserveBarConfig)
manager_nospawn.bar_position = position
yield manager_nospawn


@pytest.mark.parametrize(
"no_reserve_manager,bar_x,bar_y,bar_w,bar_h",
[
("top", 0, 0, 800, 50),
("bottom", 0, 550, 800, 50),
("left", 0, 0, 50, 600),
("right", 750, 0, 50, 600),
],
indirect=["no_reserve_manager"],
)


@dont_reserve_bar_config
def test_dont_reserve_bar(manager):
def test_dont_reserve_bar(no_reserve_manager, bar_x, bar_y, bar_w, bar_h):
"""Bar is drawn over tiled windows."""
manager = no_reserve_manager
manager.test_window("Window")
info = manager.c.window.info()

Expand All @@ -659,3 +672,13 @@ def test_dont_reserve_bar(manager):
assert info["y"] == 0
assert info["width"] == 800
assert info["height"] == 600

bar = manager.c.bar[manager.bar_position]
bar_info = bar.info()
_, x = bar.eval("self.x")
_, y = bar.eval("self.y")

assert bar_x == int(x)
assert bar_y == int(y)
assert bar_w == bar_info["width"]
assert bar_h == bar_info["height"]

0 comments on commit 87f419d

Please sign in to comment.