Skip to content

Commit

Permalink
tree: focus float nodes when switching workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeokondrak committed Dec 26, 2024
1 parent 206a2ed commit a81e2d6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
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(())
}
6 changes: 6 additions & 0 deletions src/tree/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ impl Node for WorkspaceNode {
fn node_do_focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
if let Some(fs) = self.fullscreen.get() {
fs.tl_into_node().node_do_focus(seat, direction);
} else if let Some(stacked) = self.stacked.first() {
if let Some(float) = Rc::clone(&stacked).node_into_float() {
if let Some(child) = float.child.get() {
child.node_do_focus(seat, direction);
}
}
} else if let Some(container) = self.container.get() {
container.node_do_focus(seat, direction);
}
Expand Down

0 comments on commit a81e2d6

Please sign in to comment.