-
Hey, I'd like to group newly added clients automatically in tabs if their wm_class is the same. If not I'd like to add them as split. My current idea to configure this would be to add a @hook.subscribe.client_new and set _next_window_handler. Is there an easier and more intended way to achieve this behavior? thank you for your work <3 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hey. So if I understand correctly, you want a flow like this:
Let me know if I misunderstood that. Else I think something could be hacked together to achieve the above, but there are some open questions - eg. what if you start off with tabs T1,T2,T3 instead of splits - then would you still want a new subtab level under the full-sized T2 say, if the new program matches T2's wm_class. Let me try to whip up something that does the above meanwhile - that sounds kinda nifty. |
Beta Was this translation helpful? Give feedback.
-
Here's a hacked up layout customization that defaults to splits and groups same-wm-class items as subtabs: from qtile_bonsai.core.nodes import SplitContainer
class AutoGroupBonsai(Bonsai):
def _handle_add_client__normal(self, window):
"""Sort of equivalent to overriding `Layout.add_client()`, which we don't do
directly since we want to let it take care of post-config-reload state
restoration etc.
"""
if self._tree.is_empty:
return self._tree.tab()
existing_similar = self._find_existing_similar_pane(window)
if existing_similar is not None:
new_level = True
# If the similar window is already under a subtab, let's reuse it.
if existing_similar.tab_level > 1:
new_level = False
return self._tree.tab(at_node=existing_similar, new_level=new_level)
# Fall back to splitting at the topmost possible node.
topmost_sc = self.focused_pane.get_ancestors(SplitContainer)[-1]
return self._tree.split(topmost_sc, "x", normalize=True)
def _find_existing_similar_pane(self, window):
return next(
(
p
for p in self._tree.iter_panes()
if p.window.get_wm_class() == window.get_wm_class()
),
None,
) There could be another way to do this by using a custom command, but I'd have to refactor things internally a wee bit to enable access to the new client/window to be able to use its class AutoGroupBonsai(Bonsai):
@expose_command
def spawn_and_auto_arrange(self, program):
def _handle_next_window(window):
# 💢 same above logic goes here, but this handler doesn't yet accept `window` as a param
self._next_window_handler = _handle_next_window
self._spawn_program(program) |
Beta Was this translation helpful? Give feedback.
-
Thank you that's exactly what I was searching for. For my workflow this is already working correct! I intended to have my IDE with multiple projects grouped as tab and add browser or terminal as new split for research. Another usecase for comparing two IDE instances with each other, I need them temporary in a split. Then I was thinking that just the latest created split is used for adding a new tab. But this is also a very special and rare usecase. For the moment I'm very happy with AutoGroupBonsai! |
Beta Was this translation helpful? Give feedback.
Here's a hacked up layout customization that defaults to splits and groups same-wm-class items as subtabs: