Add move-window-to-floating/tiling actions
Browse files at this commitad50dd21fea1912b9e21fb66a22fce517dac3aeeParent: 8b0cb0b5 changed files +104 -0
- niri-config/src/lib.rs +14 -0
- niri-ipc/src/lib.rs +16 -0
- src/input/mod.rs +28 -0
- src/layout/mod.rs +35 -0
- src/layout/workspace.rs +11 -0
niri-config/src/lib.rsmodified+14 -0
| @@ -1271,6 +1271,12 @@ pub enum Action { | |||
| 1271 | ToggleWindowFloating, | 1271 | ToggleWindowFloating, |
| 1272 | #[knuffel(skip)] | 1272 | #[knuffel(skip)] |
| 1273 | ToggleWindowFloatingById(u64), | 1273 | ToggleWindowFloatingById(u64), |
| 1274 | + MoveWindowToFloating, | ||
| 1275 | + #[knuffel(skip)] | ||
| 1276 | + MoveWindowToFloatingById(u64), | ||
| 1277 | + MoveWindowToTiling, | ||
| 1278 | + #[knuffel(skip)] | ||
| 1279 | + MoveWindowToTilingById(u64), | ||
| 1274 | SwitchFocusBetweenFloatingAndTiling, | 1280 | SwitchFocusBetweenFloatingAndTiling, |
| 1275 | } | 1281 | } |
| 1276 | 1282 | ||
| @@ -1413,6 +1419,14 @@ impl From<niri_ipc::Action> for Action { | |||
| 1413 | niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => { | 1419 | niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => { |
| 1414 | Self::ToggleWindowFloatingById(id) | 1420 | Self::ToggleWindowFloatingById(id) |
| 1415 | } | 1421 | } |
| 1422 | + niri_ipc::Action::MoveWindowToFloating { id: None } => Self::MoveWindowToFloating, | ||
| 1423 | + niri_ipc::Action::MoveWindowToFloating { id: Some(id) } => { | ||
| 1424 | + Self::MoveWindowToFloatingById(id) | ||
| 1425 | + } | ||
| 1426 | + niri_ipc::Action::MoveWindowToTiling { id: None } => Self::MoveWindowToTiling, | ||
| 1427 | + niri_ipc::Action::MoveWindowToTiling { id: Some(id) } => { | ||
| 1428 | + Self::MoveWindowToTilingById(id) | ||
| 1429 | + } | ||
| 1416 | niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => { | 1430 | niri_ipc::Action::SwitchFocusBetweenFloatingAndTiling {} => { |
| 1417 | Self::SwitchFocusBetweenFloatingAndTiling | 1431 | Self::SwitchFocusBetweenFloatingAndTiling |
| 1418 | } | 1432 | } |
niri-ipc/src/lib.rsmodified+16 -0
| @@ -454,6 +454,22 @@ pub enum Action { | |||
| 454 | #[cfg_attr(feature = "clap", arg(long))] | 454 | #[cfg_attr(feature = "clap", arg(long))] |
| 455 | id: Option<u64>, | 455 | id: Option<u64>, |
| 456 | }, | 456 | }, |
| 457 | + /// Move the focused window to the floating layout. | ||
| 458 | + MoveWindowToFloating { | ||
| 459 | + /// Id of the window to move. | ||
| 460 | + /// | ||
| 461 | + /// If `None`, uses the focused window. | ||
| 462 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 463 | + id: Option<u64>, | ||
| 464 | + }, | ||
| 465 | + /// Move the focused window to the tiling layout. | ||
| 466 | + MoveWindowToTiling { | ||
| 467 | + /// Id of the window to move. | ||
| 468 | + /// | ||
| 469 | + /// If `None`, uses the focused window. | ||
| 470 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 471 | + id: Option<u64>, | ||
| 472 | + }, | ||
| 457 | /// Toggles the focus between the floating and the tiling layout. | 473 | /// Toggles the focus between the floating and the tiling layout. |
| 458 | SwitchFocusBetweenFloatingAndTiling {}, | 474 | SwitchFocusBetweenFloatingAndTiling {}, |
| 459 | } | 475 | } |
src/input/mod.rsmodified+28 -0
| @@ -1318,6 +1318,34 @@ impl State { | |||
| 1318 | self.niri.queue_redraw_all(); | 1318 | self.niri.queue_redraw_all(); |
| 1319 | } | 1319 | } |
| 1320 | } | 1320 | } |
| 1321 | + Action::MoveWindowToFloating => { | ||
| 1322 | + self.niri.layout.set_window_floating(None, true); | ||
| 1323 | + // FIXME: granular | ||
| 1324 | + self.niri.queue_redraw_all(); | ||
| 1325 | + } | ||
| 1326 | + Action::MoveWindowToFloatingById(id) => { | ||
| 1327 | + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | ||
| 1328 | + let window = window.map(|(_, m)| m.window.clone()); | ||
| 1329 | + if let Some(window) = window { | ||
| 1330 | + self.niri.layout.set_window_floating(Some(&window), true); | ||
| 1331 | + // FIXME: granular | ||
| 1332 | + self.niri.queue_redraw_all(); | ||
| 1333 | + } | ||
| 1334 | + } | ||
| 1335 | + Action::MoveWindowToTiling => { | ||
| 1336 | + self.niri.layout.set_window_floating(None, false); | ||
| 1337 | + // FIXME: granular | ||
| 1338 | + self.niri.queue_redraw_all(); | ||
| 1339 | + } | ||
| 1340 | + Action::MoveWindowToTilingById(id) => { | ||
| 1341 | + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | ||
| 1342 | + let window = window.map(|(_, m)| m.window.clone()); | ||
| 1343 | + if let Some(window) = window { | ||
| 1344 | + self.niri.layout.set_window_floating(Some(&window), false); | ||
| 1345 | + // FIXME: granular | ||
| 1346 | + self.niri.queue_redraw_all(); | ||
| 1347 | + } | ||
| 1348 | + } | ||
| 1321 | Action::SwitchFocusBetweenFloatingAndTiling => { | 1349 | Action::SwitchFocusBetweenFloatingAndTiling => { |
| 1322 | self.niri.layout.switch_focus_floating_tiling(); | 1350 | self.niri.layout.switch_focus_floating_tiling(); |
| 1323 | // FIXME: granular | 1351 | // FIXME: granular |
src/layout/mod.rsmodified+35 -0
| @@ -2703,6 +2703,32 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2703 | workspace.toggle_window_floating(window); | 2703 | workspace.toggle_window_floating(window); |
| 2704 | } | 2704 | } |
| 2705 | 2705 | ||
| 2706 | + pub fn set_window_floating(&mut self, window: Option<&W::Id>, floating: bool) { | ||
| 2707 | + if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | ||
| 2708 | + if window.is_none() || window == Some(move_.tile.window().id()) { | ||
| 2709 | + if move_.is_floating != floating { | ||
| 2710 | + self.toggle_window_floating(window); | ||
| 2711 | + } | ||
| 2712 | + return; | ||
| 2713 | + } | ||
| 2714 | + } | ||
| 2715 | + | ||
| 2716 | + let workspace = if let Some(window) = window { | ||
| 2717 | + Some( | ||
| 2718 | + self.workspaces_mut() | ||
| 2719 | + .find(|ws| ws.has_window(window)) | ||
| 2720 | + .unwrap(), | ||
| 2721 | + ) | ||
| 2722 | + } else { | ||
| 2723 | + self.active_workspace_mut() | ||
| 2724 | + }; | ||
| 2725 | + | ||
| 2726 | + let Some(workspace) = workspace else { | ||
| 2727 | + return; | ||
| 2728 | + }; | ||
| 2729 | + workspace.set_window_floating(window, floating); | ||
| 2730 | + } | ||
| 2731 | + | ||
| 2706 | pub fn switch_focus_floating_tiling(&mut self) { | 2732 | pub fn switch_focus_floating_tiling(&mut self) { |
| 2707 | let Some(workspace) = self.active_workspace_mut() else { | 2733 | let Some(workspace) = self.active_workspace_mut() else { |
| 2708 | return; | 2734 | return; |
| @@ -4362,6 +4388,11 @@ mod tests { | |||
| 4362 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] | 4388 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] |
| 4363 | id: Option<usize>, | 4389 | id: Option<usize>, |
| 4364 | }, | 4390 | }, |
| 4391 | + SetWindowFloating { | ||
| 4392 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | ||
| 4393 | + id: Option<usize>, | ||
| 4394 | + floating: bool, | ||
| 4395 | + }, | ||
| 4365 | SwitchFocusFloatingTiling, | 4396 | SwitchFocusFloatingTiling, |
| 4366 | SetParent { | 4397 | SetParent { |
| 4367 | #[proptest(strategy = "1..=5usize")] | 4398 | #[proptest(strategy = "1..=5usize")] |
| @@ -4874,6 +4905,10 @@ mod tests { | |||
| 4874 | let id = id.filter(|id| layout.has_window(id)); | 4905 | let id = id.filter(|id| layout.has_window(id)); |
| 4875 | layout.toggle_window_floating(id.as_ref()); | 4906 | layout.toggle_window_floating(id.as_ref()); |
| 4876 | } | 4907 | } |
| 4908 | + Op::SetWindowFloating { id, floating } => { | ||
| 4909 | + let id = id.filter(|id| layout.has_window(id)); | ||
| 4910 | + layout.set_window_floating(id.as_ref(), floating); | ||
| 4911 | + } | ||
| 4877 | Op::SwitchFocusFloatingTiling => { | 4912 | Op::SwitchFocusFloatingTiling => { |
| 4878 | layout.switch_focus_floating_tiling(); | 4913 | layout.switch_focus_floating_tiling(); |
| 4879 | } | 4914 | } |
src/layout/workspace.rsmodified+11 -0
| @@ -1146,6 +1146,17 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1146 | tile.animate_move_from(render_pos - new_render_pos); | 1146 | tile.animate_move_from(render_pos - new_render_pos); |
| 1147 | } | 1147 | } |
| 1148 | 1148 | ||
| 1149 | + pub fn set_window_floating(&mut self, id: Option<&W::Id>, floating: bool) { | ||
| 1150 | + if id.map_or(self.floating_is_active.get(), |id| { | ||
| 1151 | + self.floating.has_window(id) | ||
| 1152 | + }) == floating | ||
| 1153 | + { | ||
| 1154 | + return; | ||
| 1155 | + } | ||
| 1156 | + | ||
| 1157 | + self.toggle_window_floating(id); | ||
| 1158 | + } | ||
| 1159 | + | ||
| 1149 | pub fn switch_focus_floating_tiling(&mut self) { | 1160 | pub fn switch_focus_floating_tiling(&mut self) { |
| 1150 | if self.floating.is_empty() { | 1161 | if self.floating.is_empty() { |
| 1151 | // If floating is empty, keep focus on scrolling. | 1162 | // If floating is empty, keep focus on scrolling. |