layout: Fix crash when a window opens next-to an only interactively moved window with no outputs
Browse files at this commitb2d2a766e48fb4331370c619bd013c50ba75686aParent: cd0d45f2 changed files +42 -1
- src/layout/mod.rs +9 -1
- src/layout/tests.rs +33 -0
src/layout/mod.rsmodified+9 -1
| @@ -1142,7 +1142,15 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1142 | .filter(|move_| next_to == move_.tile.window().id()) | 1142 | .filter(|move_| next_to == move_.tile.window().id()) |
| 1143 | .is_some() | 1143 | .is_some() |
| 1144 | { | 1144 | { |
| 1145 | - // The next_to window is being interactively moved. | 1145 | + // The next_to window is being interactively moved. If there are no |
| 1146 | + // other windows, we may have no workspaces at all. | ||
| 1147 | + if workspaces.is_empty() { | ||
| 1148 | + workspaces.push(Workspace::new_no_outputs( | ||
| 1149 | + self.clock.clone(), | ||
| 1150 | + self.options.clone(), | ||
| 1151 | + )); | ||
| 1152 | + } | ||
| 1153 | + | ||
| 1146 | (0, WorkspaceAddWindowTarget::Auto) | 1154 | (0, WorkspaceAddWindowTarget::Auto) |
| 1147 | } else { | 1155 | } else { |
| 1148 | let ws_idx = workspaces | 1156 | let ws_idx = workspaces |
src/layout/tests.rsmodified+33 -0
| @@ -2937,6 +2937,39 @@ fn interactive_move_drop_on_other_output_during_animation() { | |||
| 2937 | check_ops(&ops); | 2937 | check_ops(&ops); |
| 2938 | } | 2938 | } |
| 2939 | 2939 | ||
| 2940 | +#[test] | ||
| 2941 | +fn add_window_next_to_only_interactively_moved_without_outputs() { | ||
| 2942 | + let ops = [ | ||
| 2943 | + Op::AddWindow { | ||
| 2944 | + params: TestWindowParams::new(2), | ||
| 2945 | + }, | ||
| 2946 | + Op::AddOutput(1), | ||
| 2947 | + Op::InteractiveMoveBegin { | ||
| 2948 | + window: 2, | ||
| 2949 | + output_idx: 1, | ||
| 2950 | + px: 0.0, | ||
| 2951 | + py: 0.0, | ||
| 2952 | + }, | ||
| 2953 | + Op::InteractiveMoveUpdate { | ||
| 2954 | + window: 2, | ||
| 2955 | + dx: 0.0, | ||
| 2956 | + dy: 3586.692842955048, | ||
| 2957 | + output_idx: 1, | ||
| 2958 | + px: 0.0, | ||
| 2959 | + py: 0.0, | ||
| 2960 | + }, | ||
| 2961 | + Op::RemoveOutput(1), | ||
| 2962 | + // We have no outputs, and the only existing window is interactively moved, meaning there | ||
| 2963 | + // are no workspaces either. | ||
| 2964 | + Op::AddWindowNextTo { | ||
| 2965 | + params: TestWindowParams::new(3), | ||
| 2966 | + next_to_id: 2, | ||
| 2967 | + }, | ||
| 2968 | + ]; | ||
| 2969 | + | ||
| 2970 | + check_ops(&ops); | ||
| 2971 | +} | ||
| 2972 | + | ||
| 2940 | #[test] | 2973 | #[test] |
| 2941 | fn set_width_fixed_negative() { | 2974 | fn set_width_fixed_negative() { |
| 2942 | let ops = [ | 2975 | let ops = [ |