From 6454393cb2a092cd572cd1f37c2297435d4eeaa4 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 4 Nov 2025 13:14:30 -0800 Subject: [PATCH] feat(wm): make promote-swap reversible This commit makes the komorebic promote-swap command reversible by storing the previous container index in the Workspace state. If the current container index is the same as the layout's primary index, and there is a previous promotion swap container index available, the two containers at those indices will be swapped, effectively making a second call to promote-swap an undo. --- komorebi/src/state.rs | 1 + komorebi/src/window_manager.rs | 10 +++++++++- komorebi/src/workspace.rs | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index 7c30ac1c..81d12019 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -141,6 +141,7 @@ impl From<&WindowManager> for State { wallpaper: workspace.wallpaper.clone(), workspace_config: None, preselected_container_idx: None, + promotion_swap_container_idx: None, }) .collect::>(); ws.focus(monitor.workspaces.focused_idx()); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 5819abf8..00c03171 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1656,6 +1656,7 @@ impl WindowManager { 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, }; @@ -1665,7 +1666,14 @@ impl WindowManager { return Ok(()); } - workspace.swap_containers(focused_container_idx, primary_idx); + let primary_tile_is_focused = focused_container_idx == primary_idx; + + if primary_tile_is_focused && let Some(swap_idx) = workspace.promotion_swap_container_idx { + workspace.swap_containers(focused_container_idx, swap_idx); + } else { + workspace.promotion_swap_container_idx = Some(focused_container_idx); + workspace.swap_containers(focused_container_idx, primary_idx); + } self.update_focused_workspace(self.mouse_follows_focus, true) } diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index e7794bfe..09852097 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -67,6 +67,8 @@ pub struct Workspace { pub workspace_config: Option, #[serde(skip_serializing_if = "Option::is_none")] pub preselected_container_idx: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub promotion_swap_container_idx: Option, } #[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] @@ -119,6 +121,7 @@ impl Default for Workspace { wallpaper: None, workspace_config: None, preselected_container_idx: None, + promotion_swap_container_idx: None, } } }