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/input/mod.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/input/mod.rs') diff --git a/src/input/mod.rs b/src/input/mod.rs index 2744561c..961df54a 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -40,7 +40,7 @@ use self::move_grab::MoveGrab; use self::resize_grab::ResizeGrab; use self::spatial_movement_grab::SpatialMovementGrab; use crate::layout::scrolling::ScrollDirection; -use crate::layout::LayoutElement as _; +use crate::layout::{ActivateWindow, LayoutElement as _}; use crate::niri::{CastTarget, State}; use crate::ui::screenshot_ui::ScreenshotUi; use crate::utils::spawning::spawn; @@ -1072,7 +1072,7 @@ impl State { // FIXME: granular self.niri.queue_redraw_all(); } - Action::MoveWindowToWorkspace(reference) => { + Action::MoveWindowToWorkspace(reference, focus) => { if let Some((mut output, index)) = self.niri.find_output_and_workspace_index(reference) { @@ -1091,7 +1091,12 @@ impl State { self.move_cursor_to_output(&output); } } else { - self.niri.layout.move_to_workspace(None, index); + let activate = if focus { + ActivateWindow::Smart + } else { + ActivateWindow::No + }; + self.niri.layout.move_to_workspace(None, index, activate); self.maybe_warp_cursor_to_focus(); } @@ -1102,6 +1107,7 @@ impl State { Action::MoveWindowToWorkspaceById { window_id: id, reference, + focus, } => { let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); let window = window.map(|(_, m)| m.window.clone()); @@ -1130,7 +1136,14 @@ impl State { } } } else { - self.niri.layout.move_to_workspace(Some(&window), index); + let activate = if focus { + ActivateWindow::Smart + } else { + ActivateWindow::No + }; + self.niri + .layout + .move_to_workspace(Some(&window), index, activate); // If we focused the target window. let new_focus = self.niri.layout.focus(); -- cgit