Skip to content

Commit

Permalink
feat(layout): handle windows in a way more resistent to race conditio…
Browse files Browse the repository at this point in the history
…ns causing fallback to tab-mode; discard window.implicit_tabs option
  • Loading branch information
aravinda0 committed May 1, 2024
1 parent 24285ad commit ced2fc5
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions src/qtile_bonsai/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class LayoutOption:


class Bonsai(Layout):
WindowHandler = Callable[[], BonsaiPane]

class AddClientMode(enum.Enum):
restoration_in_progress = 1
normal = 2
Expand Down Expand Up @@ -104,21 +106,6 @@ class AddClientMode(enum.Enum):
If `False`, the next (right/down) window will take up the free space.
""",
),
LayoutOption(
"window.implicit_tabs",
False,
"""
(Experimental)
If `True`, new windows are opened as tabs when not explicitly opened as a
split.
Handy for when we want any spawned GUI apps to open up as tabs, which may
otherwise open as a split if the previous window was opened as a split.
Presently this can sometimes cause quickly opened split windows to open as
tabs instead.
""",
),
LayoutOption(
"tab_bar.height",
20,
Expand Down Expand Up @@ -240,8 +227,8 @@ def __init__(self, **config) -> None:
self._tree: Tree
self._focused_window: Window | None
self._windows_to_panes: dict[Window, BonsaiPane]
self._on_next_window: Callable[[], BonsaiPane]
self._add_client_mode: Bonsai.AddClientMode
self._pending_window_capture_ops: collections.deque[Bonsai.WindowHandler]

self._restoration_window_id_to_pane_id: dict[int, int] = {}

Expand Down Expand Up @@ -386,10 +373,6 @@ def previous(self, window) -> Window | None:
return self.previous(window)

def hide(self):
# While other layouts are active, ensure that any new windows are captured
# consistenty with the default tab layout here.
self._on_next_window = self._handle_default_next_window

self._tree.hide()

# Use this opportunity for some cleanup
Expand Down Expand Up @@ -452,8 +435,7 @@ def _handle_next_window():
target, axis, ratio=ratio, normalize=normalize, position=position
)

self._on_next_window = _handle_next_window

self._pending_window_capture_ops.appendleft(_handle_next_window)
self._spawn_program(program)

@expose_command
Expand Down Expand Up @@ -504,8 +486,7 @@ def _handle_next_window():
# `self.focused_pane` is in.
return self._tree.tab(self.focused_pane)

self._on_next_window = _handle_next_window

self._pending_window_capture_ops.appendleft(_handle_next_window)
self._spawn_program(program)

@expose_command
Expand Down Expand Up @@ -973,7 +954,7 @@ def _init(self):
def _handle_next_window():
return self._tree.tab()

self._on_next_window = _handle_next_window
self._pending_window_capture_ops = collections.deque()

self._handle_initial_restoration_check()

Expand Down Expand Up @@ -1122,15 +1103,12 @@ 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._on_next_window = self._handle_default_next_window

pane = self._on_next_window()

if self._tree.get_config("window.implicit_tabs"):
self._on_next_window = self._handle_default_next_window
if self._pending_window_capture_ops:
handler = self._pending_window_capture_ops.pop()
else:
handler = self._handle_default_next_window

return pane
return handler()

def _get_windows_to_panes_mapping_from_state(self, state: dict) -> dict:
windows_to_panes = {}
Expand Down

0 comments on commit ced2fc5

Please sign in to comment.