diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-29 22:44:19 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-30 20:12:37 +0300 |
| commit | 6c897d520165bfcaf3833b6e3d4bdbd836d26063 (patch) | |
| tree | 29fa7697f53facfe8bca4d12cbff1cca7e9065e7 /src/layout/mod.rs | |
| parent | 6cb5135f3477e63ed1738e19ba95a07ce52093ae (diff) | |
| download | niri-6c897d520165bfcaf3833b6e3d4bdbd836d26063.tar.gz niri-6c897d520165bfcaf3833b6e3d4bdbd836d26063.tar.bz2 niri-6c897d520165bfcaf3833b6e3d4bdbd836d26063.zip | |
Add center-window by-id action
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 433cae43..571411fc 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1993,6 +1993,19 @@ impl<W: LayoutElement> Layout<W> { monitor.center_column(); } + pub fn center_window(&mut self, id: Option<&W::Id>) { + let workspace = if let Some(id) = id { + Some(self.workspaces_mut().find(|ws| ws.has_window(id)).unwrap()) + } else { + self.active_workspace_mut() + }; + + let Some(workspace) = workspace else { + return; + }; + workspace.center_window(id); + } + pub fn focus(&self) -> Option<&W> { self.focus_with_output().map(|(win, _out)| win) } @@ -4390,6 +4403,10 @@ mod tests { ConsumeWindowIntoColumn, ExpelWindowFromColumn, CenterColumn, + CenterWindow { + #[proptest(strategy = "proptest::option::of(1..=5usize)")] + id: Option<usize>, + }, FocusWorkspaceDown, FocusWorkspaceUp, FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize), @@ -4901,6 +4918,10 @@ mod tests { Op::ConsumeWindowIntoColumn => layout.consume_into_column(), Op::ExpelWindowFromColumn => layout.expel_from_column(), Op::CenterColumn => layout.center_column(), + Op::CenterWindow { id } => { + let id = id.filter(|id| layout.has_window(id)); + layout.center_window(id.as_ref()); + } Op::FocusWorkspaceDown => layout.switch_workspace_down(), Op::FocusWorkspaceUp => layout.switch_workspace_up(), Op::FocusWorkspace(idx) => layout.switch_workspace(idx), |
