aboutsummaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs70
-rw-r--r--src/layout/monitor.rs7
-rw-r--r--src/layout/workspace.rs16
3 files changed, 57 insertions, 36 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index dff5c0d0..b9e298cf 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -581,28 +581,13 @@ impl<W: LayoutElement> Layout<W> {
.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
match &mut self.monitor_set {
- MonitorSet::Normal {
- monitors,
- active_monitor_idx,
- ..
- } => {
- let mon_idx = monitors
- .iter()
- .position(|mon| mon.workspaces.iter().any(|ws| ws.has_window(right_of)))
+ MonitorSet::Normal { monitors, .. } => {
+ let mon = monitors
+ .iter_mut()
+ .find(|mon| mon.workspaces.iter().any(|ws| ws.has_window(right_of)))
.unwrap();
- let mon = &mut monitors[mon_idx];
-
- let mut activate = false;
- if mon_idx == *active_monitor_idx {
- let active_ws = &mon.workspaces[mon.active_workspace_idx];
- if !active_ws.columns.is_empty() {
- let active_col = &active_ws.columns[active_ws.active_column_idx];
- let active_tile = &active_col.tiles[active_col.active_tile_idx];
- activate = active_tile.window() == right_of;
- }
- }
- mon.add_window_right_of(right_of, window, activate, width, is_full_width);
+ mon.add_window_right_of(right_of, window, width, is_full_width);
Some(&mon.output)
}
MonitorSet::NoOutputs { workspaces } => {
@@ -610,7 +595,7 @@ impl<W: LayoutElement> Layout<W> {
.iter_mut()
.find(|ws| ws.has_window(right_of))
.unwrap();
- ws.add_window_right_of(right_of, window, true, width, is_full_width);
+ ws.add_window_right_of(right_of, window, width, is_full_width);
None
}
}
@@ -2699,6 +2684,49 @@ mod tests {
check_ops(&ops);
}
+ #[test]
+ fn open_right_of_on_different_workspace() {
+ let ops = [
+ Op::AddOutput(1),
+ Op::AddWindow {
+ id: 1,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))),
+ },
+ Op::FocusWorkspaceDown,
+ Op::AddWindow {
+ id: 2,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))),
+ },
+ Op::AddWindowRightOf {
+ id: 3,
+ right_of_id: 1,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))),
+ },
+ ];
+
+ let mut layout = Layout::default();
+ for op in ops {
+ op.apply(&mut layout);
+ }
+
+ let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
+ unreachable!()
+ };
+
+ let mon = monitors.into_iter().next().unwrap();
+ assert_eq!(
+ mon.active_workspace_idx, 1,
+ "the second workspace must remain active"
+ );
+ assert_eq!(
+ mon.workspaces[0].active_column_idx, 1,
+ "the new window must become active"
+ );
+ }
+
fn arbitrary_spacing() -> impl Strategy<Value = u16> {
// Give equal weight to:
// - 0: the element is disabled
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index f5da804a..383ff965 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -130,7 +130,6 @@ impl<W: LayoutElement> Monitor<W> {
&mut self,
right_of: &W,
window: W,
- activate: bool,
width: ColumnWidth,
is_full_width: bool,
) {
@@ -141,14 +140,10 @@ impl<W: LayoutElement> Monitor<W> {
.unwrap();
let workspace = &mut self.workspaces[workspace_idx];
- workspace.add_window_right_of(right_of, window, activate, width, is_full_width);
+ workspace.add_window_right_of(right_of, window, width, is_full_width);
// After adding a new window, workspace becomes this output's own.
workspace.original_output = OutputId::new(&self.output);
-
- if activate {
- self.activate_workspace(workspace_idx);
- }
}
pub fn add_column(&mut self, workspace_idx: usize, column: Column<W>, activate: bool) {
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 47be5877..07a94321 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -559,18 +559,17 @@ impl<W: LayoutElement> Workspace<W> {
&mut self,
right_of: &W,
window: W,
- activate: bool,
width: ColumnWidth,
is_full_width: bool,
) {
self.enter_output_for_window(&window);
- let idx = self
+ let right_of_idx = self
.columns
.iter()
.position(|col| col.contains(right_of))
- .unwrap()
- + 1;
+ .unwrap();
+ let idx = right_of_idx + 1;
let column = Column::new(
window,
@@ -582,13 +581,12 @@ impl<W: LayoutElement> Workspace<W> {
);
self.columns.insert(idx, column);
- if self.active_column_idx >= idx {
- self.active_column_idx += 1;
- }
-
- if activate {
+ // Activate the new window if right_of was active.
+ if self.active_column_idx == right_of_idx {
self.activate_column(idx);
self.activate_prev_column_on_removal = true;
+ } else if idx <= self.active_column_idx {
+ self.active_column_idx += 1;
}
}