diff options
| author | Annika Hannig <annika@hannig.cc> | 2025-03-02 12:09:44 +0100 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-03-10 23:17:36 -0700 |
| commit | 8737067af530c95ff8039685b236b1f31297b699 (patch) | |
| tree | eaf811d84c737bbb548eac9fc535ccc9d102f2e1 | |
| parent | 50a99f635648c9de0d63d59dc5b7ea8d92cbe1fa (diff) | |
| download | niri-8737067af530c95ff8039685b236b1f31297b699.tar.gz niri-8737067af530c95ff8039685b236b1f31297b699.tar.bz2 niri-8737067af530c95ff8039685b236b1f31297b699.zip | |
added move window to monitor by id
| -rw-r--r-- | niri-config/src/lib.rs | 13 | ||||
| -rw-r--r-- | niri-ipc/src/lib.rs | 12 | ||||
| -rw-r--r-- | src/input/mod.rs | 26 |
3 files changed, 49 insertions, 2 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index d6fac26b..2eb5bf6c 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -1576,6 +1576,11 @@ pub enum Action { MoveWindowToMonitorPrevious, MoveWindowToMonitorNext, MoveWindowToMonitor(#[knuffel(argument)] String), + #[knuffel(skip)] + MoveWindowToMonitorById { + id: u64, + output: String, + }, MoveColumnToMonitorLeft, MoveColumnToMonitorRight, MoveColumnToMonitorDown, @@ -1780,7 +1785,13 @@ impl From<niri_ipc::Action> for Action { niri_ipc::Action::MoveWindowToMonitorUp {} => Self::MoveWindowToMonitorUp, niri_ipc::Action::MoveWindowToMonitorPrevious {} => Self::MoveWindowToMonitorPrevious, niri_ipc::Action::MoveWindowToMonitorNext {} => Self::MoveWindowToMonitorNext, - niri_ipc::Action::MoveWindowToMonitor { output } => Self::MoveWindowToMonitor(output), + niri_ipc::Action::MoveWindowToMonitor { id: None, output } => { + Self::MoveWindowToMonitor(output) + } + niri_ipc::Action::MoveWindowToMonitor { + id: Some(id), + output, + } => Self::MoveWindowToMonitorById { id, output }, niri_ipc::Action::MoveColumnToMonitorLeft {} => Self::MoveColumnToMonitorLeft, niri_ipc::Action::MoveColumnToMonitorRight {} => Self::MoveColumnToMonitorRight, niri_ipc::Action::MoveColumnToMonitorDown {} => Self::MoveColumnToMonitorDown, diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 680734cc..d4886819 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -475,8 +475,18 @@ pub enum Action { MoveWindowToMonitorPrevious {}, /// Move the focused window to the next monitor. MoveWindowToMonitorNext {}, - /// Move the focused window to a specific monitor. + /// Move a window to a specific monitor. + #[cfg_attr( + feature = "clap", + clap(about = "Move the focused window to a specific monitor") + )] MoveWindowToMonitor { + /// Id of the window to move. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option<u64>, + /// The target output name. #[cfg_attr(feature = "clap", arg())] output: String, diff --git a/src/input/mod.rs b/src/input/mod.rs index 4dce9376..2eba3225 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1458,6 +1458,32 @@ impl State { } } } + Action::MoveWindowToMonitorById { id, output } => { + if let Some(output) = self.niri.output_by_name_match(&output).cloned() { + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); + let window = window.map(|(_, m)| m.window.clone()); + + if let Some(window) = window { + let target_was_active = self + .niri + .layout + .active_output() + .is_some_and(|active| output == *active); + + self.niri + .layout + .move_to_output(Some(&window), &output, None); + + // If the active output changed (window was moved and focused). + #[allow(clippy::collapsible_if)] + if !target_was_active && self.niri.layout.active_output() == Some(&output) { + if !self.maybe_warp_cursor_to_focus_centered() { + self.move_cursor_to_output(&output); + } + } + } + } + } Action::MoveColumnToMonitorLeft => { if let Some(output) = self.niri.output_left() { self.niri.layout.move_column_to_output(&output); |
