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/arrange.c | 10 +++------- sway/tree/container.c | 54 +++++++++++++++++++-------------------------------- sway/tree/layout.c | 29 +++++++++++++-------------- sway/tree/root.c | 2 +- sway/tree/view.c | 6 +++--- sway/tree/workspace.c | 44 +++++++++++++++++++++++++---------------- 6 files changed, 68 insertions(+), 77 deletions(-) (limited to 'sway/tree') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 494a8461..cf4a5d9a 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -144,9 +144,9 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { static void arrange_children_of(struct sway_container *parent); -static void arrange_floating(struct sway_container *floating) { - for (int i = 0; i < floating->children->length; ++i) { - struct sway_container *floater = floating->children->items[i]; +static void arrange_floating(list_t *floating) { + for (int i = 0; i < floating->length; ++i) { + struct sway_container *floater = floating->items[i]; if (floater->type == C_VIEW) { view_autoconfigure(floater->sway_view); } else { @@ -154,7 +154,6 @@ static void arrange_floating(struct sway_container *floating) { } container_set_dirty(floater); } - container_set_dirty(floating); } static void arrange_children_of(struct sway_container *parent) { @@ -179,9 +178,6 @@ static void arrange_children_of(struct sway_container *parent) { case L_NONE: apply_horiz_layout(parent); break; - case L_FLOATING: - arrange_floating(parent); - break; } // Recurse into child containers diff --git a/sway/tree/container.c b/sway/tree/container.c index 2a428ca5..ea20991c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -67,7 +67,11 @@ void container_update_textures_recursive(struct sway_container *con) { } if (con->type == C_WORKSPACE) { - container_update_textures_recursive(con->sway_workspace->floating); + for (int i = 0; i < con->sway_workspace->floating->length; ++i) { + struct sway_container *floater = + con->sway_workspace->floating->items[i]; + container_update_textures_recursive(floater); + } } } } @@ -131,6 +135,7 @@ struct sway_container *container_create(enum sway_container_type type) { static void container_workspace_free(struct sway_workspace *ws) { list_foreach(ws->output_priority, free); list_free(ws->output_priority); + list_free(ws->floating); free(ws); } @@ -222,15 +227,14 @@ static struct sway_container *container_workspace_destroy( for (int i = 0; i < workspace->children->length; i++) { container_move_to(workspace->children->items[i], new_workspace); } - struct sway_container *floating = workspace->sway_workspace->floating; - for (int i = 0; i < floating->children->length; i++) { - container_move_to(floating->children->items[i], - new_workspace->sway_workspace->floating); + list_t *floating = workspace->sway_workspace->floating; + for (int i = 0; i < floating->length; i++) { + struct sway_container *floater = floating->items[i]; + container_remove_child(floater); + workspace_add_floating(new_workspace, floater); } } - container_destroy_noreaping(workspace->sway_workspace->floating); - return output; } @@ -339,10 +343,6 @@ static struct sway_container *container_destroy_noreaping( } bool container_reap_empty(struct sway_container *con) { - if (con->layout == L_FLOATING) { - // Don't reap the magical floating container that each workspace has - return false; - } switch (con->type) { case C_ROOT: case C_OUTPUT: @@ -626,9 +626,8 @@ static struct sway_container *floating_container_at(double lx, double ly, } // Items at the end of the list are on top, so iterate the list in // reverse. - for (int k = ws->floating->children->length - 1; k >= 0; --k) { - struct sway_container *floater = - ws->floating->children->items[k]; + for (int k = ws->floating->length - 1; k >= 0; --k) { + struct sway_container *floater = ws->floating->items[k]; struct wlr_box box = { .x = floater->x, .y = floater->y, @@ -664,9 +663,6 @@ struct sway_container *tiling_container_at( return container_at_tabbed(con, lx, ly, surface, sx, sy); case L_STACKED: return container_at_stacked(con, lx, ly, surface, sx, sy); - case L_FLOATING: - sway_assert(false, "Didn't expect to see floating here"); - return NULL; case L_NONE: return NULL; } @@ -880,9 +876,6 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe case L_STACKED: lenient_strcat(buffer, "S["); break; - case L_FLOATING: - lenient_strcat(buffer, "F["); - break; case L_NONE: lenient_strcat(buffer, "D["); break; @@ -1012,7 +1005,7 @@ void container_set_floating(struct sway_container *container, bool enable) { if (enable) { struct sway_container *old_parent = container_remove_child(container); - container_add_child(workspace->sway_workspace->floating, container); + workspace_add_floating(workspace, container); container_init_floating(container); if (container->type == C_VIEW) { view_set_tiled(container->sway_view, false); @@ -1069,11 +1062,8 @@ void container_set_geometry_from_floating_view(struct sway_container *con) { } bool container_is_floating(struct sway_container *container) { - struct sway_container *workspace = container_parent(container, C_WORKSPACE); - if (!workspace) { - return false; - } - return container->parent == workspace->sway_workspace->floating; + return container->parent && container->parent->type == C_WORKSPACE && + list_find(container->parent->sway_workspace->floating, container) != -1; } void container_get_box(struct sway_container *container, struct wlr_box *box) { @@ -1153,7 +1143,7 @@ void container_floating_move_to(struct sway_container *con, output_get_active_workspace(new_output->sway_output); if (old_workspace != new_workspace) { container_remove_child(con); - container_add_child(new_workspace->sway_workspace->floating, con); + workspace_add_floating(new_workspace, con); arrange_windows(old_workspace); arrange_windows(new_workspace); workspace_detect_urgent(old_workspace); @@ -1266,14 +1256,10 @@ void container_set_fullscreen(struct sway_container *container, bool enable) { } bool container_is_floating_or_child(struct sway_container *container) { - do { - if (container->parent && container->parent->layout == L_FLOATING) { - return true; - } + while (container->parent && container->parent->type != C_WORKSPACE) { container = container->parent; - } while (container && container->type != C_WORKSPACE); - - return false; + } + return container_is_floating(container); } bool container_is_fullscreen_or_child(struct sway_container *container) { 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; } diff --git a/sway/tree/root.c b/sway/tree/root.c index 8d8f42dc..c27ff2c3 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c @@ -105,7 +105,7 @@ void root_scratchpad_show(struct sway_container *con) { if (con->parent) { container_remove_child(con); } - container_add_child(ws->sway_workspace->floating, con); + workspace_add_floating(ws, con); // Make sure the container's center point overlaps this workspace double center_lx = con->x + con->width / 2; diff --git a/sway/tree/view.c b/sway/tree/view.c index 7a2c1950..b77a9bb2 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -531,7 +531,7 @@ static bool should_focus(struct sway_view *view) { struct sway_container *parent = view->swayc->parent; if (parent->type == C_WORKSPACE && prev_focus == parent) { size_t num_children = parent->children->length + - parent->sway_workspace->floating->children->length; + parent->sway_workspace->floating->length; if (num_children == 1) { return true; } @@ -557,7 +557,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { // If we're about to launch the view into the floating container, then // launch it as a tiled view in the root of the workspace instead. if (container_is_floating(target_sibling)) { - target_sibling = target_sibling->parent->parent; + target_sibling = target_sibling->parent; } view->swayc = container_view_create(target_sibling, view); @@ -1046,7 +1046,7 @@ bool view_is_visible(struct sway_view *view) { // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *container = view->swayc; - while (container->type != C_WORKSPACE && container->layout != L_FLOATING) { + while (container->type != C_WORKSPACE) { if (container->parent->layout == L_TABBED || container->parent->layout == L_STACKED) { if (seat_get_active_child(seat, container->parent) != container) { diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index a6d1870c..292f2c9a 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -67,9 +67,7 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; - swayws->floating = container_create(C_CONTAINER); - swayws->floating->parent = swayws->swayc; - swayws->floating->layout = L_FLOATING; + swayws->floating = create_list(); swayws->output_priority = create_list(); workspace->sway_workspace = swayws; workspace_output_add_priority(workspace, output); @@ -392,17 +390,15 @@ bool workspace_switch(struct sway_container *workspace, struct sway_container *next_output = workspace->parent; struct sway_container *next_output_prev_ws = seat_get_active_child(seat, next_output); - struct sway_container *floating = - next_output_prev_ws->sway_workspace->floating; + list_t *floating = next_output_prev_ws->sway_workspace->floating; bool has_sticky = false; if (workspace != next_output_prev_ws) { - for (int i = 0; i < floating->children->length; ++i) { - struct sway_container *floater = floating->children->items[i]; + for (int i = 0; i < floating->length; ++i) { + struct sway_container *floater = floating->items[i]; if (floater->is_sticky) { has_sticky = true; container_remove_child(floater); - container_add_child(workspace->sway_workspace->floating, - floater); + workspace_add_floating(workspace, floater); if (floater == focus) { seat_set_focus(seat, NULL); seat_set_focus(seat, floater); @@ -455,9 +451,9 @@ bool workspace_is_empty(struct sway_container *ws) { return false; } // Sticky views are not considered to be part of this workspace - struct sway_container *floating = ws->sway_workspace->floating; - for (int i = 0; i < floating->children->length; ++i) { - struct sway_container *floater = floating->children->items[i]; + list_t *floating = ws->sway_workspace->floating; + for (int i = 0; i < floating->length; ++i) { + struct sway_container *floater = floating->items[i]; if (!floater->is_sticky) { return false; } @@ -548,9 +544,9 @@ void workspace_for_each_container(struct sway_container *ws, container_for_each_child(container, f, data); } // Floating - for (int i = 0; i < ws->sway_workspace->floating->children->length; ++i) { + for (int i = 0; i < ws->sway_workspace->floating->length; ++i) { struct sway_container *container = - ws->sway_workspace->floating->children->items[i]; + ws->sway_workspace->floating->items[i]; f(container, data); container_for_each_child(container, f, data); } @@ -573,9 +569,8 @@ struct sway_container *workspace_find_container(struct sway_container *ws, } } // Floating - for (int i = 0; i < ws->sway_workspace->floating->children->length; ++i) { - struct sway_container *child = - ws->sway_workspace->floating->children->items[i]; + for (int i = 0; i < ws->sway_workspace->floating->length; ++i) { + struct sway_container *child = ws->sway_workspace->floating->items[i]; if (test(child, data)) { return child; } @@ -597,3 +592,18 @@ struct sway_container *workspace_wrap_children(struct sway_container *ws) { container_add_child(ws, middle); return middle; } + +void workspace_add_floating(struct sway_container *workspace, + struct sway_container *con) { + if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) { + return; + } + if (!sway_assert(con->parent == NULL, "Expected an orphan container")) { + return; + } + + list_add(workspace->sway_workspace->floating, con); + con->parent = workspace; + container_set_dirty(workspace); + container_set_dirty(con); +} -- cgit v1.2.3