From 1420334c948fd5630333bb02c2f803687bb61f77 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 15 May 2024 14:06:33 -0700 Subject: [PATCH] feat(cli): add cycle-move-workspace-to-monitor cmd This commit adds a new cli command, cycle-move-workspace-to-monitor. After the introduction of the monitor reconciliator module in combination with display_index_preferences, this command should never really be necessary, however it is worth having as a backup. resolve #718 --- komorebi-core/src/lib.rs | 1 + komorebi/src/process_command.rs | 9 +++++++++ komorebic/src/main.rs | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index c0e979cf0..34b722766 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -59,6 +59,7 @@ pub enum SocketMessage { SendContainerToMonitorWorkspaceNumber(usize, usize), MoveContainerToMonitorWorkspaceNumber(usize, usize), SendContainerToNamedWorkspace(String), + CycleMoveWorkspaceToMonitor(CycleDirection), MoveWorkspaceToMonitorNumber(usize), SwapWorkspacesToMonitorNumber(usize), ForceFocus, diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index c813b00a5..ad90e6350 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -465,6 +465,15 @@ impl WindowManager { SocketMessage::MoveWorkspaceToMonitorNumber(monitor_idx) => { self.move_workspace_to_monitor(monitor_idx)?; } + SocketMessage::CycleMoveWorkspaceToMonitor(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_workspace_to_monitor(monitor_idx)?; + } SocketMessage::TogglePause => { if self.is_paused { tracing::info!("resuming"); diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 7eafd97ee..359790036 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -160,6 +160,7 @@ gen_enum_subcommand_args! { CycleMoveToMonitor: CycleDirection, CycleMonitor: CycleDirection, CycleWorkspace: CycleDirection, + CycleMoveWorkspaceToMonitor: CycleDirection, Stack: OperationDirection, CycleStack: CycleDirection, FlipLayout: Axis, @@ -955,6 +956,9 @@ enum SubCommand { /// Move the focused workspace to the specified monitor #[clap(arg_required_else_help = true)] MoveWorkspaceToMonitor(MoveWorkspaceToMonitor), + /// Move the focused workspace monitor in the given cycle direction + #[clap(arg_required_else_help = true)] + CycleMoveWorkspaceToMonitor(CycleMoveWorkspaceToMonitor), /// Swap focused monitor workspaces with specified monitor #[clap(arg_required_else_help = true)] SwapWorkspacesWithMonitor(SwapWorkspacesWithMonitor), @@ -1583,6 +1587,11 @@ fn main() -> Result<()> { SubCommand::MoveWorkspaceToMonitor(arg) => { send_message(&SocketMessage::MoveWorkspaceToMonitorNumber(arg.target).as_bytes()?)?; } + SubCommand::CycleMoveWorkspaceToMonitor(arg) => { + send_message( + &SocketMessage::CycleMoveWorkspaceToMonitor(arg.cycle_direction).as_bytes()?, + )?; + } SubCommand::SwapWorkspacesWithMonitor(arg) => { send_message(&SocketMessage::SwapWorkspacesToMonitorNumber(arg.target).as_bytes()?)?; }