mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-01-11 14:40:25 +01:00
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:
@@ -273,6 +273,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());
|
||||
|
||||
@@ -2898,6 +2898,7 @@ impl WindowManager {
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let focused_container_idx = workspace.focused_container_idx();
|
||||
|
||||
let primary_idx = match &workspace.layout {
|
||||
Layout::Default(_) => 0,
|
||||
Layout::Custom(layout) => layout.first_container_idx(
|
||||
@@ -2912,7 +2913,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)
|
||||
}
|
||||
|
||||
@@ -80,6 +80,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)]
|
||||
@@ -132,6 +134,7 @@ impl Default for Workspace {
|
||||
workspace_config: None,
|
||||
wallpaper: None,
|
||||
preselected_container_idx: None,
|
||||
promotion_swap_container_idx: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user