From 97423fc8e9d3f1f2990be09777498c5c3d55984f Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 6 Dec 2022 18:54:44 -0800 Subject: [PATCH] feat(wm): move/send container to ws by direction This commit introduces two new commands which will allow the user to move or send the currently focused window to either the next or previous workspace depending on the cycle direction. re #297 --- justfile | 2 +- komorebi-core/src/lib.rs | 2 ++ komorebi/src/process_command.rs | 32 ++++++++++++++++++++++++++++++++ komorebic.lib.ahk | 8 ++++++++ komorebic/src/main.rs | 18 ++++++++++++++++++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 42a8a499..ccc71442 100644 --- a/justfile +++ b/justfile @@ -28,7 +28,7 @@ install: run: just install-komorebic - cargo +stable run --bin komorebi --locked + cargo +stable run --bin komorebi --locked -- -a warn $RUST_LOG="warn": just run diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 08d7281b..d6468af8 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -47,8 +47,10 @@ pub enum SocketMessage { CycleStack(CycleDirection), MoveContainerToMonitorNumber(usize), MoveContainerToWorkspaceNumber(usize), + CycleMoveContainerToWorkspace(CycleDirection), SendContainerToMonitorNumber(usize), SendContainerToWorkspaceNumber(usize), + CycleSendContainerToWorkspace(CycleDirection), SendContainerToMonitorWorkspaceNumber(usize, usize), MoveWorkspaceToMonitorNumber(usize), Close, diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 23ecb541..40247664 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -265,12 +265,44 @@ impl WindowManager { SocketMessage::MoveContainerToWorkspaceNumber(workspace_idx) => { self.move_container_to_workspace(workspace_idx, true)?; } + SocketMessage::CycleMoveContainerToWorkspace(direction) => { + let focused_monitor = self + .focused_monitor() + .ok_or_else(|| anyhow!("there is no monitor"))?; + + let focused_workspace_idx = focused_monitor.focused_workspace_idx(); + let workspaces = focused_monitor.workspaces().len(); + + let workspace_idx = direction.next_idx( + focused_workspace_idx, + NonZeroUsize::new(workspaces) + .ok_or_else(|| anyhow!("there must be at least one workspace"))?, + ); + + self.move_container_to_workspace(workspace_idx, true)?; + } SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => { self.move_container_to_monitor(monitor_idx, None, true)?; } SocketMessage::SendContainerToWorkspaceNumber(workspace_idx) => { self.move_container_to_workspace(workspace_idx, false)?; } + SocketMessage::CycleSendContainerToWorkspace(direction) => { + let focused_monitor = self + .focused_monitor() + .ok_or_else(|| anyhow!("there is no monitor"))?; + + let focused_workspace_idx = focused_monitor.focused_workspace_idx(); + let workspaces = focused_monitor.workspaces().len(); + + let workspace_idx = direction.next_idx( + focused_workspace_idx, + NonZeroUsize::new(workspaces) + .ok_or_else(|| anyhow!("there must be at least one workspace"))?, + ); + + self.move_container_to_workspace(workspace_idx, false)?; + } SocketMessage::SendContainerToMonitorNumber(monitor_idx) => { self.move_container_to_monitor(monitor_idx, None, false)?; } diff --git a/komorebic.lib.ahk b/komorebic.lib.ahk index d9e97adc..9f46ada0 100644 --- a/komorebic.lib.ahk +++ b/komorebic.lib.ahk @@ -96,6 +96,10 @@ MoveToWorkspace(target) { RunWait, komorebic.exe move-to-workspace %target%, , Hide } +CycleMoveToWorkspace(cycle_direction) { + RunWait, komorebic.exe cycle-move-to-workspace %cycle_direction%, , Hide +} + SendToMonitor(target) { RunWait, komorebic.exe send-to-monitor %target%, , Hide } @@ -104,6 +108,10 @@ SendToWorkspace(target) { RunWait, komorebic.exe send-to-workspace %target%, , Hide } +CycleSendToWorkspace(cycle_direction) { + RunWait, komorebic.exe cycle-send-to-workspace %cycle_direction%, , Hide +} + SendToMonitorWorkspace(target_monitor, target_workspace) { RunWait, komorebic.exe send-to-monitor-workspace %target_monitor% %target_workspace%, , Hide } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 4f7cdda2..bad11ec7 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -112,6 +112,8 @@ gen_enum_subcommand_args! { Move: OperationDirection, CycleFocus: CycleDirection, CycleMove: CycleDirection, + CycleMoveToWorkspace: CycleDirection, + CycleSendToWorkspace: CycleDirection, CycleMonitor: CycleDirection, CycleWorkspace: CycleDirection, Stack: OperationDirection, @@ -576,12 +578,18 @@ enum SubCommand { /// Move the focused window to the specified workspace #[clap(arg_required_else_help = true)] MoveToWorkspace(MoveToWorkspace), + /// Move the focused window to the workspace in the given cycle direction + #[clap(arg_required_else_help = true)] + CycleMoveToWorkspace(CycleMoveToWorkspace), /// Send the focused window to the specified monitor #[clap(arg_required_else_help = true)] SendToMonitor(SendToMonitor), /// Send the focused window to the specified workspace #[clap(arg_required_else_help = true)] SendToWorkspace(SendToWorkspace), + /// Send the focused window to the workspace in the given cycle direction + #[clap(arg_required_else_help = true)] + CycleSendToWorkspace(CycleSendToWorkspace), /// Send the focused window to the specified monitor workspace #[clap(arg_required_else_help = true)] SendToMonitorWorkspace(SendToMonitorWorkspace), @@ -847,12 +855,22 @@ fn main() -> Result<()> { SubCommand::MoveToWorkspace(arg) => { send_message(&SocketMessage::MoveContainerToWorkspaceNumber(arg.target).as_bytes()?)?; } + SubCommand::CycleMoveToWorkspace(arg) => { + send_message( + &SocketMessage::CycleMoveContainerToWorkspace(arg.cycle_direction).as_bytes()?, + )?; + } SubCommand::SendToMonitor(arg) => { send_message(&SocketMessage::SendContainerToMonitorNumber(arg.target).as_bytes()?)?; } SubCommand::SendToWorkspace(arg) => { send_message(&SocketMessage::SendContainerToWorkspaceNumber(arg.target).as_bytes()?)?; } + SubCommand::CycleSendToWorkspace(arg) => { + send_message( + &SocketMessage::CycleSendContainerToWorkspace(arg.cycle_direction).as_bytes()?, + )?; + } SubCommand::SendToMonitorWorkspace(arg) => { send_message( &SocketMessage::SendContainerToMonitorWorkspaceNumber(