From 756997ca83ddee8768ab3fda5fe2d98da365a038 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 26 Sep 2023 20:36:48 +0400 Subject: Fix panic when adding previously-removed output sometimes --- src/layout.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/layout.rs') diff --git a/src/layout.rs b/src/layout.rs index cd8ea9b0..f72e57b4 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -363,6 +363,11 @@ impl MonitorSet { if primary.workspaces[i].original_output == id { let ws = primary.workspaces.remove(i); workspaces.push(ws); + + if i <= primary.active_workspace_idx { + primary.active_workspace_idx = + primary.active_workspace_idx.saturating_sub(1); + } } } workspaces.reverse(); @@ -2573,4 +2578,33 @@ mod tests { } } } + + #[test] + fn primary_active_workspace_idx_not_updated_on_output_add() { + let ops = [ + Op::AddOutput(1), + Op::AddOutput(2), + Op::FocusOutput(1), + Op::AddWindow { + id: 0, + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), + activate: true, + }, + Op::FocusOutput(2), + Op::AddWindow { + id: 1, + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), + activate: true, + }, + Op::RemoveOutput(2), + Op::FocusWorkspace(3), + Op::AddOutput(2), + ]; + + let mut monitor_set = MonitorSet::default(); + for op in ops { + op.apply(&mut monitor_set); + monitor_set.verify_invariants(); + } + } } -- cgit