layout: Deduplicate move_workspace_to_output()
Browse files at this commit36dc5c6e8e82028d7a1a2cbf6bf411c1a030eea2Parent: ea3bbea4 changed files +10 -32
- src/handlers/mod.rs +1 -1
- src/input/mod.rs +1 -1
- src/layout/mod.rs +7 -29
- src/layout/tests.rs +1 -1
src/handlers/mod.rsmodified+1 -1
| @@ -583,7 +583,7 @@ impl ExtWorkspaceHandler for State { | |||
| 583 | if let Some((old_output, old_idx)) = self.niri.find_output_and_workspace_index(reference) { | 583 | if let Some((old_output, old_idx)) = self.niri.find_output_and_workspace_index(reference) { |
| 584 | self.niri | 584 | self.niri |
| 585 | .layout | 585 | .layout |
| 586 | - .move_workspace_to_output_by_id(old_idx, old_output, output); | 586 | + .move_workspace_to_output_by_id(old_idx, old_output, &output); |
| 587 | } | 587 | } |
| 588 | } | 588 | } |
| 589 | } | 589 | } |
src/input/mod.rsmodified+1 -1
| @@ -1950,7 +1950,7 @@ impl State { | |||
| 1950 | if self.niri.layout.move_workspace_to_output_by_id( | 1950 | if self.niri.layout.move_workspace_to_output_by_id( |
| 1951 | old_idx, | 1951 | old_idx, |
| 1952 | output, | 1952 | output, |
| 1953 | - new_output.clone(), | 1953 | + &new_output, |
| 1954 | ) { | 1954 | ) { |
| 1955 | // Cursor warp already calls `queue_redraw_all` | 1955 | // Cursor warp already calls `queue_redraw_all` |
| 1956 | if !self.maybe_warp_cursor_to_focus_centered() { | 1956 | if !self.maybe_warp_cursor_to_focus_centered() { |
src/layout/mod.rsmodified+7 -29
| @@ -3387,43 +3387,21 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3387 | monitors, | 3387 | monitors, |
| 3388 | active_monitor_idx, | 3388 | active_monitor_idx, |
| 3389 | .. | 3389 | .. |
| 3390 | - } = &mut self.monitor_set | 3390 | + } = &self.monitor_set |
| 3391 | else { | 3391 | else { |
| 3392 | return false; | 3392 | return false; |
| 3393 | }; | 3393 | }; |
| 3394 | 3394 | ||
| 3395 | - let current = &mut monitors[*active_monitor_idx]; | 3395 | + let idx = monitors[*active_monitor_idx].active_workspace_idx; |
| 3396 | - | 3396 | + self.move_workspace_to_output_by_id(idx, None, output) |
| 3397 | - // Do not do anything if the output is already correct | ||
| 3398 | - if ¤t.output == output { | ||
| 3399 | - // Just update the original output since this is an explicit movement action. | ||
| 3400 | - current.active_workspace().original_output = OutputId::new(output); | ||
| 3401 | - | ||
| 3402 | - return false; | ||
| 3403 | - } | ||
| 3404 | - | ||
| 3405 | - let mut ws = current.remove_workspace_by_idx(current.active_workspace_idx); | ||
| 3406 | - ws.original_output = OutputId::new(output); | ||
| 3407 | - | ||
| 3408 | - let target_idx = monitors | ||
| 3409 | - .iter() | ||
| 3410 | - .position(|mon| &mon.output == output) | ||
| 3411 | - .unwrap(); | ||
| 3412 | - let target = &mut monitors[target_idx]; | ||
| 3413 | - | ||
| 3414 | - target.insert_workspace(ws, target.active_workspace_idx + 1, true); | ||
| 3415 | - | ||
| 3416 | - *active_monitor_idx = target_idx; | ||
| 3417 | - | ||
| 3418 | - true | ||
| 3419 | } | 3397 | } |
| 3420 | 3398 | ||
| 3421 | - // FIXME: accept workspace by id and deduplicate logic with move_workspace_to_output() | 3399 | + // FIXME: accept workspace by id |
| 3422 | pub fn move_workspace_to_output_by_id( | 3400 | pub fn move_workspace_to_output_by_id( |
| 3423 | &mut self, | 3401 | &mut self, |
| 3424 | old_idx: usize, | 3402 | old_idx: usize, |
| 3425 | old_output: Option<Output>, | 3403 | old_output: Option<Output>, |
| 3426 | - new_output: Output, | 3404 | + new_output: &Output, |
| 3427 | ) -> bool { | 3405 | ) -> bool { |
| 3428 | let MonitorSet::Normal { | 3406 | let MonitorSet::Normal { |
| 3429 | monitors, | 3407 | monitors, |
| @@ -3444,7 +3422,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3444 | }; | 3422 | }; |
| 3445 | let target_idx = monitors | 3423 | let target_idx = monitors |
| 3446 | .iter() | 3424 | .iter() |
| 3447 | - .position(|mon| mon.output == new_output) | 3425 | + .position(|mon| mon.output == *new_output) |
| 3448 | .unwrap(); | 3426 | .unwrap(); |
| 3449 | 3427 | ||
| 3450 | let current = &mut monitors[current_idx]; | 3428 | let current = &mut monitors[current_idx]; |
| @@ -3467,7 +3445,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3467 | current_idx == *active_monitor_idx && old_idx == current.active_workspace_idx; | 3445 | current_idx == *active_monitor_idx && old_idx == current.active_workspace_idx; |
| 3468 | 3446 | ||
| 3469 | let mut ws = current.remove_workspace_by_idx(old_idx); | 3447 | let mut ws = current.remove_workspace_by_idx(old_idx); |
| 3470 | - ws.original_output = OutputId::new(&new_output); | 3448 | + ws.original_output = OutputId::new(new_output); |
| 3471 | 3449 | ||
| 3472 | let target = &mut monitors[target_idx]; | 3450 | let target = &mut monitors[target_idx]; |
| 3473 | target.insert_workspace(ws, target.active_workspace_idx + 1, activate); | 3451 | target.insert_workspace(ws, target.active_workspace_idx + 1, activate); |
src/layout/tests.rsmodified+1 -1
| @@ -1245,7 +1245,7 @@ impl Op { | |||
| 1245 | return; | 1245 | return; |
| 1246 | }; | 1246 | }; |
| 1247 | 1247 | ||
| 1248 | - layout.move_workspace_to_output_by_id(old_idx, Some(old_output), output); | 1248 | + layout.move_workspace_to_output_by_id(old_idx, Some(old_output), &output); |
| 1249 | } | 1249 | } |
| 1250 | Op::SwitchPresetColumnWidth => layout.toggle_width(true), | 1250 | Op::SwitchPresetColumnWidth => layout.toggle_width(true), |
| 1251 | Op::SwitchPresetColumnWidthBack => layout.toggle_width(false), | 1251 | Op::SwitchPresetColumnWidthBack => layout.toggle_width(false), |