diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-26 20:36:48 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-26 20:36:48 +0400 |
| commit | 756997ca83ddee8768ab3fda5fe2d98da365a038 (patch) | |
| tree | b9a1b1734e3b9414ec36811ba179798700d125ee /src | |
| parent | b7be8fcb75d8b03d7cc55df24d5f2730c9a17b3f (diff) | |
| download | niri-756997ca83ddee8768ab3fda5fe2d98da365a038.tar.gz niri-756997ca83ddee8768ab3fda5fe2d98da365a038.tar.bz2 niri-756997ca83ddee8768ab3fda5fe2d98da365a038.zip | |
Fix panic when adding previously-removed output sometimes
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout.rs | 34 |
1 files changed, 34 insertions, 0 deletions
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<W: LayoutElement> MonitorSet<W> { 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(); + } + } } |
