From 3e263534fb0925899628061b9a2c8d7308358c21 Mon Sep 17 00:00:00 2001 From: cdunder Date: Tue, 29 Oct 2024 23:37:24 -0700 Subject: [PATCH] Make move_to_container insert at the correct index. --- sway/commands/move.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sway/commands/move.c b/sway/commands/move.c index 69ed06c0b5..b855556a39 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -257,7 +257,25 @@ static void container_move_to_container(struct sway_container *container, if (destination->view) { container_add_sibling(destination, container, 1); } else { - container_add_child(destination, container); + /* For split containers, we use the currently focused container within it. + * This allows setting marks on, e.g., tabbed containers which will move + * con to a new tab behind the focused tab. */ + sway_log(SWAY_DEBUG, "target is a split container, descending to the currently focused child."); + struct sway_node *focused = seat_get_active_tiling_child( + config->handler_context.seat, &destination->node); + if (!focused || focused == &destination->node) { + // The container has no children + container_add_child(destination, container); + return; + } + struct sway_container *target = focused->sway_container; + int index = container_sibling_index(target) + 1; + if (target->pending.parent) { + container_insert_child(target->pending.parent, container, index); + } else { + // FIXME: This would work except 'Only containers can have marks'. + workspace_insert_tiling(target->pending.workspace, container, index); + } } if (container->view) {