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.
This commit is contained in:
LGUG2Z committed 2025-11-04 13:14:32 -08:00
1 parent b09e979af5
commit 6454393cb2
3 files changed
+13 -1

No files matched your search

+1
View File
@@ -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::<VecDeque<_>>();
ws.focus(monitor.workspaces.focused_idx());
+9 -1
View File
@@ -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)
}
+3
View File
@@ -67,6 +67,8 @@ pub struct Workspace {
pub workspace_config: Option<WorkspaceConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
pub preselected_container_idx: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub promotion_swap_container_idx: Option<usize>,
}
#[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,
}
}
}