layout: Add Column::position
Browse files at this commitc048abc8b50dc7fa79c117518d510059717aa356Parent: 4dd75782 changed files +9 -10
- src/layout/mod.rs +2 -2
- src/layout/workspace.rs +7 -8
src/layout/mod.rsmodified+2 -2
| @@ -518,7 +518,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 518 | for mon in monitors { | 518 | for mon in monitors { |
| 519 | for ws in &mon.workspaces { | 519 | for ws in &mon.workspaces { |
| 520 | for col in &ws.columns { | 520 | for col in &ws.columns { |
| 521 | - if let Some(idx) = col.windows.iter().position(|w| w == window) { | 521 | + if let Some(idx) = col.position(window) { |
| 522 | return Some(col.window_y(idx)); | 522 | return Some(col.window_y(idx)); |
| 523 | } | 523 | } |
| 524 | } | 524 | } |
| @@ -528,7 +528,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 528 | MonitorSet::NoOutputs { workspaces, .. } => { | 528 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 529 | for ws in workspaces { | 529 | for ws in workspaces { |
| 530 | for col in &ws.columns { | 530 | for col in &ws.columns { |
| 531 | - if let Some(idx) = col.windows.iter().position(|w| w == window) { | 531 | + if let Some(idx) = col.position(window) { |
| 532 | return Some(col.window_y(idx)); | 532 | return Some(col.window_y(idx)); |
| 533 | } | 533 | } |
| 534 | } | 534 | } |
src/layout/workspace.rsmodified+7 -8
| @@ -529,7 +529,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 529 | .unwrap(); | 529 | .unwrap(); |
| 530 | let column = &self.columns[column_idx]; | 530 | let column = &self.columns[column_idx]; |
| 531 | 531 | ||
| 532 | - let window_idx = column.windows.iter().position(|win| win == window).unwrap(); | 532 | + let window_idx = column.position(window).unwrap(); |
| 533 | self.remove_window_by_idx(column_idx, window_idx); | 533 | self.remove_window_by_idx(column_idx, window_idx); |
| 534 | } | 534 | } |
| 535 | 535 | ||
| @@ -809,12 +809,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 809 | .columns | 809 | .columns |
| 810 | .iter() | 810 | .iter() |
| 811 | .enumerate() | 811 | .enumerate() |
| 812 | - .find_map(|(col_idx, col)| { | 812 | + .find_map(|(col_idx, col)| col.position(window).map(|win_idx| (col_idx, win_idx))) |
| 813 | - col.windows | ||
| 814 | - .iter() | ||
| 815 | - .position(|w| w == window) | ||
| 816 | - .map(|win_idx| (col_idx, win_idx)) | ||
| 817 | - }) | ||
| 818 | .unwrap(); | 813 | .unwrap(); |
| 819 | 814 | ||
| 820 | let mut col = &mut self.columns[col_idx]; | 815 | let mut col = &mut self.columns[col_idx]; |
| @@ -1027,8 +1022,12 @@ impl<W: LayoutElement> Column<W> { | |||
| 1027 | self.windows.iter().any(|win| win == window) | 1022 | self.windows.iter().any(|win| win == window) |
| 1028 | } | 1023 | } |
| 1029 | 1024 | ||
| 1025 | + pub fn position(&self, window: &W) -> Option<usize> { | ||
| 1026 | + self.windows.iter().position(|win| win == window) | ||
| 1027 | + } | ||
| 1028 | + | ||
| 1030 | fn activate_window(&mut self, window: &W) { | 1029 | fn activate_window(&mut self, window: &W) { |
| 1031 | - let idx = self.windows.iter().position(|win| win == window).unwrap(); | 1030 | + let idx = self.position(window).unwrap(); |
| 1032 | self.active_window_idx = idx; | 1031 | self.active_window_idx = idx; |
| 1033 | } | 1032 | } |
| 1034 | 1033 | ||