From 0db48e2f1bf001bfd05c686002ff1998d0f1205b Mon Sep 17 00:00:00 2001 From: nyx Date: Sat, 29 Mar 2025 02:40:08 -0400 Subject: Add focus argument to move-window-to-workspace (#1332) * layout: add focus flag to move-window-to-workspace * lib: update comment * misc: minor dup refactor * input: format code * layout: minor nit * layout: update comment * input: remove unnecessary conditionals * misc: replace boolean * tests: fix the failing one * layout: change to smart * ipc: Option -> bool * lib: format code * Rewrite focus doc comment --------- Co-authored-by: Ivan Molodetskikh --- src/layout/mod.rs | 9 +++++++-- src/layout/monitor.rs | 26 ++++++++++++++++---------- src/layout/tests.rs | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) (limited to 'src/layout') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 64e6877c..62ece8c0 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -2120,7 +2120,12 @@ impl Layout { monitor.move_to_workspace_down(); } - pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) { + pub fn move_to_workspace( + &mut self, + window: Option<&W::Id>, + idx: usize, + activate: ActivateWindow, + ) { if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { if window.is_none() || window == Some(move_.tile.window().id()) { return; @@ -2143,7 +2148,7 @@ impl Layout { }; monitor }; - monitor.move_to_workspace(window, idx); + monitor.move_to_workspace(window, idx, activate); } pub fn move_column_to_workspace_up(&mut self) { diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 851bffbd..b0879606 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -474,7 +474,12 @@ impl Monitor { ); } - pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) { + pub fn move_to_workspace( + &mut self, + window: Option<&W::Id>, + idx: usize, + activate: ActivateWindow, + ) { let source_workspace_idx = if let Some(window) = window { self.workspaces .iter() @@ -490,14 +495,11 @@ impl Monitor { } let new_id = self.workspaces[new_idx].id(); - let activate = window.map_or(true, |win| { - self.active_window().map(|win| win.id()) == Some(win) + let activate = activate.map_smart(|| { + window.map_or(true, |win| { + self.active_window().map(|win| win.id()) == Some(win) + }) }); - let activate = if activate { - ActivateWindow::Yes - } else { - ActivateWindow::No - }; let workspace = &mut self.workspaces[source_workspace_idx]; let transaction = Transaction::new(); @@ -515,7 +517,11 @@ impl Monitor { id: new_id, column_idx: None, }, - activate, + if activate { + ActivateWindow::Yes + } else { + ActivateWindow::No + }, removed.width, removed.is_full_width, removed.is_floating, @@ -578,7 +584,7 @@ impl Monitor { let workspace = &mut self.workspaces[source_workspace_idx]; if workspace.floating_is_active() { - self.move_to_workspace(None, idx); + self.move_to_workspace(None, idx, ActivateWindow::Smart); return; } diff --git a/src/layout/tests.rs b/src/layout/tests.rs index f7e5c759..727f53f5 100644 --- a/src/layout/tests.rs +++ b/src/layout/tests.rs @@ -1063,7 +1063,7 @@ impl Op { workspace_idx, } => { let window_id = window_id.filter(|id| layout.has_window(id)); - layout.move_to_workspace(window_id.as_ref(), workspace_idx); + layout.move_to_workspace(window_id.as_ref(), workspace_idx, ActivateWindow::Smart); } Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(), -- cgit