Fix move-window-to-workspace panic when wrong monitor is active
Browse files at this commit9089c3fb0224a7f8d425a02fa299f6a5ea607b17Parent: 6c897d51 changed file +34 -7
- src/layout/mod.rs +34 -7
src/layout/mod.rsmodified+34 -7
| @@ -1904,8 +1904,21 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1904 | } | 1904 | } |
| 1905 | } | 1905 | } |
| 1906 | 1906 | ||
| 1907 | - let Some(monitor) = self.active_monitor() else { | 1907 | + let monitor = if let Some(window) = window { |
| 1908 | - return; | 1908 | + match &mut self.monitor_set { |
| 1909 | + MonitorSet::Normal { monitors, .. } => monitors | ||
| 1910 | + .iter_mut() | ||
| 1911 | + .find(|mon| mon.has_window(window)) | ||
| 1912 | + .unwrap(), | ||
| 1913 | + MonitorSet::NoOutputs { .. } => { | ||
| 1914 | + return; | ||
| 1915 | + } | ||
| 1916 | + } | ||
| 1917 | + } else { | ||
| 1918 | + let Some(monitor) = self.active_monitor() else { | ||
| 1919 | + return; | ||
| 1920 | + }; | ||
| 1921 | + monitor | ||
| 1909 | }; | 1922 | }; |
| 1910 | monitor.move_to_workspace(window, idx); | 1923 | monitor.move_to_workspace(window, idx); |
| 1911 | } | 1924 | } |
| @@ -4935,11 +4948,7 @@ mod tests { | |||
| 4935 | window_id, | 4948 | window_id, |
| 4936 | workspace_idx, | 4949 | workspace_idx, |
| 4937 | } => { | 4950 | } => { |
| 4938 | - let window_id = window_id.filter(|id| { | 4951 | + let window_id = window_id.filter(|id| layout.has_window(id)); |
| 4939 | - layout | ||
| 4940 | - .active_monitor() | ||
| 4941 | - .map_or(false, |mon| mon.has_window(id)) | ||
| 4942 | - }); | ||
| 4943 | layout.move_to_workspace(window_id.as_ref(), workspace_idx); | 4952 | layout.move_to_workspace(window_id.as_ref(), workspace_idx); |
| 4944 | } | 4953 | } |
| 4945 | Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), | 4954 | Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), |
| @@ -6708,6 +6717,24 @@ mod tests { | |||
| 6708 | check_ops(&ops); | 6717 | check_ops(&ops); |
| 6709 | } | 6718 | } |
| 6710 | 6719 | ||
| 6720 | + #[test] | ||
| 6721 | + fn move_window_to_workspace_with_different_active_output() { | ||
| 6722 | + let ops = [ | ||
| 6723 | + Op::AddOutput(0), | ||
| 6724 | + Op::AddOutput(1), | ||
| 6725 | + Op::AddWindow { | ||
| 6726 | + params: TestWindowParams::new(0), | ||
| 6727 | + }, | ||
| 6728 | + Op::FocusOutput(1), | ||
| 6729 | + Op::MoveWindowToWorkspace { | ||
| 6730 | + window_id: Some(0), | ||
| 6731 | + workspace_idx: 2, | ||
| 6732 | + }, | ||
| 6733 | + ]; | ||
| 6734 | + | ||
| 6735 | + check_ops(&ops); | ||
| 6736 | + } | ||
| 6737 | + | ||
| 6711 | fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool { | 6738 | fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool { |
| 6712 | if parent_id == id { | 6739 | if parent_id == id { |
| 6713 | return true; | 6740 | return true; |