Fix moving empty workspaces to original output

This commit is contained in:
Ivan Molodetskikh
2023-10-14 20:32:53 +04:00
parent c29fdcaccb
commit d1f431fd7e
+40 -5
View File
@@ -479,7 +479,13 @@ impl<W: LayoutElement> Layout<W> {
for i in (0..primary.workspaces.len()).rev() {
if primary.workspaces[i].original_output == id {
let ws = primary.workspaces.remove(i);
workspaces.push(ws);
// The user could've closed a window while remaining on this workspace, on
// another monitor. However, we will add an empty workspace in the end
// instead.
if ws.has_windows() {
workspaces.push(ws);
}
if i <= primary.active_workspace_idx {
primary.active_workspace_idx =
@@ -488,10 +494,9 @@ impl<W: LayoutElement> Layout<W> {
}
}
workspaces.reverse();
if workspaces.iter().all(|ws| ws.has_windows()) {
// Make sure there's always an empty workspace.
workspaces.push(Workspace::new(output.clone(), self.options.clone()));
}
// Make sure there's always an empty workspace.
workspaces.push(Workspace::new(output.clone(), self.options.clone()));
for ws in &mut workspaces {
ws.set_output(Some(output.clone()));
@@ -1074,6 +1079,11 @@ impl<W: LayoutElement> Layout<W> {
);
}
assert!(
monitor.workspaces.last().unwrap().columns.is_empty(),
"monitor must have an empty workspace in the end"
);
// FIXME: verify that primary doesn't have any workspaces for which their own monitor
// exists.
@@ -3286,6 +3296,31 @@ mod tests {
assert!(monitors[0].workspaces[0].has_windows());
}
#[test]
fn empty_workspaces_dont_move_back_to_original_output() {
let ops = [
Op::AddOutput(1),
Op::AddWindow {
id: 1,
bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
activate: true,
},
Op::FocusWorkspaceDown,
Op::AddWindow {
id: 2,
bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
activate: true,
},
Op::AddOutput(2),
Op::RemoveOutput(1),
Op::FocusWorkspace(1),
Op::CloseWindow(1),
Op::AddOutput(1),
];
check_ops(&ops);
}
proptest! {
#![proptest_config(ProptestConfig {
cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() {