diff --git a/README.md b/README.md index 05072397..5c67fbae 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,7 @@ move-to-monitor Move the focused window to the specified mo move-to-workspace Move the focused window to the specified workspace send-to-monitor Send the focused window to the specified monitor send-to-workspace Send the focused window to the specified workspace +send-to-monitor-workspace Send the focused window to the specified monitor workspace focus-monitor Focus the specified monitor focus-workspace Focus the specified workspace on the focused monitor focus-monitor-workspace Focus the specified workspace on the target monitor diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index dc38fea5..378f606c 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -48,6 +48,7 @@ pub enum SocketMessage { MoveContainerToWorkspaceNumber(usize), SendContainerToMonitorNumber(usize), SendContainerToWorkspaceNumber(usize), + SendContainerToMonitorWorkspaceNumber(usize, usize), MoveWorkspaceToMonitorNumber(usize), Promote, ToggleFloat, diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index 3c0e9f01..ead80f01 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -59,10 +59,19 @@ impl Monitor { Ok(()) } - pub fn add_container(&mut self, container: Container) -> Result<()> { - let workspace = self - .focused_workspace_mut() - .ok_or_else(|| anyhow!("there is no workspace"))?; + pub fn add_container( + &mut self, + container: Container, + workspace_idx: Option, + ) -> Result<()> { + let workspace = if let Some(idx) = workspace_idx { + self.workspaces_mut() + .get_mut(idx) + .ok_or_else(|| anyhow!("there is no workspace at index {}", idx))? + } else { + self.focused_workspace_mut() + .ok_or_else(|| anyhow!("there is no workspace"))? + }; workspace.add_container(container); diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index b8f9f743..831f7e23 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -189,13 +189,16 @@ impl WindowManager { self.move_container_to_workspace(workspace_idx, true)?; } SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => { - self.move_container_to_monitor(monitor_idx, true)?; + self.move_container_to_monitor(monitor_idx, None, true)?; } SocketMessage::SendContainerToWorkspaceNumber(workspace_idx) => { self.move_container_to_workspace(workspace_idx, false)?; } SocketMessage::SendContainerToMonitorNumber(monitor_idx) => { - self.move_container_to_monitor(monitor_idx, false)?; + self.move_container_to_monitor(monitor_idx, None, false)?; + } + SocketMessage::SendContainerToMonitorWorkspaceNumber(monitor_idx, workspace_idx) => { + self.move_container_to_monitor(monitor_idx, Option::from(workspace_idx), false)?; } SocketMessage::MoveWorkspaceToMonitorNumber(monitor_idx) => { self.move_workspace_to_monitor(monitor_idx)?; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index b61a1b2c..8e98e8a4 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -776,7 +776,12 @@ impl WindowManager { } #[tracing::instrument(skip(self))] - pub fn move_container_to_monitor(&mut self, idx: usize, follow: bool) -> Result<()> { + pub fn move_container_to_monitor( + &mut self, + monitor_idx: usize, + workspace_idx: Option, + follow: bool, + ) -> Result<()> { tracing::info!("moving container"); let invisible_borders = self.invisible_borders; @@ -802,15 +807,15 @@ impl WindowManager { let target_monitor = self .monitors_mut() - .get_mut(idx) + .get_mut(monitor_idx) .ok_or_else(|| anyhow!("there is no monitor"))?; - target_monitor.add_container(container)?; + target_monitor.add_container(container, workspace_idx)?; target_monitor.load_focused_workspace(mouse_follows_focus)?; target_monitor.update_focused_workspace(offset, &invisible_borders)?; if follow { - self.focus_monitor(idx)?; + self.focus_monitor(monitor_idx)?; } self.update_focused_workspace(self.mouse_follows_focus) diff --git a/komorebic.lib.sample.ahk b/komorebic.lib.sample.ahk index dd2f582b..e97d065b 100644 --- a/komorebic.lib.sample.ahk +++ b/komorebic.lib.sample.ahk @@ -96,6 +96,10 @@ SendToWorkspace(target) { Run, komorebic.exe send-to-workspace %target%, , Hide } +SendToMonitorWorkspace(target_monitor, target_workspace) { + Run, komorebic.exe send-to-monitor-workspace %target_monitor% %target_workspace%, , Hide +} + FocusMonitor(target) { Run, komorebic.exe focus-monitor %target%, , Hide } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 11e84eff..54b355b3 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -245,6 +245,14 @@ struct FocusMonitorWorkspace { target_workspace: usize, } +#[derive(Parser, AhkFunction)] +pub struct SendToMonitorWorkspace { + /// Target monitor index (zero-indexed) + target_monitor: usize, + /// Workspace index on the target monitor (zero-indexed) + target_workspace: usize, +} + macro_rules! gen_padding_subcommand_args { // SubCommand Pattern ( $( $name:ident ),+ $(,)? ) => { @@ -451,6 +459,9 @@ enum SubCommand { /// Send the focused window to the specified workspace #[clap(setting = AppSettings::ArgRequiredElseHelp)] SendToWorkspace(SendToWorkspace), + /// Send the focused window to the specified monitor workspace + #[clap(setting = AppSettings::ArgRequiredElseHelp)] + SendToMonitorWorkspace(SendToMonitorWorkspace), /// Focus the specified monitor #[clap(setting = AppSettings::ArgRequiredElseHelp)] FocusMonitor(FocusMonitor), @@ -658,6 +669,15 @@ fn main() -> Result<()> { SubCommand::SendToWorkspace(arg) => { send_message(&*SocketMessage::SendContainerToWorkspaceNumber(arg.target).as_bytes()?)?; } + SubCommand::SendToMonitorWorkspace(arg) => { + send_message( + &*SocketMessage::SendContainerToMonitorWorkspaceNumber( + arg.target_monitor, + arg.target_workspace, + ) + .as_bytes()?, + )?; + } SubCommand::MoveWorkspaceToMonitor(arg) => { send_message(&*SocketMessage::MoveWorkspaceToMonitorNumber(arg.target).as_bytes()?)?; }