From 5094001862559917d4ab47d1b8e67f419646db73 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 24 Aug 2021 06:52:54 -0700 Subject: [PATCH] feat(wm): add send-to-workspace/monitor cmds This commit adds two commands to allow the user to send the currently focused container to a different workspace or monitor as a background operation, without following the moved container to the destination workspace or monitor. resolve #20 --- README.md | 8 ++++++-- derive-ahk/src/lib.rs | 8 ++++---- komorebi-core/src/lib.rs | 2 ++ komorebi/src/process_command.rs | 6 ++++++ komorebi/src/window_manager.rs | 2 ++ komorebic.lib.sample.ahk | 8 ++++++++ komorebic/src/main.rs | 14 ++++++++++++++ 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec252593..1f178ab2 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,8 @@ unstack Unstack the focused window cycle-stack Cycle the focused stack in the specified cycle direction move-to-monitor Move the focused window to the specified monitor 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 focus-monitor Focus the specified monitor focus-workspace Focus the specified workspace on the focused monitor new-workspace Create and append a new workspace on the focused monitor @@ -236,8 +238,10 @@ used [is available here](komorebi.sample.with.lib.ahk). - [x] Cycle through stacked windows - [x] Change focused window by direction - [x] Move focused window container in direction -- [x] Move focused window container to monitor -- [x] Move focused window container to workspace +- [x] Move focused window container to monitor and follow +- [x] Move focused window container to workspace follow +- [x] Send focused window container to monitor +- [x] Send focused window container to workspace - [x] Mouse follows focused container - [x] Resize window container in direction - [ ] Resize child window containers by split ratio diff --git a/derive-ahk/src/lib.rs b/derive-ahk/src/lib.rs index 2780b9d3..4239476e 100644 --- a/derive-ahk/src/lib.rs +++ b/derive-ahk/src/lib.rs @@ -43,8 +43,8 @@ pub fn ahk_function(input: ::proc_macro::TokenStream) -> ::proc_macro::TokenStre impl AhkFunction for #name { fn generate_ahk_function() -> String { ::std::format!(r#" -{}({}) {{ - Run, komorebic.exe {} {}, , Hide +{}({}) {{ + Run, komorebic.exe {} {}, , Hide }}"#, ::std::stringify!(#name), #arguments, @@ -88,8 +88,8 @@ pub fn ahk_library(input: ::proc_macro::TokenStream) -> ::proc_macro::TokenStrea let name = &variant.ident; stream.extend(quote! { v.push(::std::format!(r#" -{}() {{ - Run, komorebic.exe {}, , Hide +{}() {{ + Run, komorebic.exe {}, , Hide }}"#, ::std::stringify!(#name), ::std::stringify!(#name).to_kebab_case() diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index cbc33653..b13c453e 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -32,6 +32,8 @@ pub enum SocketMessage { CycleStack(CycleDirection), MoveContainerToMonitorNumber(usize), MoveContainerToWorkspaceNumber(usize), + SendContainerToMonitorNumber(usize), + SendContainerToWorkspaceNumber(usize), Promote, ToggleFloat, ToggleMonocle, diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index b231715c..ab1b9876 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -106,6 +106,12 @@ impl WindowManager { SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => { self.move_container_to_monitor(monitor_idx, 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)?; + } SocketMessage::TogglePause => { tracing::info!("pausing"); self.is_paused = !self.is_paused; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 2e0cd313..50422a77 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -527,8 +527,10 @@ impl WindowManager { let monitor = self .focused_monitor_mut() .ok_or_else(|| anyhow!("there is no monitor"))?; + monitor.move_container_to_workspace(idx, follow)?; monitor.load_focused_workspace()?; + self.update_focused_workspace(true) } diff --git a/komorebic.lib.sample.ahk b/komorebic.lib.sample.ahk index 4181f63e..b5cd58d1 100644 --- a/komorebic.lib.sample.ahk +++ b/komorebic.lib.sample.ahk @@ -48,6 +48,14 @@ MoveToWorkspace(target) { Run, komorebic.exe move-to-workspace %target%, , Hide } +SendToMonitor(target) { + Run, komorebic.exe send-to-monitor %target%, , Hide +} + +SendToWorkspace(target) { + Run, komorebic.exe send-to-workspace %target%, , Hide +} + FocusMonitor(target) { Run, komorebic.exe focus-monitor %target%, , Hide } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index c7bc77a0..48d5dfb0 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -101,6 +101,8 @@ macro_rules! gen_target_subcommand_args { gen_target_subcommand_args! { MoveToMonitor, MoveToWorkspace, + SendToMonitor, + SendToWorkspace, FocusMonitor, FocusWorkspace } @@ -270,6 +272,12 @@ enum SubCommand { /// Move the focused window to the specified workspace #[clap(setting = AppSettings::ArgRequiredElseHelp)] MoveToWorkspace(MoveToWorkspace), + /// Send the focused window to the specified monitor + #[clap(setting = AppSettings::ArgRequiredElseHelp)] + SendToMonitor(SendToMonitor), + /// Send the focused window to the specified workspace + #[clap(setting = AppSettings::ArgRequiredElseHelp)] + SendToWorkspace(SendToWorkspace), /// Focus the specified monitor #[clap(setting = AppSettings::ArgRequiredElseHelp)] FocusMonitor(FocusMonitor), @@ -422,6 +430,12 @@ fn main() -> Result<()> { SubCommand::MoveToWorkspace(arg) => { send_message(&*SocketMessage::MoveContainerToWorkspaceNumber(arg.target).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::ContainerPadding(arg) => { send_message( &*SocketMessage::ContainerPadding(arg.monitor, arg.workspace, arg.size)