From 2b5a404ac920339a2b9ce32d4718272dee4668b9 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 19 Aug 2018 15:07:07 +1000 Subject: Replace hacky L_FLOATING container with a list Workspaces previously had a magical `workspace->floating` container, which had a layout of L_FLOATING and whose children were actual floating views. This allowed some conveniences, but was a hacky solution because the container has to be exempt from focus, coordinate transactions with the workspace, and omit emitting IPC events (which we didn't do). This commit changes it to be a list directly in the sway_workspace. The L_FLOATING layout is no longer used so this has been removed as well. * Fixes incorrect check in the swap command (it checked if the containers had the L_FLOATING layout, but this layout applied to the magical container). * Introduces workspace_add_floating --- sway/tree/layout.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 49ec806e..2f22a3dd 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -117,9 +117,11 @@ struct sway_container *container_remove_child(struct sway_container *child) { } struct sway_container *parent = child->parent; - int index = index_child(child); + list_t *list = container_is_floating(child) ? + parent->sway_workspace->floating : parent->children; + int index = list_find(list, child); if (index != -1) { - list_del(parent->children, index); + list_del(list, index); } child->parent = NULL; container_notify_subtree_changed(parent); @@ -160,7 +162,8 @@ void container_move_to(struct sway_container *container, struct sway_container *old_output = container_parent(container, C_OUTPUT); old_parent = container_remove_child(container); - container_add_child(new_ws->sway_workspace->floating, container); + workspace_add_floating(new_ws, container); + container_handle_fullscreen_reparent(container, old_parent); // If changing output, center it within the workspace if (old_output != new_ws->parent && !container->is_fullscreen) { container_floating_move_to_center(container); @@ -431,9 +434,6 @@ void container_move(struct sway_container *container, if ((index == parent->children->length - 1 && offs > 0) || (index == 0 && offs < 0)) { if (current->parent == container->parent) { - if (parent->parent->layout == L_FLOATING) { - return; - } if (!parent->is_fullscreen && (parent->layout == L_TABBED || parent->layout == L_STACKED)) { @@ -457,14 +457,10 @@ void container_move(struct sway_container *container, sibling = parent->children->items[index + offs]; wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id); } - } else if (!parent->is_fullscreen && - parent->parent->layout != L_FLOATING && - (parent->layout == L_TABBED || + } else if (!parent->is_fullscreen && (parent->layout == L_TABBED || parent->layout == L_STACKED)) { move_out_of_tabs_stacks(container, current, move_dir, offs); return; - } else if (parent->parent->layout == L_FLOATING) { - return; } else { wlr_log(WLR_DEBUG, "Moving up to find a parallel container"); current = current->parent; @@ -802,13 +798,15 @@ struct sway_container *container_replace_child(struct sway_container *child, if (parent == NULL) { return NULL; } - int i = index_child(child); - // TODO floating + list_t *list = container_is_floating(child) ? + parent->sway_workspace->floating : parent->children; + int i = list_find(list, child); + if (new_child->parent) { container_remove_child(new_child); } - parent->children->items[i] = new_child; + list->items[i] = new_child; new_child->parent = parent; child->parent = NULL; @@ -973,7 +971,8 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) { "Cannot swap ancestor and descendant")) { return; } - if (!sway_assert(con1->layout != L_FLOATING && con2->layout != L_FLOATING, + if (!sway_assert(!container_is_floating(con1) + && !container_is_floating(con2), "Swapping with floating containers is not supported")) { return; } -- cgit v1.2.3