don't autosplit in fullscreen layouts

This commit is contained in:
Alex Janka 2024-10-07 12:15:20 +11:00
parent 6b409dfe18
commit d8e1691e0d

View file

@ -157,18 +157,40 @@ async fn main() -> Res<()> {
Ok(()) 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( async fn autosplit(
node: &swayipc_async::Node, node: &swayipc_async::Node,
tree: &swayipc_async::Node, tree: &swayipc_async::Node,
connection: &mut swayipc_async::Connection, connection: &mut swayipc_async::Connection,
) -> Res<()> { ) -> 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 { if node.node_type == swayipc_async::NodeType::Con {
let (width, height) = (node.window_rect.width, node.window_rect.height); 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 // 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 // - so only skip if size is 0 and we have no children
if (width == 0 || height == 0) && node.focus.is_empty() { if (width == 0 || height == 0) && node.focus.is_empty() {
return Ok(()); 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 if tree
.find_as_ref(|n| n.focus.contains(&node.id)) .find_as_ref(|n| n.focus.contains(&node.id))
.is_some_and(|parent| { .is_some_and(|parent| {
@ -178,6 +200,7 @@ async fn autosplit(
{ {
return Ok(()); return Ok(());
} }
let config = CONFIG.get().await; let config = CONFIG.get().await;
if !config.autosplit_enabled if !config.autosplit_enabled
|| config.force_tabbed.iter().any(|blocked| { || config.force_tabbed.iter().any(|blocked| {