diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-12-26 10:29:00 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-12-26 10:29:00 +0400 |
| commit | c048abc8b50dc7fa79c117518d510059717aa356 (patch) | |
| tree | 7ebcd1183566fe58215871e1409bc6be208cbc0f | |
| parent | 4dd7578fe7c55e4b3154b212d757632d173c76c2 (diff) | |
| download | niri-c048abc8b50dc7fa79c117518d510059717aa356.tar.gz niri-c048abc8b50dc7fa79c117518d510059717aa356.tar.bz2 niri-c048abc8b50dc7fa79c117518d510059717aa356.zip | |
layout: Add Column::position
| -rw-r--r-- | src/layout/mod.rs | 4 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 15 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 0514e12c..79c7cd19 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -518,7 +518,7 @@ impl<W: LayoutElement> Layout<W> { for mon in monitors { for ws in &mon.workspaces { for col in &ws.columns { - if let Some(idx) = col.windows.iter().position(|w| w == window) { + if let Some(idx) = col.position(window) { return Some(col.window_y(idx)); } } @@ -528,7 +528,7 @@ impl<W: LayoutElement> Layout<W> { MonitorSet::NoOutputs { workspaces, .. } => { for ws in workspaces { for col in &ws.columns { - if let Some(idx) = col.windows.iter().position(|w| w == window) { + if let Some(idx) = col.position(window) { return Some(col.window_y(idx)); } } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 8d5d8f88..3e5f3c8f 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -529,7 +529,7 @@ impl<W: LayoutElement> Workspace<W> { .unwrap(); let column = &self.columns[column_idx]; - let window_idx = column.windows.iter().position(|win| win == window).unwrap(); + let window_idx = column.position(window).unwrap(); self.remove_window_by_idx(column_idx, window_idx); } @@ -809,12 +809,7 @@ impl<W: LayoutElement> Workspace<W> { .columns .iter() .enumerate() - .find_map(|(col_idx, col)| { - col.windows - .iter() - .position(|w| w == window) - .map(|win_idx| (col_idx, win_idx)) - }) + .find_map(|(col_idx, col)| col.position(window).map(|win_idx| (col_idx, win_idx))) .unwrap(); let mut col = &mut self.columns[col_idx]; @@ -1027,8 +1022,12 @@ impl<W: LayoutElement> Column<W> { self.windows.iter().any(|win| win == window) } + pub fn position(&self, window: &W) -> Option<usize> { + self.windows.iter().position(|win| win == window) + } + fn activate_window(&mut self, window: &W) { - let idx = self.windows.iter().position(|win| win == window).unwrap(); + let idx = self.position(window).unwrap(); self.active_window_idx = idx; } |
