diff --git a/src/main.rs b/src/main.rs index 009b094..8152b38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,18 +157,40 @@ async fn main() -> Res<()> { Ok(()) } +fn any_parent( + tree: &swayipc_async::Node, + id: i64, + mut test: impl FnMut(&swayipc_async::Node) -> bool, +) -> bool { + tree.find_as_ref(|n| n.focus.contains(&id)) + .is_some_and(|parent| test(parent) || any_parent(tree, parent.id, test)) +} + async fn autosplit( node: &swayipc_async::Node, tree: &swayipc_async::Node, connection: &mut swayipc_async::Connection, ) -> Res<()> { + // todo: investigate why we're splitting many layers deep in nested layouts, ie + // [tab/stack] -> split if node.node_type == swayipc_async::NodeType::Con { let (width, height) = (node.window_rect.width, node.window_rect.height); + // we don't want to split zero-sized windows, but containers are also zero-sized // - so only skip if size is 0 and we have no children if (width == 0 || height == 0) && node.focus.is_empty() { return Ok(()); } + + // don't autosplit if we're in fullscreen + if any_parent(&tree, node.id, |n| { + (n.node_type == swayipc_async::NodeType::Con + || n.node_type == swayipc_async::NodeType::FloatingCon) + && n.fullscreen_mode.is_some_and(|m| m != 0) + }) { + return Ok(()); + } + if tree .find_as_ref(|n| n.focus.contains(&node.id)) .is_some_and(|parent| { @@ -178,6 +200,7 @@ async fn autosplit( { return Ok(()); } + let config = CONFIG.get().await; if !config.autosplit_enabled || config.force_tabbed.iter().any(|blocked| {