Skip to content

Commit

Permalink
fix: additional fix to window position on manage (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger authored Jan 20, 2025
1 parent 5eac1bc commit d6f512f
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions packages/wm/src/commands/window/manage_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ fn window_state_to_create(
Ok(WindowState::default_from_config(&config.value))
}

/// Gets where to insert a new window in the container tree.
///
/// Rules:
/// - For non-tiling windows: Always append to the workspace.
/// - For tiling windows:
/// 1. Try to insert after the focused tiling window if one exists.
/// 2. If a non-tiling window is focused, try to insert after the first
/// tiling window found.
/// 3. If no tiling windows exist, append to the workspace.
///
/// Returns tuple of (parent container, insertion index).
fn insertion_target(
window_state: &WindowState,
state: &WmState,
Expand All @@ -224,27 +235,27 @@ fn insertion_target(
let focused_workspace =
focused_container.workspace().context("No workspace.")?;

// Append to the workspace if the window is not tiling. Otherwise, insert
// next to the currently focused container.
if focused_container.is_workspace()
|| *window_state != WindowState::Tiling
{
Ok((
focused_workspace.clone().into(),
focused_workspace.child_count(),
))
} else {
let insertion_sibling = match focused_container {
Container::TilingWindow(_) => focused_container,
// For tiling windows, try to find a suitable tiling window to insert
// next to.
if *window_state == WindowState::Tiling {
let sibling = match focused_container {
Container::TilingWindow(_) => Some(focused_container),
_ => focused_workspace
.descendant_focus_order()
.find(Container::is_tiling_window)
.context("No insertion target.")?,
.find(Container::is_tiling_window),
};

Ok((
insertion_sibling.parent().context("No parent.")?,
insertion_sibling.index() + 1,
))
if let Some(sibling) = sibling {
return Ok((
sibling.parent().context("No parent.")?,
sibling.index() + 1,
));
}
}

// Default to appending to workspace.
Ok((
focused_workspace.clone().into(),
focused_workspace.child_count(),
))
}

0 comments on commit d6f512f

Please sign in to comment.