Preserve empty named workspaces upon output removal
Browse files at this commitb5ad0e12fd46f7ab06f4bbc0e80bf3f2d4395cbfParent: c8e46b91 changed file +28 -1
- src/layout/mod.rs +28 -1
src/layout/mod.rsmodified+28 -1
| @@ -403,7 +403,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // Get rid of empty workspaces. |
| 406 | - workspaces.retain(|ws| ws.has_windows()); | |
| 406 | + workspaces.retain(|ws| ws.has_windows() || ws.name.is_some()); | |
| 407 | 407 | |
| 408 | 408 | if monitors.is_empty() { |
| 409 | 409 | // Removed the last monitor. |
| @@ -3811,6 +3811,33 @@ mod tests { | ||
| 3811 | 3811 | check_ops(&ops); |
| 3812 | 3812 | } |
| 3813 | 3813 | |
| 3814 | + #[test] | |
| 3815 | + fn removing_all_outputs_preserves_empty_named_workspaces() { | |
| 3816 | + let ops = [ | |
| 3817 | + Op::AddOutput(1), | |
| 3818 | + Op::AddNamedWorkspace { | |
| 3819 | + ws_name: 1, | |
| 3820 | + output_name: None, | |
| 3821 | + }, | |
| 3822 | + Op::AddNamedWorkspace { | |
| 3823 | + ws_name: 2, | |
| 3824 | + output_name: None, | |
| 3825 | + }, | |
| 3826 | + Op::RemoveOutput(1), | |
| 3827 | + ]; | |
| 3828 | + | |
| 3829 | + let mut layout = Layout::default(); | |
| 3830 | + for op in ops { | |
| 3831 | + op.apply(&mut layout); | |
| 3832 | + } | |
| 3833 | + | |
| 3834 | + let MonitorSet::NoOutputs { workspaces } = layout.monitor_set else { | |
| 3835 | + unreachable!() | |
| 3836 | + }; | |
| 3837 | + | |
| 3838 | + assert_eq!(workspaces.len(), 2); | |
| 3839 | + } | |
| 3840 | + | |
| 3814 | 3841 | fn arbitrary_spacing() -> impl Strategy<Value = u16> { |
| 3815 | 3842 | // Give equal weight to: |
| 3816 | 3843 | // - 0: the element is disabled |