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.
This commit is contained in:
LGUG2Z committed 2025-11-04 07:53:29 -08:00
1 parent 4c0f34d7ef
commit b09e979af5
8 files changed
+42 -4

No files matched your search

+1 -1
View File
@@ -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
+12
View File
@@ -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
```
+1 -1
View File
@@ -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
+1
View File
@@ -290,6 +290,7 @@ pub enum SocketMessage {
Close,
Minimize,
Promote,
PromoteSwap,
PromoteFocus,
PromoteWindow(OperationDirection),
EagerFocus(String),
+1
View File
@@ -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)?;
+18
View File
@@ -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()?;
+7 -2
View File
@@ -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)?;
}
+1
View File
@@ -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