Activate the new right_of window on its workspace
Browse files at this commit4b8e04da041a0cb6b07afe5405bef7e4a61bce5bParent: 026ad8f3 changed files +57 -36
- src/layout/mod.rs +49 -21
- src/layout/monitor.rs +1 -6
- src/layout/workspace.rs +7 -9
src/layout/mod.rsmodified+49 -21
| @@ -581,28 +581,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 581 | .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); | 581 | .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); |
| 582 | 582 | ||
| 583 | match &mut self.monitor_set { | 583 | match &mut self.monitor_set { |
| 584 | - MonitorSet::Normal { | 584 | + MonitorSet::Normal { monitors, .. } => { |
| 585 | - monitors, | 585 | + let mon = monitors |
| 586 | - active_monitor_idx, | 586 | + .iter_mut() |
| 587 | - .. | 587 | + .find(|mon| mon.workspaces.iter().any(|ws| ws.has_window(right_of))) |
| 588 | - } => { | ||
| 589 | - let mon_idx = monitors | ||
| 590 | - .iter() | ||
| 591 | - .position(|mon| mon.workspaces.iter().any(|ws| ws.has_window(right_of))) | ||
| 592 | .unwrap(); | 588 | .unwrap(); |
| 593 | - let mon = &mut monitors[mon_idx]; | ||
| 594 | - | ||
| 595 | - let mut activate = false; | ||
| 596 | - if mon_idx == *active_monitor_idx { | ||
| 597 | - let active_ws = &mon.workspaces[mon.active_workspace_idx]; | ||
| 598 | - if !active_ws.columns.is_empty() { | ||
| 599 | - let active_col = &active_ws.columns[active_ws.active_column_idx]; | ||
| 600 | - let active_tile = &active_col.tiles[active_col.active_tile_idx]; | ||
| 601 | - activate = active_tile.window() == right_of; | ||
| 602 | - } | ||
| 603 | - } | ||
| 604 | 589 | ||
| 605 | - mon.add_window_right_of(right_of, window, activate, width, is_full_width); | 590 | + mon.add_window_right_of(right_of, window, width, is_full_width); |
| 606 | Some(&mon.output) | 591 | Some(&mon.output) |
| 607 | } | 592 | } |
| 608 | MonitorSet::NoOutputs { workspaces } => { | 593 | MonitorSet::NoOutputs { workspaces } => { |
| @@ -610,7 +595,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 610 | .iter_mut() | 595 | .iter_mut() |
| 611 | .find(|ws| ws.has_window(right_of)) | 596 | .find(|ws| ws.has_window(right_of)) |
| 612 | .unwrap(); | 597 | .unwrap(); |
| 613 | - ws.add_window_right_of(right_of, window, true, width, is_full_width); | 598 | + ws.add_window_right_of(right_of, window, width, is_full_width); |
| 614 | None | 599 | None |
| 615 | } | 600 | } |
| 616 | } | 601 | } |
| @@ -2699,6 +2684,49 @@ mod tests { | |||
| 2699 | check_ops(&ops); | 2684 | check_ops(&ops); |
| 2700 | } | 2685 | } |
| 2701 | 2686 | ||
| 2687 | + #[test] | ||
| 2688 | + fn open_right_of_on_different_workspace() { | ||
| 2689 | + let ops = [ | ||
| 2690 | + Op::AddOutput(1), | ||
| 2691 | + Op::AddWindow { | ||
| 2692 | + id: 1, | ||
| 2693 | + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 2694 | + min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))), | ||
| 2695 | + }, | ||
| 2696 | + Op::FocusWorkspaceDown, | ||
| 2697 | + Op::AddWindow { | ||
| 2698 | + id: 2, | ||
| 2699 | + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 2700 | + min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))), | ||
| 2701 | + }, | ||
| 2702 | + Op::AddWindowRightOf { | ||
| 2703 | + id: 3, | ||
| 2704 | + right_of_id: 1, | ||
| 2705 | + bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 2706 | + min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))), | ||
| 2707 | + }, | ||
| 2708 | + ]; | ||
| 2709 | + | ||
| 2710 | + let mut layout = Layout::default(); | ||
| 2711 | + for op in ops { | ||
| 2712 | + op.apply(&mut layout); | ||
| 2713 | + } | ||
| 2714 | + | ||
| 2715 | + let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { | ||
| 2716 | + unreachable!() | ||
| 2717 | + }; | ||
| 2718 | + | ||
| 2719 | + let mon = monitors.into_iter().next().unwrap(); | ||
| 2720 | + assert_eq!( | ||
| 2721 | + mon.active_workspace_idx, 1, | ||
| 2722 | + "the second workspace must remain active" | ||
| 2723 | + ); | ||
| 2724 | + assert_eq!( | ||
| 2725 | + mon.workspaces[0].active_column_idx, 1, | ||
| 2726 | + "the new window must become active" | ||
| 2727 | + ); | ||
| 2728 | + } | ||
| 2729 | + | ||
| 2702 | fn arbitrary_spacing() -> impl Strategy<Value = u16> { | 2730 | fn arbitrary_spacing() -> impl Strategy<Value = u16> { |
| 2703 | // Give equal weight to: | 2731 | // Give equal weight to: |
| 2704 | // - 0: the element is disabled | 2732 | // - 0: the element is disabled |
src/layout/monitor.rsmodified+1 -6
| @@ -130,7 +130,6 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 130 | &mut self, | 130 | &mut self, |
| 131 | right_of: &W, | 131 | right_of: &W, |
| 132 | window: W, | 132 | window: W, |
| 133 | - activate: bool, | ||
| 134 | width: ColumnWidth, | 133 | width: ColumnWidth, |
| 135 | is_full_width: bool, | 134 | is_full_width: bool, |
| 136 | ) { | 135 | ) { |
| @@ -141,14 +140,10 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 141 | .unwrap(); | 140 | .unwrap(); |
| 142 | let workspace = &mut self.workspaces[workspace_idx]; | 141 | let workspace = &mut self.workspaces[workspace_idx]; |
| 143 | 142 | ||
| 144 | - workspace.add_window_right_of(right_of, window, activate, width, is_full_width); | 143 | + workspace.add_window_right_of(right_of, window, width, is_full_width); |
| 145 | 144 | ||
| 146 | // After adding a new window, workspace becomes this output's own. | 145 | // After adding a new window, workspace becomes this output's own. |
| 147 | workspace.original_output = OutputId::new(&self.output); | 146 | workspace.original_output = OutputId::new(&self.output); |
| 148 | - | ||
| 149 | - if activate { | ||
| 150 | - self.activate_workspace(workspace_idx); | ||
| 151 | - } | ||
| 152 | } | 147 | } |
| 153 | 148 | ||
| 154 | pub fn add_column(&mut self, workspace_idx: usize, column: Column<W>, activate: bool) { | 149 | pub fn add_column(&mut self, workspace_idx: usize, column: Column<W>, activate: bool) { |
src/layout/workspace.rsmodified+7 -9
| @@ -559,18 +559,17 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 559 | &mut self, | 559 | &mut self, |
| 560 | right_of: &W, | 560 | right_of: &W, |
| 561 | window: W, | 561 | window: W, |
| 562 | - activate: bool, | ||
| 563 | width: ColumnWidth, | 562 | width: ColumnWidth, |
| 564 | is_full_width: bool, | 563 | is_full_width: bool, |
| 565 | ) { | 564 | ) { |
| 566 | self.enter_output_for_window(&window); | 565 | self.enter_output_for_window(&window); |
| 567 | 566 | ||
| 568 | - let idx = self | 567 | + let right_of_idx = self |
| 569 | .columns | 568 | .columns |
| 570 | .iter() | 569 | .iter() |
| 571 | .position(|col| col.contains(right_of)) | 570 | .position(|col| col.contains(right_of)) |
| 572 | - .unwrap() | 571 | + .unwrap(); |
| 573 | - + 1; | 572 | + let idx = right_of_idx + 1; |
| 574 | 573 | ||
| 575 | let column = Column::new( | 574 | let column = Column::new( |
| 576 | window, | 575 | window, |
| @@ -582,13 +581,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 582 | ); | 581 | ); |
| 583 | self.columns.insert(idx, column); | 582 | self.columns.insert(idx, column); |
| 584 | 583 | ||
| 585 | - if self.active_column_idx >= idx { | 584 | + // Activate the new window if right_of was active. |
| 586 | - self.active_column_idx += 1; | 585 | + if self.active_column_idx == right_of_idx { |
| 587 | - } | ||
| 588 | - | ||
| 589 | - if activate { | ||
| 590 | self.activate_column(idx); | 586 | self.activate_column(idx); |
| 591 | self.activate_prev_column_on_removal = true; | 587 | self.activate_prev_column_on_removal = true; |
| 588 | + } else if idx <= self.active_column_idx { | ||
| 589 | + self.active_column_idx += 1; | ||
| 592 | } | 590 | } |
| 593 | } | 591 | } |
| 594 | 592 | ||