Fix panic when the last window on previous workspace is closed
Browse files at this commitd3735227cec6439d36cd2f6061df5dbc7cc9bc19Parent: 5ad5f291 changed file +20 -0
- src/layout.rs +20 -0
src/layout.rsmodified+20 -0
| @@ -528,6 +528,10 @@ impl<W: LayoutElement> MonitorSet<W> { | |||
| 528 | && idx != mon.workspaces.len() - 1 | 528 | && idx != mon.workspaces.len() - 1 |
| 529 | { | 529 | { |
| 530 | mon.workspaces.remove(idx); | 530 | mon.workspaces.remove(idx); |
| 531 | + | ||
| 532 | + if idx < mon.active_workspace_idx { | ||
| 533 | + mon.active_workspace_idx -= 1; | ||
| 534 | + } | ||
| 531 | } | 535 | } |
| 532 | 536 | ||
| 533 | break; | 537 | break; |
| @@ -2612,4 +2616,20 @@ mod tests { | |||
| 2612 | 2616 | ||
| 2613 | check_ops(&ops); | 2617 | check_ops(&ops); |
| 2614 | } | 2618 | } |
| 2619 | + | ||
| 2620 | + #[test] | ||
| 2621 | + fn test() { | ||
| 2622 | + let ops = [ | ||
| 2623 | + Op::AddOutput(1), | ||
| 2624 | + Op::AddWindow { | ||
| 2625 | + id: 0, | ||
| 2626 | + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 2627 | + activate: true, | ||
| 2628 | + }, | ||
| 2629 | + Op::FocusWorkspaceDown, | ||
| 2630 | + Op::CloseWindow(0), | ||
| 2631 | + ]; | ||
| 2632 | + | ||
| 2633 | + check_ops(&ops); | ||
| 2634 | + } | ||
| 2615 | } | 2635 | } |