Add toggle-window-width by-id action
Browse files at this commita7c57f4fafabed609ef75b92715beb4e7335d823Parent: 84091076 changed files +87 -0
- niri-config/src/lib.rs +7 -0
- niri-ipc/src/lib.rs +8 -0
- src/input/mod.rs +10 -0
- src/layout/mod.rs +31 -0
- src/layout/scrolling.rs +21 -0
- src/layout/workspace.rs +10 -0
niri-config/src/lib.rsmodified+7 -0
| @@ -1273,6 +1273,9 @@ pub enum Action { | |||
| 1273 | #[knuffel(skip)] | 1273 | #[knuffel(skip)] |
| 1274 | ResetWindowHeightById(u64), | 1274 | ResetWindowHeightById(u64), |
| 1275 | SwitchPresetColumnWidth, | 1275 | SwitchPresetColumnWidth, |
| 1276 | + SwitchPresetWindowWidth, | ||
| 1277 | + #[knuffel(skip)] | ||
| 1278 | + SwitchPresetWindowWidthById(u64), | ||
| 1276 | SwitchPresetWindowHeight, | 1279 | SwitchPresetWindowHeight, |
| 1277 | #[knuffel(skip)] | 1280 | #[knuffel(skip)] |
| 1278 | SwitchPresetWindowHeightById(u64), | 1281 | SwitchPresetWindowHeightById(u64), |
| @@ -1424,6 +1427,10 @@ impl From<niri_ipc::Action> for Action { | |||
| 1424 | niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, | 1427 | niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, |
| 1425 | niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), | 1428 | niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), |
| 1426 | niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, | 1429 | niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, |
| 1430 | + niri_ipc::Action::SwitchPresetWindowWidth { id: None } => Self::SwitchPresetWindowWidth, | ||
| 1431 | + niri_ipc::Action::SwitchPresetWindowWidth { id: Some(id) } => { | ||
| 1432 | + Self::SwitchPresetWindowWidthById(id) | ||
| 1433 | + } | ||
| 1427 | niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { | 1434 | niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { |
| 1428 | Self::SwitchPresetWindowHeight | 1435 | Self::SwitchPresetWindowHeight |
| 1429 | } | 1436 | } |
niri-ipc/src/lib.rsmodified+8 -0
| @@ -420,6 +420,14 @@ pub enum Action { | |||
| 420 | }, | 420 | }, |
| 421 | /// Switch between preset column widths. | 421 | /// Switch between preset column widths. |
| 422 | SwitchPresetColumnWidth {}, | 422 | SwitchPresetColumnWidth {}, |
| 423 | + /// Switch between preset window widths. | ||
| 424 | + SwitchPresetWindowWidth { | ||
| 425 | + /// Id of the window whose width to switch. | ||
| 426 | + /// | ||
| 427 | + /// If `None`, uses the focused window. | ||
| 428 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 429 | + id: Option<u64>, | ||
| 430 | + }, | ||
| 423 | /// Switch between preset window heights. | 431 | /// Switch between preset window heights. |
| 424 | SwitchPresetWindowHeight { | 432 | SwitchPresetWindowHeight { |
| 425 | /// Id of the window whose height to switch. | 433 | /// Id of the window whose height to switch. |
src/input/mod.rsmodified+10 -0
| @@ -1112,6 +1112,16 @@ impl State { | |||
| 1112 | Action::SwitchPresetColumnWidth => { | 1112 | Action::SwitchPresetColumnWidth => { |
| 1113 | self.niri.layout.toggle_width(); | 1113 | self.niri.layout.toggle_width(); |
| 1114 | } | 1114 | } |
| 1115 | + Action::SwitchPresetWindowWidth => { | ||
| 1116 | + self.niri.layout.toggle_window_width(None); | ||
| 1117 | + } | ||
| 1118 | + Action::SwitchPresetWindowWidthById(id) => { | ||
| 1119 | + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | ||
| 1120 | + let window = window.map(|(_, m)| m.window.clone()); | ||
| 1121 | + if let Some(window) = window { | ||
| 1122 | + self.niri.layout.toggle_window_width(Some(&window)); | ||
| 1123 | + } | ||
| 1124 | + } | ||
| 1115 | Action::SwitchPresetWindowHeight => { | 1125 | Action::SwitchPresetWindowHeight => { |
| 1116 | self.niri.layout.toggle_window_height(None); | 1126 | self.niri.layout.toggle_window_height(None); |
| 1117 | } | 1127 | } |
src/layout/mod.rsmodified+31 -0
| @@ -2607,6 +2607,29 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2607 | monitor.toggle_width(); | 2607 | monitor.toggle_width(); |
| 2608 | } | 2608 | } |
| 2609 | 2609 | ||
| 2610 | + pub fn toggle_window_width(&mut self, window: Option<&W::Id>) { | ||
| 2611 | + if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | ||
| 2612 | + if window.is_none() || window == Some(move_.tile.window().id()) { | ||
| 2613 | + return; | ||
| 2614 | + } | ||
| 2615 | + } | ||
| 2616 | + | ||
| 2617 | + let workspace = if let Some(window) = window { | ||
| 2618 | + Some( | ||
| 2619 | + self.workspaces_mut() | ||
| 2620 | + .find(|ws| ws.has_window(window)) | ||
| 2621 | + .unwrap(), | ||
| 2622 | + ) | ||
| 2623 | + } else { | ||
| 2624 | + self.active_workspace_mut() | ||
| 2625 | + }; | ||
| 2626 | + | ||
| 2627 | + let Some(workspace) = workspace else { | ||
| 2628 | + return; | ||
| 2629 | + }; | ||
| 2630 | + workspace.toggle_window_width(window); | ||
| 2631 | + } | ||
| 2632 | + | ||
| 2610 | pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { | 2633 | pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { |
| 2611 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 2634 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2612 | if window.is_none() || window == Some(move_.tile.window().id()) { | 2635 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| @@ -4474,6 +4497,10 @@ mod tests { | |||
| 4474 | }, | 4497 | }, |
| 4475 | MoveColumnToOutput(#[proptest(strategy = "1..=5usize")] usize), | 4498 | MoveColumnToOutput(#[proptest(strategy = "1..=5usize")] usize), |
| 4476 | SwitchPresetColumnWidth, | 4499 | SwitchPresetColumnWidth, |
| 4500 | + SwitchPresetWindowWidth { | ||
| 4501 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | ||
| 4502 | + id: Option<usize>, | ||
| 4503 | + }, | ||
| 4477 | SwitchPresetWindowHeight { | 4504 | SwitchPresetWindowHeight { |
| 4478 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] | 4505 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] |
| 4479 | id: Option<usize>, | 4506 | id: Option<usize>, |
| @@ -5009,6 +5036,10 @@ mod tests { | |||
| 5009 | Op::MoveWorkspaceDown => layout.move_workspace_down(), | 5036 | Op::MoveWorkspaceDown => layout.move_workspace_down(), |
| 5010 | Op::MoveWorkspaceUp => layout.move_workspace_up(), | 5037 | Op::MoveWorkspaceUp => layout.move_workspace_up(), |
| 5011 | Op::SwitchPresetColumnWidth => layout.toggle_width(), | 5038 | Op::SwitchPresetColumnWidth => layout.toggle_width(), |
| 5039 | + Op::SwitchPresetWindowWidth { id } => { | ||
| 5040 | + let id = id.filter(|id| layout.has_window(id)); | ||
| 5041 | + layout.toggle_window_width(id.as_ref()); | ||
| 5042 | + } | ||
| 5012 | Op::SwitchPresetWindowHeight { id } => { | 5043 | Op::SwitchPresetWindowHeight { id } => { |
| 5013 | let id = id.filter(|id| layout.has_window(id)); | 5044 | let id = id.filter(|id| layout.has_window(id)); |
| 5014 | layout.toggle_window_height(id.as_ref()); | 5045 | layout.toggle_window_height(id.as_ref()); |
src/layout/scrolling.rsmodified+21 -0
| @@ -2116,6 +2116,27 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2116 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2116 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2117 | } | 2117 | } |
| 2118 | 2118 | ||
| 2119 | + pub fn toggle_window_width(&mut self, window: Option<&W::Id>) { | ||
| 2120 | + if self.columns.is_empty() { | ||
| 2121 | + return; | ||
| 2122 | + } | ||
| 2123 | + | ||
| 2124 | + let col = if let Some(window) = window { | ||
| 2125 | + self.columns | ||
| 2126 | + .iter_mut() | ||
| 2127 | + .find(|col| col.contains(window)) | ||
| 2128 | + .unwrap() | ||
| 2129 | + } else { | ||
| 2130 | + &mut self.columns[self.active_column_idx] | ||
| 2131 | + }; | ||
| 2132 | + | ||
| 2133 | + // FIXME: when we fix preset fixed width to be per-window, this should also be made | ||
| 2134 | + // window-specific to resolve the correct window width. | ||
| 2135 | + col.toggle_width(); | ||
| 2136 | + | ||
| 2137 | + cancel_resize_for_column(&mut self.interactive_resize, col); | ||
| 2138 | + } | ||
| 2139 | + | ||
| 2119 | pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { | 2140 | pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { |
| 2120 | if self.columns.is_empty() { | 2141 | if self.columns.is_empty() { |
| 2121 | return; | 2142 | return; |
src/layout/workspace.rsmodified+10 -0
| @@ -1041,6 +1041,16 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1041 | self.scrolling.reset_window_height(window); | 1041 | self.scrolling.reset_window_height(window); |
| 1042 | } | 1042 | } |
| 1043 | 1043 | ||
| 1044 | + pub fn toggle_window_width(&mut self, window: Option<&W::Id>) { | ||
| 1045 | + if window.map_or(self.floating_is_active.get(), |id| { | ||
| 1046 | + self.floating.has_window(id) | ||
| 1047 | + }) { | ||
| 1048 | + self.floating.toggle_window_width(window); | ||
| 1049 | + } else { | ||
| 1050 | + self.scrolling.toggle_window_width(window); | ||
| 1051 | + } | ||
| 1052 | + } | ||
| 1053 | + | ||
| 1044 | pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { | 1054 | pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { |
| 1045 | if window.map_or(self.floating_is_active.get(), |id| { | 1055 | if window.map_or(self.floating_is_active.get(), |id| { |
| 1046 | self.floating.has_window(id) | 1056 | self.floating.has_window(id) |