From b09e979af5eb1b115069bb58805ec887a2ab51f9 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 4 Nov 2025 07:52:13 -0800 Subject: [PATCH] feat(wm): promote containers by swapping indices This commit adds a new SocketMessage variant PromoteSwap and corresponding komorebic promote-swap command. PromoteSwap will also promote the focused window container to the largest tile in the layout, but instead of removing the focused container x from the Ring and inserting it into position 0, possibly changing the positions of other windows between 0 and x, the indices x and 0 in the Ring will be swapped directly. --- docs/cli/promote-focus.md | 2 +- docs/cli/promote-swap.md | 12 ++++++++++++ docs/cli/promote.md | 2 +- komorebi/src/core/mod.rs | 1 + komorebi/src/process_command.rs | 1 + komorebi/src/window_manager.rs | 18 ++++++++++++++++++ komorebic/src/main.rs | 9 +++++++-- mkdocs.yml | 1 + 8 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 docs/cli/promote-swap.md diff --git a/docs/cli/promote-focus.md b/docs/cli/promote-focus.md index dcbd198d..95e0fd4b 100644 --- a/docs/cli/promote-focus.md +++ b/docs/cli/promote-focus.md @@ -1,7 +1,7 @@ # promote-focus ``` -Promote the user focus to the top of the tree +Promote the user focus to the largest window container Usage: komorebic promote-focus diff --git a/docs/cli/promote-swap.md b/docs/cli/promote-swap.md new file mode 100644 index 00000000..c0430ae0 --- /dev/null +++ b/docs/cli/promote-swap.md @@ -0,0 +1,12 @@ +# promote-swap + +``` +Promote the focused window to the largest tile by swapping container indices with the largest tile + +Usage: komorebic promote-swap + +Options: + -h, --help + Print help + +``` \ No newline at end of file diff --git a/docs/cli/promote.md b/docs/cli/promote.md index ddf40bde..831a9d88 100644 --- a/docs/cli/promote.md +++ b/docs/cli/promote.md @@ -1,7 +1,7 @@ # promote ``` -Promote the focused window to the top of the tree +Promote the focused window to the largest tile via container removal and re-insertion Usage: komorebic promote diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index d40724fe..7aea3eb6 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -290,6 +290,7 @@ pub enum SocketMessage { Close, Minimize, Promote, + PromoteSwap, PromoteFocus, PromoteWindow(OperationDirection), EagerFocus(String), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 3fa2842d..4ebe8eeb 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -135,6 +135,7 @@ impl WindowManager { match message { SocketMessage::Promote => self.promote_container_to_front()?, + SocketMessage::PromoteSwap => self.promote_container_swap()?, SocketMessage::PromoteFocus => self.promote_focus_to_front()?, SocketMessage::PromoteWindow(direction) => { self.focus_container_in_direction(direction)?; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 34a3f1c4..5819abf8 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1652,6 +1652,24 @@ impl WindowManager { self.update_focused_workspace(self.mouse_follows_focus, true) } + #[tracing::instrument(skip(self))] + pub fn promote_container_swap(&mut self) -> eyre::Result<()> { + let workspace = self.focused_workspace_mut()?; + let focused_container_idx = workspace.focused_container_idx(); + let primary_idx = match workspace.layout { + Layout::Default(_) => 0, + }; + + if matches!(workspace.layout, Layout::Default(DefaultLayout::Grid)) { + tracing::debug!("ignoring promote-swap command for grid layout"); + return Ok(()); + } + + workspace.swap_containers(focused_container_idx, primary_idx); + + self.update_focused_workspace(self.mouse_follows_focus, true) + } + #[tracing::instrument(skip(self))] pub fn promote_focus_to_front(&mut self) -> eyre::Result<()> { let workspace = self.focused_workspace_mut()?; diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index dd7ed95c..2a898158 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -932,9 +932,11 @@ enum SubCommand { /// Flip the layout on the focused workspace #[clap(arg_required_else_help = true)] FlipLayout(FlipLayout), - /// Promote the focused window to the top of the tree + /// Promote the focused window to the largest tile via container removal and re-insertion Promote, - /// Promote the user focus to the top of the tree + /// Promote the focused window to the largest tile by swapping container indices with the largest tile + PromoteSwap, + /// Promote the user focus to the largest window container PromoteFocus, /// Promote the window in the specified direction PromoteWindow(PromoteWindow), @@ -1760,6 +1762,9 @@ fn main() -> eyre::Result<()> { SubCommand::Promote => { send_message(&SocketMessage::Promote)?; } + SubCommand::PromoteSwap => { + send_message(&SocketMessage::PromoteSwap)?; + } SubCommand::PromoteFocus => { send_message(&SocketMessage::PromoteFocus)?; } diff --git a/mkdocs.yml b/mkdocs.yml index 0b47fb4b..a77cb832 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -145,6 +145,7 @@ nav: - cli/scrolling-layout-columns.md - cli/flip-layout.md - cli/promote.md + - cli/promote-swap.md - cli/promote-focus.md - cli/promote-window.md - cli/retile.md