diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-29 13:45:29 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-29 13:56:26 +0300 |
| commit | 1c749f578c44daa044bce30c2d3f22eb45970e4b (patch) | |
| tree | 809028c7048a7d22cbb16f9f7b6904a75a91da26 | |
| parent | 3a887a6e499b5bd16fa1b3e5552bab73b93eb36b (diff) | |
| download | niri-1c749f578c44daa044bce30c2d3f22eb45970e4b.tar.gz niri-1c749f578c44daa044bce30c2d3f22eb45970e4b.tar.bz2 niri-1c749f578c44daa044bce30c2d3f22eb45970e4b.zip | |
layout: Update workspace original output on moving even if same monitor
Moving is an explicit action that puts the workspace on a specific monitor. It
makes sense to update the original output even if the workspace already happens
to be on the target monitor.
| -rw-r--r-- | src/layout/mod.rs | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 8eb4c85b..17c97592 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -3046,6 +3046,9 @@ impl<W: LayoutElement> Layout<W> { // Do not do anything if the output is already correct if ¤t.output == output { + // Just update the original output since this is an explicit movement action. + current.active_workspace().original_output = OutputId::new(output); + return false; } @@ -3119,11 +3122,16 @@ impl<W: LayoutElement> Layout<W> { .position(|mon| mon.output == new_output) .unwrap(); + let current = &mut monitors[current_idx]; + + // Do not do anything if the output is already correct if current_idx == target_idx { + // Just update the original output since this is an explicit movement action. + current.workspaces[old_idx].original_output = OutputId::new(¤t.output); + return false; } - let current = &mut monitors[current_idx]; let current_active_ws_idx = current.active_workspace_idx; if old_idx == current.workspaces.len() - 1 { @@ -6066,6 +6074,59 @@ mod tests { } #[test] + fn workspaces_update_original_output_on_moving_to_same_output() { + let ops = [ + Op::AddOutput(1), + Op::SetWorkspaceName { + new_ws_name: 1, + ws_name: None, + }, + Op::AddOutput(2), + Op::RemoveOutput(1), + Op::FocusWorkspaceUp, + Op::MoveWorkspaceToOutput(2), + Op::AddOutput(1), + ]; + + let layout = check_ops(&ops); + let (mon, _, ws) = layout + .workspaces() + .find(|(_, _, ws)| ws.name().is_some()) + .unwrap(); + assert!(ws.name().is_some()); // Sanity check. + let mon = mon.unwrap(); + assert_eq!(mon.output_name(), "output2"); + } + + #[test] + fn workspaces_update_original_output_on_moving_to_same_monitor() { + let ops = [ + Op::AddOutput(1), + Op::SetWorkspaceName { + new_ws_name: 1, + ws_name: None, + }, + Op::AddOutput(2), + Op::RemoveOutput(1), + Op::FocusWorkspaceUp, + Op::MoveWorkspaceToMonitor { + ws_name: Some(1), + output_id: 2, + }, + Op::AddOutput(1), + ]; + + let layout = check_ops(&ops); + let (mon, _, ws) = layout + .workspaces() + .find(|(_, _, ws)| ws.name().is_some()) + .unwrap(); + assert!(ws.name().is_some()); // Sanity check. + let mon = mon.unwrap(); + assert_eq!(mon.output_name(), "output2"); + } + + #[test] fn large_negative_height_change() { let ops = [ Op::AddOutput(1), |
