Add focus argument to move-window-to-workspace (#1332)
Browse files at this commit6 changed files +58 -19
- niri-config/src/lib.rs +9 -2
- niri-ipc/src/lib.rs +8 -0
- src/input/mod.rs +17 -4
- src/layout/mod.rs +7 -2
- src/layout/monitor.rs +16 -10
- src/layout/tests.rs +1 -1
niri-config/src/lib.rsmodified+9 -2
| @@ -1592,11 +1592,15 @@ pub enum Action { | |||
| 1592 | FocusWorkspacePrevious, | 1592 | FocusWorkspacePrevious, |
| 1593 | MoveWindowToWorkspaceDown, | 1593 | MoveWindowToWorkspaceDown, |
| 1594 | MoveWindowToWorkspaceUp, | 1594 | MoveWindowToWorkspaceUp, |
| 1595 | - MoveWindowToWorkspace(#[knuffel(argument)] WorkspaceReference), | 1595 | + MoveWindowToWorkspace( |
| 1596 | + #[knuffel(argument)] WorkspaceReference, | ||
| 1597 | + #[knuffel(property(name = "focus"), default = true)] bool, | ||
| 1598 | + ), | ||
| 1596 | #[knuffel(skip)] | 1599 | #[knuffel(skip)] |
| 1597 | MoveWindowToWorkspaceById { | 1600 | MoveWindowToWorkspaceById { |
| 1598 | window_id: u64, | 1601 | window_id: u64, |
| 1599 | reference: WorkspaceReference, | 1602 | reference: WorkspaceReference, |
| 1603 | + focus: bool, | ||
| 1600 | }, | 1604 | }, |
| 1601 | MoveColumnToWorkspaceDown, | 1605 | MoveColumnToWorkspaceDown, |
| 1602 | MoveColumnToWorkspaceUp, | 1606 | MoveColumnToWorkspaceUp, |
| @@ -1817,13 +1821,16 @@ impl From<niri_ipc::Action> for Action { | |||
| 1817 | niri_ipc::Action::MoveWindowToWorkspace { | 1821 | niri_ipc::Action::MoveWindowToWorkspace { |
| 1818 | window_id: None, | 1822 | window_id: None, |
| 1819 | reference, | 1823 | reference, |
| 1820 | - } => Self::MoveWindowToWorkspace(WorkspaceReference::from(reference)), | 1824 | + focus, |
| 1825 | + } => Self::MoveWindowToWorkspace(WorkspaceReference::from(reference), focus), | ||
| 1821 | niri_ipc::Action::MoveWindowToWorkspace { | 1826 | niri_ipc::Action::MoveWindowToWorkspace { |
| 1822 | window_id: Some(window_id), | 1827 | window_id: Some(window_id), |
| 1823 | reference, | 1828 | reference, |
| 1829 | + focus, | ||
| 1824 | } => Self::MoveWindowToWorkspaceById { | 1830 | } => Self::MoveWindowToWorkspaceById { |
| 1825 | window_id, | 1831 | window_id, |
| 1826 | reference: WorkspaceReference::from(reference), | 1832 | reference: WorkspaceReference::from(reference), |
| 1833 | + focus, | ||
| 1827 | }, | 1834 | }, |
| 1828 | niri_ipc::Action::MoveColumnToWorkspaceDown {} => Self::MoveColumnToWorkspaceDown, | 1835 | niri_ipc::Action::MoveColumnToWorkspaceDown {} => Self::MoveColumnToWorkspaceDown, |
| 1829 | niri_ipc::Action::MoveColumnToWorkspaceUp {} => Self::MoveColumnToWorkspaceUp, | 1836 | niri_ipc::Action::MoveColumnToWorkspaceUp {} => Self::MoveColumnToWorkspaceUp, |
niri-ipc/src/lib.rsmodified+8 -0
| @@ -426,6 +426,14 @@ pub enum Action { | |||
| 426 | /// Reference (index or name) of the workspace to move the window to. | 426 | /// Reference (index or name) of the workspace to move the window to. |
| 427 | #[cfg_attr(feature = "clap", arg())] | 427 | #[cfg_attr(feature = "clap", arg())] |
| 428 | reference: WorkspaceReferenceArg, | 428 | reference: WorkspaceReferenceArg, |
| 429 | + | ||
| 430 | + /// Whether the focus should follow the moved window. | ||
| 431 | + /// | ||
| 432 | + /// If `true` (the default) and the window to move is focused, the focus will follow the | ||
| 433 | + /// window to the new workspace. If `false`, the focus will remain on the original | ||
| 434 | + /// workspace. | ||
| 435 | + #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | ||
| 436 | + focus: bool, | ||
| 429 | }, | 437 | }, |
| 430 | /// Move the focused column to the workspace below. | 438 | /// Move the focused column to the workspace below. |
| 431 | MoveColumnToWorkspaceDown {}, | 439 | MoveColumnToWorkspaceDown {}, |
src/input/mod.rsmodified+17 -4
| @@ -40,7 +40,7 @@ use self::move_grab::MoveGrab; | |||
| 40 | use self::resize_grab::ResizeGrab; | 40 | use self::resize_grab::ResizeGrab; |
| 41 | use self::spatial_movement_grab::SpatialMovementGrab; | 41 | use self::spatial_movement_grab::SpatialMovementGrab; |
| 42 | use crate::layout::scrolling::ScrollDirection; | 42 | use crate::layout::scrolling::ScrollDirection; |
| 43 | -use crate::layout::LayoutElement as _; | 43 | +use crate::layout::{ActivateWindow, LayoutElement as _}; |
| 44 | use crate::niri::{CastTarget, State}; | 44 | use crate::niri::{CastTarget, State}; |
| 45 | use crate::ui::screenshot_ui::ScreenshotUi; | 45 | use crate::ui::screenshot_ui::ScreenshotUi; |
| 46 | use crate::utils::spawning::spawn; | 46 | use crate::utils::spawning::spawn; |
| @@ -1072,7 +1072,7 @@ impl State { | |||
| 1072 | // FIXME: granular | 1072 | // FIXME: granular |
| 1073 | self.niri.queue_redraw_all(); | 1073 | self.niri.queue_redraw_all(); |
| 1074 | } | 1074 | } |
| 1075 | - Action::MoveWindowToWorkspace(reference) => { | 1075 | + Action::MoveWindowToWorkspace(reference, focus) => { |
| 1076 | if let Some((mut output, index)) = | 1076 | if let Some((mut output, index)) = |
| 1077 | self.niri.find_output_and_workspace_index(reference) | 1077 | self.niri.find_output_and_workspace_index(reference) |
| 1078 | { | 1078 | { |
| @@ -1091,7 +1091,12 @@ impl State { | |||
| 1091 | self.move_cursor_to_output(&output); | 1091 | self.move_cursor_to_output(&output); |
| 1092 | } | 1092 | } |
| 1093 | } else { | 1093 | } else { |
| 1094 | - self.niri.layout.move_to_workspace(None, index); | 1094 | + let activate = if focus { |
| 1095 | + ActivateWindow::Smart | ||
| 1096 | + } else { | ||
| 1097 | + ActivateWindow::No | ||
| 1098 | + }; | ||
| 1099 | + self.niri.layout.move_to_workspace(None, index, activate); | ||
| 1095 | self.maybe_warp_cursor_to_focus(); | 1100 | self.maybe_warp_cursor_to_focus(); |
| 1096 | } | 1101 | } |
| 1097 | 1102 | ||
| @@ -1102,6 +1107,7 @@ impl State { | |||
| 1102 | Action::MoveWindowToWorkspaceById { | 1107 | Action::MoveWindowToWorkspaceById { |
| 1103 | window_id: id, | 1108 | window_id: id, |
| 1104 | reference, | 1109 | reference, |
| 1110 | + focus, | ||
| 1105 | } => { | 1111 | } => { |
| 1106 | let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | 1112 | let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); |
| 1107 | let window = window.map(|(_, m)| m.window.clone()); | 1113 | let window = window.map(|(_, m)| m.window.clone()); |
| @@ -1130,7 +1136,14 @@ impl State { | |||
| 1130 | } | 1136 | } |
| 1131 | } | 1137 | } |
| 1132 | } else { | 1138 | } else { |
| 1133 | - self.niri.layout.move_to_workspace(Some(&window), index); | 1139 | + let activate = if focus { |
| 1140 | + ActivateWindow::Smart | ||
| 1141 | + } else { | ||
| 1142 | + ActivateWindow::No | ||
| 1143 | + }; | ||
| 1144 | + self.niri | ||
| 1145 | + .layout | ||
| 1146 | + .move_to_workspace(Some(&window), index, activate); | ||
| 1134 | 1147 | ||
| 1135 | // If we focused the target window. | 1148 | // If we focused the target window. |
| 1136 | let new_focus = self.niri.layout.focus(); | 1149 | let new_focus = self.niri.layout.focus(); |
src/layout/mod.rsmodified+7 -2
| @@ -2120,7 +2120,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2120 | monitor.move_to_workspace_down(); | 2120 | monitor.move_to_workspace_down(); |
| 2121 | } | 2121 | } |
| 2122 | 2122 | ||
| 2123 | - pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) { | 2123 | + pub fn move_to_workspace( |
| 2124 | + &mut self, | ||
| 2125 | + window: Option<&W::Id>, | ||
| 2126 | + idx: usize, | ||
| 2127 | + activate: ActivateWindow, | ||
| 2128 | + ) { | ||
| 2124 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 2129 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2125 | if window.is_none() || window == Some(move_.tile.window().id()) { | 2130 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| 2126 | return; | 2131 | return; |
| @@ -2143,7 +2148,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2143 | }; | 2148 | }; |
| 2144 | monitor | 2149 | monitor |
| 2145 | }; | 2150 | }; |
| 2146 | - monitor.move_to_workspace(window, idx); | 2151 | + monitor.move_to_workspace(window, idx, activate); |
| 2147 | } | 2152 | } |
| 2148 | 2153 | ||
| 2149 | pub fn move_column_to_workspace_up(&mut self) { | 2154 | pub fn move_column_to_workspace_up(&mut self) { |
src/layout/monitor.rsmodified+16 -10
| @@ -474,7 +474,12 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 474 | ); | 474 | ); |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | - pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) { | 477 | + pub fn move_to_workspace( |
| 478 | + &mut self, | ||
| 479 | + window: Option<&W::Id>, | ||
| 480 | + idx: usize, | ||
| 481 | + activate: ActivateWindow, | ||
| 482 | + ) { | ||
| 478 | let source_workspace_idx = if let Some(window) = window { | 483 | let source_workspace_idx = if let Some(window) = window { |
| 479 | self.workspaces | 484 | self.workspaces |
| 480 | .iter() | 485 | .iter() |
| @@ -490,14 +495,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 490 | } | 495 | } |
| 491 | let new_id = self.workspaces[new_idx].id(); | 496 | let new_id = self.workspaces[new_idx].id(); |
| 492 | 497 | ||
| 493 | - let activate = window.map_or(true, |win| { | 498 | + let activate = activate.map_smart(|| { |
| 494 | - self.active_window().map(|win| win.id()) == Some(win) | 499 | + window.map_or(true, |win| { |
| 500 | + self.active_window().map(|win| win.id()) == Some(win) | ||
| 501 | + }) | ||
| 495 | }); | 502 | }); |
| 496 | - let activate = if activate { | ||
| 497 | - ActivateWindow::Yes | ||
| 498 | - } else { | ||
| 499 | - ActivateWindow::No | ||
| 500 | - }; | ||
| 501 | 503 | ||
| 502 | let workspace = &mut self.workspaces[source_workspace_idx]; | 504 | let workspace = &mut self.workspaces[source_workspace_idx]; |
| 503 | let transaction = Transaction::new(); | 505 | let transaction = Transaction::new(); |
| @@ -515,7 +517,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 515 | id: new_id, | 517 | id: new_id, |
| 516 | column_idx: None, | 518 | column_idx: None, |
| 517 | }, | 519 | }, |
| 518 | - activate, | 520 | + if activate { |
| 521 | + ActivateWindow::Yes | ||
| 522 | + } else { | ||
| 523 | + ActivateWindow::No | ||
| 524 | + }, | ||
| 519 | removed.width, | 525 | removed.width, |
| 520 | removed.is_full_width, | 526 | removed.is_full_width, |
| 521 | removed.is_floating, | 527 | removed.is_floating, |
| @@ -578,7 +584,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 578 | 584 | ||
| 579 | let workspace = &mut self.workspaces[source_workspace_idx]; | 585 | let workspace = &mut self.workspaces[source_workspace_idx]; |
| 580 | if workspace.floating_is_active() { | 586 | if workspace.floating_is_active() { |
| 581 | - self.move_to_workspace(None, idx); | 587 | + self.move_to_workspace(None, idx, ActivateWindow::Smart); |
| 582 | return; | 588 | return; |
| 583 | } | 589 | } |
| 584 | 590 | ||
src/layout/tests.rsmodified+1 -1
| @@ -1063,7 +1063,7 @@ impl Op { | |||
| 1063 | workspace_idx, | 1063 | workspace_idx, |
| 1064 | } => { | 1064 | } => { |
| 1065 | let window_id = window_id.filter(|id| layout.has_window(id)); | 1065 | let window_id = window_id.filter(|id| layout.has_window(id)); |
| 1066 | - layout.move_to_workspace(window_id.as_ref(), workspace_idx); | 1066 | + layout.move_to_workspace(window_id.as_ref(), workspace_idx, ActivateWindow::Smart); |
| 1067 | } | 1067 | } |
| 1068 | Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), | 1068 | Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), |
| 1069 | Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(), | 1069 | Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(), |