Skip to content

Commit 0e9d47e

Browse files
committed
Make move_to_container insert at the correct index.
1 parent f293418 commit 0e9d47e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sway/commands/move.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,26 @@ static void container_move_to_container(struct sway_container *container,
256256
if (destination->view) {
257257
container_add_sibling(destination, container, 1);
258258
} else {
259-
container_add_child(destination, container);
259+
/* For split containers, we use the currently focused container within it.
260+
* This allows setting marks on, e.g., tabbed containers which will move
261+
* con to a new tab behind the focused tab. */
262+
sway_log(SWAY_DEBUG, "target is a split container, descending to the currently focused child.");
263+
struct sway_node *focused = seat_get_active_tiling_child(
264+
config->handler_context.seat, &destination->node);
265+
if (!focused || focused == &destination->node) {
266+
// The container has no children
267+
container_add_child(destination, container);
268+
return;
269+
}
270+
struct sway_container *target = focused->sway_container;
271+
int index = container_sibling_index(target) + 1;
272+
if (target->pending.parent) {
273+
container_insert_child(target->pending.parent, container, index);
274+
} else {
275+
// TODO: This branch is unreachable until workspaces can be marked.
276+
// Issue url: https://github.com/swaywm/sway/issues/8474
277+
workspace_insert_tiling(target->pending.workspace, container, index);
278+
}
260279
}
261280

262281
if (container->view) {

0 commit comments

Comments
 (0)