mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-05 22:46:32 +01:00
feat(wm): promote
The first tile of a layout is its largest, and the place for the window being worked on. `komorebic promote` moves the focused window there, with the windows that were before it each moving one tile on; `promote-swap` swaps it with the window that has the first tile, and from the first tile swaps it back with the window it was last swapped with; `promote-window left|right|up|down` promotes the window on that side of the focused one; and `promote-focus` gives the focus to the first tile and moves nothing. The grid layout has no largest tile, so the four do nothing there. The vm-commands sweep gains the four.
This commit is contained in:
1 parent
95eb4d5039
commit
554d77aed9
17 files changed
+419
-6
No files matched your search
@@ -606,6 +606,92 @@ impl WindowManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Moves the focused container to the first index of the focused workspace, which is the
|
||||
/// largest tile, and tiles the workspace again: the containers before it each move one index
|
||||
/// on
|
||||
///
|
||||
/// The grid layout has no largest tile, and nothing changes there.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// There is no focused workspace, it has no containers, or it cannot be tiled again.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_container_to_front(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
if matches!(workspace.layout, Layout::Default(DefaultLayout::Grid)) {
|
||||
tracing::debug!("ignoring promote command for grid layout");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("promoting container");
|
||||
|
||||
workspace.promote_container()?;
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
|
||||
/// Swaps the focused container with the one at the first index, the largest tile, and tiles
|
||||
/// the workspace again; when the focused container is the first already, swaps it back with
|
||||
/// the container it was swapped with last
|
||||
///
|
||||
/// The grid layout has no largest tile, and nothing changes there.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// There is no focused workspace, or it cannot be tiled again.
|
||||
#[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(());
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
/// Gives the focus to the container at the first index, the largest tile, without moving
|
||||
/// anything
|
||||
///
|
||||
/// The grid layout has no largest tile, and nothing changes there.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// There is no focused workspace, or the backend refuses to focus the window.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn promote_focus_to_front(&mut self) -> eyre::Result<()> {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
if matches!(workspace.layout, Layout::Default(DefaultLayout::Grid)) {
|
||||
tracing::info!("ignoring promote focus command for grid layout");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!("promoting focus");
|
||||
|
||||
let target_idx = match workspace.layout {
|
||||
Layout::Default(_) => 0,
|
||||
};
|
||||
|
||||
workspace.focus_container(target_idx);
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
|
||||
/// Mirrors the layout of the focused workspace along `layout_flip`, on top of the way it is
|
||||
/// mirrored already, and tiles the workspace again
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user