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/scrolling.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/scrolling.rs')
| -rw-r--r-- | src/layout/scrolling.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs index a378c461..6fa6fbfc 100644 --- a/src/layout/scrolling.rs +++ b/src/layout/scrolling.rs @@ -1747,6 +1747,28 @@ impl<W: LayoutElement> ScrollingSpace<W> { cancel_resize_for_column(&mut self.interactive_resize, col); } + pub fn center_window(&mut self, window: Option<&W::Id>) { + if self.columns.is_empty() { + return; + } + + let col_idx = if let Some(window) = window { + self.columns + .iter() + .position(|col| col.contains(window)) + .unwrap() + } else { + self.active_column_idx + }; + + // We can reasonably center only the active column. + if col_idx != self.active_column_idx { + return; + } + + self.center_column(); + } + pub fn view_pos(&self) -> f64 { self.column_x(self.active_column_idx) + self.view_offset.current() } |
