1
0
Fork 0
forked from wry/wry

container: autotile uses major axis as first split

This commit is contained in:
atagen 2026-06-08 19:20:46 +10:00
parent dc62d2240f
commit c1b2c7f17c
8 changed files with 83 additions and 11 deletions

View file

@ -344,6 +344,12 @@ impl TestConfig {
pub fn set_autotile(&self, enabled: bool) -> TestResult {
self.send(ClientMessage::SetAutotile { enabled })
}
pub fn get_autotile(&self) -> Result<bool, TestError> {
let reply = self.send_with_reply(ClientMessage::GetAutotile)?;
get_response!(reply, GetAutotile { enabled });
Ok(enabled)
}
}
impl Drop for TestConfig {

View file

@ -11,6 +11,7 @@ testcase!();
async fn test(run: Rc<TestRun>) -> TestResult {
run.backend.install_default()?;
run.cfg.set_autotile(true)?;
tassert_eq!(run.cfg.get_autotile()?, true);
let client = run.create_client().await?;

View file

@ -89,11 +89,27 @@ impl State {
} else {
lap.add_child_after(&*la, node);
}
} else if autotile {
if let Some(last) = c.children.last() {
let la = last_child_descendant(last.node.clone());
let lap = la
.tl_data()
.parent
.get()
.and_then(|n| n.node_into_container());
if let Some(lap) = lap {
lap.add_tiled_child_after(&*la, node);
} else {
c.append_child(node);
}
} else {
c.append_child(node);
}
} else {
c.append_child(node);
}
} else {
let container = ContainerNode::new(self, ws, node, ContainerSplit::Horizontal);
let container = ContainerNode::new(self, ws, node, initial_split_for_workspace(ws));
ws.set_container(&container);
}
}
@ -537,3 +553,40 @@ impl State {
}
}
fn initial_split_for_workspace(ws: &WorkspaceNode) -> ContainerSplit {
ContainerSplit::for_largest_axis(ws.output.get().global.pos.get())
}
fn last_child_descendant(mut node: Rc<dyn ToplevelNode>) -> Rc<dyn ToplevelNode> {
loop {
let Some(container) = node.clone().node_into_container() else {
return node;
};
let Some(last) = container.children.last() else {
return container;
};
node = last.node.clone();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn initial_split_uses_largest_output_axis() {
assert_eq!(
ContainerSplit::for_largest_axis(Rect::new_sized_saturating(0, 0, 800, 600)),
ContainerSplit::Horizontal
);
assert_eq!(
ContainerSplit::for_largest_axis(Rect::new_sized_saturating(0, 0, 600, 800)),
ContainerSplit::Vertical
);
assert_eq!(
ContainerSplit::for_largest_axis(Rect::new_sized_saturating(0, 0, 600, 600)),
ContainerSplit::Horizontal
);
}
}

View file

@ -60,6 +60,14 @@ pub enum ContainerSplit {
}
impl ContainerSplit {
pub fn for_largest_axis(rect: Rect) -> Self {
if rect.height() > rect.width() {
ContainerSplit::Vertical
} else {
ContainerSplit::Horizontal
}
}
pub fn other(self) -> Self {
match self {
ContainerSplit::Horizontal => ContainerSplit::Vertical,
@ -302,11 +310,12 @@ impl ContainerNode {
};
let focused_node = focused.node.clone();
let focused_active = focused_node.tl_data().active();
let split = ContainerSplit::for_largest_axis(focused.body.get());
let sub = ContainerNode::new(
&self.state,
&self.workspace.get(),
focused_node.clone(),
self.split.get().other(),
split,
);
// Autotile-created groups are structural and collapse once only one
// child remains. Explicit make-group commands control their own