Skip to content

Commit

Permalink
fix(layout): be resistant to edge cases where Layout.remove() is invo…
Browse files Browse the repository at this point in the history
…ked unnecessarily

eg. for window spawned as floating, then we directly fullscreen it, then
we quit it. `Layout.remove(win)` gets invoked despite the window not
having been added to the layout.
  • Loading branch information
aravinda0 committed Aug 13, 2024
1 parent 4dc078e commit 5c0aef9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/qtile_bonsai/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ def add_client(self, window: Window):
qtile calls `Layout.add_client()`. We keep this up until all existing windows
are processed, after which we switch from 'restoration' to 'normal' mode.
"""
print("addy waddy")
if self._add_client_mode == Bonsai.AddClientMode.restoration_in_progress:
pane = self._handle_add_client__restoration_in_progress(window)
else:
Expand All @@ -442,8 +441,21 @@ def add_client(self, window: Window):
self.interaction_mode = Bonsai.InteractionMode.normal

def remove(self, window: Window) -> Window | None:
print("removio")
pane = self._windows_to_panes[window]
pane = self._windows_to_panes.get(window)
if pane is None:
# There seems to be some edge cases where `Layout.remove()` can be invoked
# even though the window was not added to the layout. The built-in layouts
# also seem to have this protection. Known scenarios:
# 1. When a program starts out as floating, and then is made fullscreen, and
# then we quit it. The window never got added to a tiled layout, but
# `Layout.remove(win)` is still invoked for it.
# NOTE: It was hard to create an integration test for this. Some weird
# issue where when we made a floating window into fullscreen, then
# `core.Core._xpoll` caused a re-invocation of the `window.fullscreen`
# setter, messing our test. Happens only during integration test - not
# during manual test.
return None

normalize_on_remove = self._tree.get_config(
"window.normalize_on_remove", level=pane.tab_level
)
Expand Down

0 comments on commit 5c0aef9

Please sign in to comment.