Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: focus float nodes when switching workspaces #335

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/it/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ mod t0040_virtual_keyboard;
mod t0041_input_method;
mod t0042_toplevel_select;
mod t0043_destroy_registry;
mod t0044_stacked_focus;

pub trait TestCase: Sync {
fn name(&self) -> &'static str;
Expand Down Expand Up @@ -137,5 +138,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> {
t0041_input_method,
t0042_toplevel_select,
t0043_destroy_registry,
t0044_stacked_focus,
}
}
40 changes: 40 additions & 0 deletions src/it/tests/t0044_stacked_focus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use {
crate::{
it::{test_error::TestError, testrun::TestRun},
tree::ToplevelNodeBase,
},
std::rc::Rc,
};

testcase!();

/// Test that container focus is set to a lone stacked window when switching to its workspace
async fn test(run: Rc<TestRun>) -> Result<(), TestError> {
let ds = run.create_default_setup().await?;
let client = run.create_client().await?;

run.cfg.show_workspace(ds.seat.id(), "1")?;
let win1 = client.create_window().await?;
win1.map().await?;
client.sync().await;
run.cfg.set_floating(ds.seat.id(), true)?;

run.cfg.show_workspace(ds.seat.id(), "2")?;
let win2 = client.create_window().await?;
win2.map().await?;
client.sync().await;

run.cfg.show_workspace(ds.seat.id(), "1")?;

let container = match win1.tl.server.tl_data().parent.get() {
Some(p) => match p.node_into_float() {
Some(p) => p,
_ => bail!("Containing node is not a float"),
},
_ => bail!("Toplevel doesn't have a parent"),
};

tassert!(container.active.get());

Ok(())
}
8 changes: 8 additions & 0 deletions src/tree/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ impl Node for WorkspaceNode {
fs.tl_into_node().node_do_focus(seat, direction);
} else if let Some(container) = self.container.get() {
container.node_do_focus(seat, direction);
} else if let Some(float) = self
.stacked
.rev_iter()
.find_map(|node| (*node).clone().node_into_float())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clone can be avoided but it doesn't allocate so I don't think it makes much of a difference

{
if let Some(child) = float.child.get() {
child.node_do_focus(seat, direction);
}
}
}

Expand Down
Loading