Add SwitchPresetWindowHeight by id
Browse files at this commitc3cb42f04d065c0e481ca66ae2a3edce7c5aac74Parent: d0e624e6 changed files +62 -17
- niri-config/src/lib.rs +8 -1
- niri-ipc/src/lib.rs +7 -1
- src/input/mod.rs +8 -1
- src/layout/mod.rs +23 -7
- src/layout/monitor.rs +0 -4
- src/layout/workspace.rs +16 -3
niri-config/src/lib.rsmodified+8 -1
| @@ -1159,6 +1159,8 @@ pub enum Action { | |||
| 1159 | ResetWindowHeightById(u64), | 1159 | ResetWindowHeightById(u64), |
| 1160 | SwitchPresetColumnWidth, | 1160 | SwitchPresetColumnWidth, |
| 1161 | SwitchPresetWindowHeight, | 1161 | SwitchPresetWindowHeight, |
| 1162 | + #[knuffel(skip)] | ||
| 1163 | + SwitchPresetWindowHeightById(u64), | ||
| 1162 | MaximizeColumn, | 1164 | MaximizeColumn, |
| 1163 | SetColumnWidth(#[knuffel(argument, str)] SizeChange), | 1165 | SetColumnWidth(#[knuffel(argument, str)] SizeChange), |
| 1164 | SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget), | 1166 | SwitchLayout(#[knuffel(argument, str)] LayoutSwitchTarget), |
| @@ -1270,7 +1272,12 @@ impl From<niri_ipc::Action> for Action { | |||
| 1270 | niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, | 1272 | niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, |
| 1271 | niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), | 1273 | niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), |
| 1272 | niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, | 1274 | niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, |
| 1273 | - niri_ipc::Action::SwitchPresetWindowHeight {} => Self::SwitchPresetWindowHeight, | 1275 | + niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { |
| 1276 | + Self::SwitchPresetWindowHeight | ||
| 1277 | + } | ||
| 1278 | + niri_ipc::Action::SwitchPresetWindowHeight { id: Some(id) } => { | ||
| 1279 | + Self::SwitchPresetWindowHeightById(id) | ||
| 1280 | + } | ||
| 1274 | niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn, | 1281 | niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn, |
| 1275 | niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change), | 1282 | niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change), |
| 1276 | niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout), | 1283 | niri_ipc::Action::SwitchLayout { layout } => Self::SwitchLayout(layout), |
niri-ipc/src/lib.rsmodified+7 -1
| @@ -351,7 +351,13 @@ pub enum Action { | |||
| 351 | /// Switch between preset column widths. | 351 | /// Switch between preset column widths. |
| 352 | SwitchPresetColumnWidth {}, | 352 | SwitchPresetColumnWidth {}, |
| 353 | /// Switch between preset window heights. | 353 | /// Switch between preset window heights. |
| 354 | - SwitchPresetWindowHeight {}, | 354 | + SwitchPresetWindowHeight { |
| 355 | + /// Id of the window whose height to switch. | ||
| 356 | + /// | ||
| 357 | + /// If `None`, uses the focused window. | ||
| 358 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 359 | + id: Option<u64>, | ||
| 360 | + }, | ||
| 355 | /// Toggle the maximized state of the focused column. | 361 | /// Toggle the maximized state of the focused column. |
| 356 | MaximizeColumn {}, | 362 | MaximizeColumn {}, |
| 357 | /// Change the width of the focused column. | 363 | /// Change the width of the focused column. |
src/input/mod.rsmodified+8 -1
| @@ -1036,7 +1036,14 @@ impl State { | |||
| 1036 | self.niri.layout.toggle_width(); | 1036 | self.niri.layout.toggle_width(); |
| 1037 | } | 1037 | } |
| 1038 | Action::SwitchPresetWindowHeight => { | 1038 | Action::SwitchPresetWindowHeight => { |
| 1039 | - self.niri.layout.toggle_window_height(); | 1039 | + self.niri.layout.toggle_window_height(None); |
| 1040 | + } | ||
| 1041 | + Action::SwitchPresetWindowHeightById(id) => { | ||
| 1042 | + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | ||
| 1043 | + let window = window.map(|(_, m)| m.window.clone()); | ||
| 1044 | + if let Some(window) = window { | ||
| 1045 | + self.niri.layout.toggle_window_height(Some(&window)); | ||
| 1046 | + } | ||
| 1040 | } | 1047 | } |
| 1041 | Action::CenterColumn => { | 1048 | Action::CenterColumn => { |
| 1042 | self.niri.layout.center_column(); | 1049 | self.niri.layout.center_column(); |
src/layout/mod.rsmodified+23 -7
| @@ -1951,11 +1951,21 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1951 | monitor.toggle_width(); | 1951 | monitor.toggle_width(); |
| 1952 | } | 1952 | } |
| 1953 | 1953 | ||
| 1954 | - pub fn toggle_window_height(&mut self) { | 1954 | + pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { |
| 1955 | - let Some(monitor) = self.active_monitor() else { | 1955 | + let workspace = if let Some(window) = window { |
| 1956 | + Some( | ||
| 1957 | + self.workspaces_mut() | ||
| 1958 | + .find(|ws| ws.has_window(window)) | ||
| 1959 | + .unwrap(), | ||
| 1960 | + ) | ||
| 1961 | + } else { | ||
| 1962 | + self.active_workspace_mut() | ||
| 1963 | + }; | ||
| 1964 | + | ||
| 1965 | + let Some(workspace) = workspace else { | ||
| 1956 | return; | 1966 | return; |
| 1957 | }; | 1967 | }; |
| 1958 | - monitor.toggle_window_height(); | 1968 | + workspace.toggle_window_height(window); |
| 1959 | } | 1969 | } |
| 1960 | 1970 | ||
| 1961 | pub fn toggle_full_width(&mut self) { | 1971 | pub fn toggle_full_width(&mut self) { |
| @@ -3048,7 +3058,10 @@ mod tests { | |||
| 3048 | }, | 3058 | }, |
| 3049 | MoveColumnToOutput(#[proptest(strategy = "1..=5u8")] u8), | 3059 | MoveColumnToOutput(#[proptest(strategy = "1..=5u8")] u8), |
| 3050 | SwitchPresetColumnWidth, | 3060 | SwitchPresetColumnWidth, |
| 3051 | - SwitchPresetWindowHeight, | 3061 | + SwitchPresetWindowHeight { |
| 3062 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | ||
| 3063 | + id: Option<usize>, | ||
| 3064 | + }, | ||
| 3052 | MaximizeColumn, | 3065 | MaximizeColumn, |
| 3053 | SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange), | 3066 | SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange), |
| 3054 | SetWindowHeight { | 3067 | SetWindowHeight { |
| @@ -3475,7 +3488,10 @@ mod tests { | |||
| 3475 | Op::MoveWorkspaceDown => layout.move_workspace_down(), | 3488 | Op::MoveWorkspaceDown => layout.move_workspace_down(), |
| 3476 | Op::MoveWorkspaceUp => layout.move_workspace_up(), | 3489 | Op::MoveWorkspaceUp => layout.move_workspace_up(), |
| 3477 | Op::SwitchPresetColumnWidth => layout.toggle_width(), | 3490 | Op::SwitchPresetColumnWidth => layout.toggle_width(), |
| 3478 | - Op::SwitchPresetWindowHeight => layout.toggle_window_height(), | 3491 | + Op::SwitchPresetWindowHeight { id } => { |
| 3492 | + let id = id.filter(|id| layout.has_window(id)); | ||
| 3493 | + layout.toggle_window_height(id.as_ref()); | ||
| 3494 | + } | ||
| 3479 | Op::MaximizeColumn => layout.toggle_full_width(), | 3495 | Op::MaximizeColumn => layout.toggle_full_width(), |
| 3480 | Op::SetColumnWidth(change) => layout.set_column_width(change), | 3496 | Op::SetColumnWidth(change) => layout.set_column_width(change), |
| 3481 | Op::SetWindowHeight { id, change } => { | 3497 | Op::SetWindowHeight { id, change } => { |
| @@ -4458,8 +4474,8 @@ mod tests { | |||
| 4458 | min_max_size: Default::default(), | 4474 | min_max_size: Default::default(), |
| 4459 | }, | 4475 | }, |
| 4460 | Op::ConsumeOrExpelWindowLeft, | 4476 | Op::ConsumeOrExpelWindowLeft, |
| 4461 | - Op::SwitchPresetWindowHeight, | 4477 | + Op::SwitchPresetWindowHeight { id: None }, |
| 4462 | - Op::SwitchPresetWindowHeight, | 4478 | + Op::SwitchPresetWindowHeight { id: None }, |
| 4463 | ]; | 4479 | ]; |
| 4464 | for op in ops { | 4480 | for op in ops { |
| 4465 | op.apply(&mut layout); | 4481 | op.apply(&mut layout); |
src/layout/monitor.rsmodified+0 -4
| @@ -740,10 +740,6 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 740 | self.active_workspace().toggle_width(); | 740 | self.active_workspace().toggle_width(); |
| 741 | } | 741 | } |
| 742 | 742 | ||
| 743 | - pub fn toggle_window_height(&mut self) { | ||
| 744 | - self.active_workspace().toggle_window_height(); | ||
| 745 | - } | ||
| 746 | - | ||
| 747 | pub fn toggle_full_width(&mut self) { | 743 | pub fn toggle_full_width(&mut self) { |
| 748 | self.active_workspace().toggle_full_width(); | 744 | self.active_workspace().toggle_full_width(); |
| 749 | } | 745 | } |
src/layout/workspace.rsmodified+16 -3
| @@ -2373,13 +2373,26 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2373 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2373 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2374 | } | 2374 | } |
| 2375 | 2375 | ||
| 2376 | - pub fn toggle_window_height(&mut self) { | 2376 | + pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { |
| 2377 | if self.columns.is_empty() { | 2377 | if self.columns.is_empty() { |
| 2378 | return; | 2378 | return; |
| 2379 | } | 2379 | } |
| 2380 | 2380 | ||
| 2381 | - let col = &mut self.columns[self.active_column_idx]; | 2381 | + let (col, tile_idx) = if let Some(window) = window { |
| 2382 | - col.toggle_window_height(None, true); | 2382 | + self.columns |
| 2383 | + .iter_mut() | ||
| 2384 | + .find_map(|col| { | ||
| 2385 | + col.tiles | ||
| 2386 | + .iter() | ||
| 2387 | + .position(|tile| tile.window().id() == window) | ||
| 2388 | + .map(|tile_idx| (col, Some(tile_idx))) | ||
| 2389 | + }) | ||
| 2390 | + .unwrap() | ||
| 2391 | + } else { | ||
| 2392 | + (&mut self.columns[self.active_column_idx], None) | ||
| 2393 | + }; | ||
| 2394 | + | ||
| 2395 | + col.toggle_window_height(tile_idx, true); | ||
| 2383 | 2396 | ||
| 2384 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2397 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2385 | } | 2398 | } |