From f41e8c151e0c8a3f28cdcb21b4311a25d5f1fc69 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 24 Feb 2023 16:59:13 -0800 Subject: [PATCH] feat(wm): add cycle move/send to monitor cmds This commit introduces cyclical commands for moving (with focus) or sending (without focus) windows between adjacent monitors. resolve #363 --- komorebi-core/src/lib.rs | 2 ++ komorebi/src/process_command.rs | 18 ++++++++++++++++++ komorebic/src/main.rs | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 15f78dd8..6c7fbd8a 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -46,10 +46,12 @@ pub enum SocketMessage { UnstackWindow, CycleStack(CycleDirection), MoveContainerToMonitorNumber(usize), + CycleMoveContainerToMonitor(CycleDirection), MoveContainerToWorkspaceNumber(usize), MoveContainerToNamedWorkspace(String), CycleMoveContainerToWorkspace(CycleDirection), SendContainerToMonitorNumber(usize), + CycleSendContainerToMonitor(CycleDirection), SendContainerToWorkspaceNumber(usize), CycleSendContainerToWorkspace(CycleDirection), SendContainerToMonitorWorkspaceNumber(usize, usize), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 68fe98cf..26fb50c7 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -321,6 +321,15 @@ impl WindowManager { SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => { self.move_container_to_monitor(monitor_idx, None, true)?; } + SocketMessage::CycleMoveContainerToMonitor(direction) => { + let monitor_idx = direction.next_idx( + self.focused_monitor_idx(), + NonZeroUsize::new(self.monitors().len()) + .ok_or_else(|| anyhow!("there must be at least one monitor"))?, + ); + + self.move_container_to_monitor(monitor_idx, None, true)?; + } SocketMessage::SendContainerToWorkspaceNumber(workspace_idx) => { self.move_container_to_workspace(workspace_idx, false)?; } @@ -343,6 +352,15 @@ impl WindowManager { SocketMessage::SendContainerToMonitorNumber(monitor_idx) => { self.move_container_to_monitor(monitor_idx, None, false)?; } + SocketMessage::CycleSendContainerToMonitor(direction) => { + let monitor_idx = direction.next_idx( + self.focused_monitor_idx(), + NonZeroUsize::new(self.monitors().len()) + .ok_or_else(|| anyhow!("there must be at least one monitor"))?, + ); + + 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)?; } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 5d2190d2..d18aefb6 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -113,6 +113,8 @@ gen_enum_subcommand_args! { CycleMove: CycleDirection, CycleMoveToWorkspace: CycleDirection, CycleSendToWorkspace: CycleDirection, + CycleSendToMonitor: CycleDirection, + CycleMoveToMonitor: CycleDirection, CycleMonitor: CycleDirection, CycleWorkspace: CycleDirection, Stack: OperationDirection, @@ -722,6 +724,9 @@ enum SubCommand { /// Move the focused window to the specified monitor #[clap(arg_required_else_help = true)] MoveToMonitor(MoveToMonitor), + /// Move the focused window to the monitor in the given cycle direction + #[clap(arg_required_else_help = true)] + CycleMoveToMonitor(CycleMoveToMonitor), /// Move the focused window to the specified workspace #[clap(arg_required_else_help = true)] MoveToWorkspace(MoveToWorkspace), @@ -734,6 +739,9 @@ enum SubCommand { /// Send the focused window to the specified monitor #[clap(arg_required_else_help = true)] SendToMonitor(SendToMonitor), + /// Send the focused window to the monitor in the given cycle direction + #[clap(arg_required_else_help = true)] + CycleSendToMonitor(CycleSendToMonitor), /// Send the focused window to the specified workspace #[clap(arg_required_else_help = true)] SendToWorkspace(SendToWorkspace), @@ -1054,6 +1062,11 @@ fn main() -> Result<()> { SubCommand::MoveToMonitor(arg) => { send_message(&SocketMessage::MoveContainerToMonitorNumber(arg.target).as_bytes()?)?; } + SubCommand::CycleMoveToMonitor(arg) => { + send_message( + &SocketMessage::CycleMoveContainerToMonitor(arg.cycle_direction).as_bytes()?, + )?; + } SubCommand::MoveToWorkspace(arg) => { send_message(&SocketMessage::MoveContainerToWorkspaceNumber(arg.target).as_bytes()?)?; } @@ -1068,6 +1081,11 @@ fn main() -> Result<()> { SubCommand::SendToMonitor(arg) => { send_message(&SocketMessage::SendContainerToMonitorNumber(arg.target).as_bytes()?)?; } + SubCommand::CycleSendToMonitor(arg) => { + send_message( + &SocketMessage::CycleSendContainerToMonitor(arg.cycle_direction).as_bytes()?, + )?; + } SubCommand::SendToWorkspace(arg) => { send_message(&SocketMessage::SendContainerToWorkspaceNumber(arg.target).as_bytes()?)?; }