Add and use remove_window_by_idx
Browse files at this commit489a225fae57adba01057893d244c64c749bccfeParent: 85cb4b43 changed files +35 -31
- src/layout/mod.rs +1 -2
- src/layout/monitor.rs +9 -9
- src/layout/workspace.rs +25 -20
src/layout/mod.rsmodified+1 -2
| @@ -1045,10 +1045,9 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1045 | return; | 1045 | return; |
| 1046 | } | 1046 | } |
| 1047 | let column = &ws.columns[ws.active_column_idx]; | 1047 | let column = &ws.columns[ws.active_column_idx]; |
| 1048 | - let window = column.windows[column.active_window_idx].clone(); | ||
| 1049 | let width = column.width; | 1048 | let width = column.width; |
| 1050 | let is_full_width = column.is_full_width; | 1049 | let is_full_width = column.is_full_width; |
| 1051 | - ws.remove_window(&window); | 1050 | + let window = ws.remove_window_by_idx(ws.active_column_idx, column.active_window_idx); |
| 1052 | 1051 | ||
| 1053 | let workspace_idx = monitors[new_idx].active_workspace_idx; | 1052 | let workspace_idx = monitors[new_idx].active_workspace_idx; |
| 1054 | self.add_window_by_idx(new_idx, workspace_idx, window, true, width, is_full_width); | 1053 | self.add_window_by_idx(new_idx, workspace_idx, window, true, width, is_full_width); |
src/layout/monitor.rsmodified+9 -9
| @@ -249,11 +249,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 249 | return; | 249 | return; |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | - let column = &mut workspace.columns[workspace.active_column_idx]; | 252 | + let column = &workspace.columns[workspace.active_column_idx]; |
| 253 | let width = column.width; | 253 | let width = column.width; |
| 254 | let is_full_width = column.is_full_width; | 254 | let is_full_width = column.is_full_width; |
| 255 | - let window = column.windows[column.active_window_idx].clone(); | 255 | + let window = |
| 256 | - workspace.remove_window(&window); | 256 | + workspace.remove_window_by_idx(workspace.active_column_idx, column.active_window_idx); |
| 257 | 257 | ||
| 258 | self.add_window(new_idx, window, true, width, is_full_width); | 258 | self.add_window(new_idx, window, true, width, is_full_width); |
| 259 | } | 259 | } |
| @@ -271,11 +271,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 271 | return; | 271 | return; |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | - let column = &mut workspace.columns[workspace.active_column_idx]; | 274 | + let column = &workspace.columns[workspace.active_column_idx]; |
| 275 | let width = column.width; | 275 | let width = column.width; |
| 276 | let is_full_width = column.is_full_width; | 276 | let is_full_width = column.is_full_width; |
| 277 | - let window = column.windows[column.active_window_idx].clone(); | 277 | + let window = |
| 278 | - workspace.remove_window(&window); | 278 | + workspace.remove_window_by_idx(workspace.active_column_idx, column.active_window_idx); |
| 279 | 279 | ||
| 280 | self.add_window(new_idx, window, true, width, is_full_width); | 280 | self.add_window(new_idx, window, true, width, is_full_width); |
| 281 | } | 281 | } |
| @@ -293,11 +293,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 293 | return; | 293 | return; |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | - let column = &mut workspace.columns[workspace.active_column_idx]; | 296 | + let column = &workspace.columns[workspace.active_column_idx]; |
| 297 | let width = column.width; | 297 | let width = column.width; |
| 298 | let is_full_width = column.is_full_width; | 298 | let is_full_width = column.is_full_width; |
| 299 | - let window = column.windows[column.active_window_idx].clone(); | 299 | + let window = |
| 300 | - workspace.remove_window(&window); | 300 | + workspace.remove_window_by_idx(workspace.active_column_idx, column.active_window_idx); |
| 301 | 301 | ||
| 302 | self.add_window(new_idx, window, true, width, is_full_width); | 302 | self.add_window(new_idx, window, true, width, is_full_width); |
| 303 | 303 | ||
src/layout/workspace.rsmodified+25 -20
| @@ -482,21 +482,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 482 | } | 482 | } |
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | - pub fn remove_window(&mut self, window: &W) { | 485 | + pub fn remove_window_by_idx(&mut self, column_idx: usize, window_idx: usize) -> W { |
| 486 | + let column = &mut self.columns[column_idx]; | ||
| 487 | + let window = column.windows.remove(window_idx); | ||
| 488 | + column.heights.remove(window_idx); | ||
| 489 | + | ||
| 486 | if let Some(output) = &self.output { | 490 | if let Some(output) = &self.output { |
| 487 | window.output_leave(output); | 491 | window.output_leave(output); |
| 488 | } | 492 | } |
| 489 | 493 | ||
| 490 | - let column_idx = self | ||
| 491 | - .columns | ||
| 492 | - .iter() | ||
| 493 | - .position(|col| col.contains(window)) | ||
| 494 | - .unwrap(); | ||
| 495 | - let column = &mut self.columns[column_idx]; | ||
| 496 | - | ||
| 497 | - let window_idx = column.windows.iter().position(|win| win == window).unwrap(); | ||
| 498 | - column.windows.remove(window_idx); | ||
| 499 | - column.heights.remove(window_idx); | ||
| 500 | if column.windows.is_empty() { | 494 | if column.windows.is_empty() { |
| 501 | if column_idx + 1 == self.active_column_idx { | 495 | if column_idx + 1 == self.active_column_idx { |
| 502 | // The previous column, that we were going to activate upon removal of the active | 496 | // The previous column, that we were going to activate upon removal of the active |
| @@ -509,7 +503,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 509 | // view jumps. | 503 | // view jumps. |
| 510 | self.columns.remove(column_idx); | 504 | self.columns.remove(column_idx); |
| 511 | if self.columns.is_empty() { | 505 | if self.columns.is_empty() { |
| 512 | - return; | 506 | + return window; |
| 513 | } | 507 | } |
| 514 | 508 | ||
| 515 | if self.active_column_idx > column_idx | 509 | if self.active_column_idx > column_idx |
| @@ -523,11 +517,25 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 523 | self.activate_column(min(self.active_column_idx, self.columns.len() - 1)); | 517 | self.activate_column(min(self.active_column_idx, self.columns.len() - 1)); |
| 524 | } | 518 | } |
| 525 | 519 | ||
| 526 | - return; | 520 | + return window; |
| 527 | } | 521 | } |
| 528 | 522 | ||
| 529 | column.active_window_idx = min(column.active_window_idx, column.windows.len() - 1); | 523 | column.active_window_idx = min(column.active_window_idx, column.windows.len() - 1); |
| 530 | column.update_window_sizes(); | 524 | column.update_window_sizes(); |
| 525 | + | ||
| 526 | + window | ||
| 527 | + } | ||
| 528 | + | ||
| 529 | + pub fn remove_window(&mut self, window: &W) { | ||
| 530 | + let column_idx = self | ||
| 531 | + .columns | ||
| 532 | + .iter() | ||
| 533 | + .position(|col| col.contains(window)) | ||
| 534 | + .unwrap(); | ||
| 535 | + let column = &self.columns[column_idx]; | ||
| 536 | + | ||
| 537 | + let window_idx = column.windows.iter().position(|win| win == window).unwrap(); | ||
| 538 | + self.remove_window_by_idx(column_idx, window_idx); | ||
| 531 | } | 539 | } |
| 532 | 540 | ||
| 533 | pub fn update_window(&mut self, window: &W) { | 541 | pub fn update_window(&mut self, window: &W) { |
| @@ -662,10 +670,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 662 | } | 670 | } |
| 663 | 671 | ||
| 664 | let source_column_idx = self.active_column_idx + 1; | 672 | let source_column_idx = self.active_column_idx + 1; |
| 665 | - | 673 | + let window = self.remove_window_by_idx(source_column_idx, 0); |
| 666 | - let source_column = &mut self.columns[source_column_idx]; | ||
| 667 | - let window = source_column.windows[0].clone(); | ||
| 668 | - self.remove_window(&window); | ||
| 669 | 674 | ||
| 670 | let target_column = &mut self.columns[self.active_column_idx]; | 675 | let target_column = &mut self.columns[self.active_column_idx]; |
| 671 | target_column.add_window(window); | 676 | target_column.add_window(window); |
| @@ -676,15 +681,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 676 | return; | 681 | return; |
| 677 | } | 682 | } |
| 678 | 683 | ||
| 679 | - let source_column = &mut self.columns[self.active_column_idx]; | 684 | + let source_column = &self.columns[self.active_column_idx]; |
| 680 | if source_column.windows.len() == 1 { | 685 | if source_column.windows.len() == 1 { |
| 681 | return; | 686 | return; |
| 682 | } | 687 | } |
| 683 | 688 | ||
| 684 | let width = source_column.width; | 689 | let width = source_column.width; |
| 685 | let is_full_width = source_column.is_full_width; | 690 | let is_full_width = source_column.is_full_width; |
| 686 | - let window = source_column.windows[source_column.active_window_idx].clone(); | 691 | + let window = |
| 687 | - self.remove_window(&window); | 692 | + self.remove_window_by_idx(self.active_column_idx, source_column.active_window_idx); |
| 688 | 693 | ||
| 689 | self.add_window(window, true, width, is_full_width); | 694 | self.add_window(window, true, width, is_full_width); |
| 690 | } | 695 | } |