Fix panic when adding previously-removed output sometimes
Browse files at this commit756997ca83ddee8768ab3fda5fe2d98da365a038Parent: b7be8fc1 changed file +34 -0
- src/layout.rs +34 -0
src/layout.rsmodified+34 -0
| @@ -363,6 +363,11 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 363 | if primary.workspaces[i].original_output == id { | 363 | if primary.workspaces[i].original_output == id { |
| 364 | let ws = primary.workspaces.remove(i); | 364 | let ws = primary.workspaces.remove(i); |
| 365 | workspaces.push(ws); | 365 | workspaces.push(ws); |
| 366 | + | ||
| 367 | + if i <= primary.active_workspace_idx { | ||
| 368 | + primary.active_workspace_idx = | ||
| 369 | + primary.active_workspace_idx.saturating_sub(1); | ||
| 370 | + } | ||
| 366 | } | 371 | } |
| 367 | } | 372 | } |
| 368 | workspaces.reverse(); | 373 | workspaces.reverse(); |
| @@ -2573,4 +2578,33 @@ mod tests { | |||
| 2573 | } | 2578 | } |
| 2574 | } | 2579 | } |
| 2575 | } | 2580 | } |
| 2581 | + | ||
| 2582 | + #[test] | ||
| 2583 | + fn primary_active_workspace_idx_not_updated_on_output_add() { | ||
| 2584 | + let ops = [ | ||
| 2585 | + Op::AddOutput(1), | ||
| 2586 | + Op::AddOutput(2), | ||
| 2587 | + Op::FocusOutput(1), | ||
| 2588 | + Op::AddWindow { | ||
| 2589 | + id: 0, | ||
| 2590 | + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 2591 | + activate: true, | ||
| 2592 | + }, | ||
| 2593 | + Op::FocusOutput(2), | ||
| 2594 | + Op::AddWindow { | ||
| 2595 | + id: 1, | ||
| 2596 | + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 2597 | + activate: true, | ||
| 2598 | + }, | ||
| 2599 | + Op::RemoveOutput(2), | ||
| 2600 | + Op::FocusWorkspace(3), | ||
| 2601 | + Op::AddOutput(2), | ||
| 2602 | + ]; | ||
| 2603 | + | ||
| 2604 | + let mut monitor_set = MonitorSet::default(); | ||
| 2605 | + for op in ops { | ||
| 2606 | + op.apply(&mut monitor_set); | ||
| 2607 | + monitor_set.verify_invariants(); | ||
| 2608 | + } | ||
| 2609 | + } | ||
| 2576 | } | 2610 | } |