From 2b5a404ac920339a2b9ce32d4718272dee4668b9 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 19 Aug 2018 15:07:07 +1000 Subject: [PATCH] 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 --- include/sway/tree/container.h | 3 +- include/sway/tree/workspace.h | 5 +++- sway/commands/floating.c | 2 +- sway/commands/focus.c | 2 +- sway/commands/move.c | 2 +- sway/commands/scratchpad.c | 9 +++--- sway/commands/swap.c | 2 +- sway/debug-tree.c | 2 -- sway/desktop/output.c | 31 +++++++------------- sway/desktop/render.c | 5 +--- sway/desktop/transaction.c | 4 ++- sway/input/cursor.c | 4 +-- sway/input/seat.c | 18 +++++------- sway/ipc-json.c | 11 ++++--- 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 +++++++++++++++++----------- 20 files changed, 109 insertions(+), 136 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index c84108012..5eccedc15 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -40,7 +40,6 @@ enum sway_container_layout { L_VERT, L_STACKED, L_TABBED, - L_FLOATING, }; enum sway_container_border { @@ -87,7 +86,7 @@ struct sway_container_state { // Workspace properties struct sway_container *ws_fullscreen; - struct sway_container *ws_floating; + list_t *ws_floating; }; struct sway_container { diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index c9dbb5389..35c91017c 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -9,7 +9,7 @@ struct sway_view; struct sway_workspace { struct sway_container *swayc; struct sway_container *fullscreen; - struct sway_container *floating; + list_t *floating; // struct sway_container list_t *output_priority; bool urgent; }; @@ -63,4 +63,7 @@ struct sway_container *workspace_find_container(struct sway_container *ws, */ struct sway_container *workspace_wrap_children(struct sway_container *ws); +void workspace_add_floating(struct sway_container *workspace, + struct sway_container *con); + #endif diff --git a/sway/commands/floating.c b/sway/commands/floating.c index c9467ef0c..beafd9fb0 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c @@ -33,7 +33,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) { // If the container is in a floating split container, // operate on the split container instead of the child. if (container_is_floating_or_child(container)) { - while (container->parent->layout != L_FLOATING) { + while (container->parent->type != C_WORKSPACE) { container = container->parent; } } diff --git a/sway/commands/focus.c b/sway/commands/focus.c index fe15b4c7c..6659a6834 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -39,7 +39,7 @@ static struct cmd_results *focus_mode(struct sway_container *con, // If the container is in a floating split container, // operate on the split container instead of the child. if (container_is_floating_or_child(con)) { - while (con->parent->layout != L_FLOATING) { + while (con->parent->type != C_WORKSPACE) { con = con->parent; } } diff --git a/sway/commands/move.c b/sway/commands/move.c index 33d1ee4a1..e788d32fc 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -449,7 +449,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) { // If the container is in a floating split container, // operate on the split container instead of the child. if (container_is_floating_or_child(con)) { - while (con->parent->layout != L_FLOATING) { + while (con->parent->type != C_WORKSPACE) { con = con->parent; } } diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c index 0e573aeb3..7da200154 100644 --- a/sway/commands/scratchpad.c +++ b/sway/commands/scratchpad.c @@ -16,7 +16,7 @@ static void scratchpad_toggle_auto(void) { // If the focus is in a floating split container, // operate on the split container instead of the child. if (container_is_floating_or_child(focus)) { - while (focus->parent->layout != L_FLOATING) { + while (focus->parent->type != C_WORKSPACE) { focus = focus->parent; } } @@ -33,9 +33,8 @@ static void scratchpad_toggle_auto(void) { // Check if there is an unfocused scratchpad window on the current workspace // and focus it. - for (int i = 0; i < ws->sway_workspace->floating->children->length; ++i) { - struct sway_container *floater = - ws->sway_workspace->floating->children->items[i]; + for (int i = 0; i < ws->sway_workspace->floating->length; ++i) { + struct sway_container *floater = ws->sway_workspace->floating->items[i]; if (floater->scratchpad && focus != floater) { wlr_log(WLR_DEBUG, "Focusing other scratchpad window (%s) in this workspace", @@ -103,7 +102,7 @@ struct cmd_results *cmd_scratchpad(int argc, char **argv) { // If the container is in a floating split container, // operate on the split container instead of the child. if (container_is_floating_or_child(con)) { - while (con->parent->layout != L_FLOATING) { + while (con->parent->type != C_WORKSPACE) { con = con->parent; } } diff --git a/sway/commands/swap.c b/sway/commands/swap.c index 615e6b1de..f881a0025 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c @@ -72,7 +72,7 @@ struct cmd_results *cmd_swap(int argc, char **argv) { || container_has_ancestor(other, current)) { error = cmd_results_new(CMD_FAILURE, "swap", "Cannot swap ancestor and descendant"); - } else if (current->layout == L_FLOATING || other->layout == L_FLOATING) { + } else if (container_is_floating(current) || container_is_floating(other)) { error = cmd_results_new(CMD_FAILURE, "swap", "Swapping with floating containers is not supported"); } diff --git a/sway/debug-tree.c b/sway/debug-tree.c index f3465afe4..0cb499e7a 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c @@ -22,8 +22,6 @@ static const char *layout_to_str(enum sway_container_layout layout) { return "L_STACKED"; case L_TABBED: return "L_TABBED"; - case L_FLOATING: - return "L_FLOATING"; case L_NONE: return "L_NONE"; } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 1e4f196be..2253eb51b 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -316,31 +316,21 @@ static void send_frame_done_container_iterator(struct sway_container *con, send_frame_done_iterator, data->when); } -static void send_frame_done_container(struct sway_output *output, - struct sway_container *con, struct timespec *when) { - struct send_frame_done_data data = { - .output = output, - .when = when, - }; - output_for_each_container(output->swayc, - send_frame_done_container_iterator, &data); -} - static void send_frame_done(struct sway_output *output, struct timespec *when) { if (output_has_opaque_overlay_layer_surface(output)) { goto send_frame_overlay; } + struct send_frame_done_data data = { + .output = output, + .when = when, + }; struct sway_container *workspace = output_get_active_workspace(output); if (workspace->current.ws_fullscreen) { - if (workspace->current.ws_fullscreen->type == C_VIEW) { - output_view_for_each_surface(output, - workspace->current.ws_fullscreen->sway_view, - send_frame_done_iterator, when); - } else { - send_frame_done_container(output, workspace->current.ws_fullscreen, - when); - } + send_frame_done_container_iterator( + workspace->current.ws_fullscreen, &data); + container_for_each_child(workspace->current.ws_fullscreen, + send_frame_done_container_iterator, &data); #ifdef HAVE_XWAYLAND send_frame_done_unmanaged(output, &root_container.sway_root->xwayland_unmanaged, when); @@ -351,9 +341,8 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) { send_frame_done_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], when); - send_frame_done_container(output, workspace, when); - send_frame_done_container(output, workspace->sway_workspace->floating, - when); + workspace_for_each_container(workspace, + send_frame_done_container_iterator, &data); #ifdef HAVE_XWAYLAND send_frame_done_unmanaged(output, diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 7c48d0d27..aa70903e8 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -754,8 +754,6 @@ static void render_container(struct sway_output *output, case L_TABBED: render_container_tabbed(output, damage, con, parent_focused); break; - case L_FLOATING: - sway_assert(false, "Didn't expect to see floating here"); } } @@ -806,8 +804,7 @@ static void render_floating(struct sway_output *soutput, if (!workspace_is_visible(ws)) { continue; } - list_t *floating = - ws->current.ws_floating->current.children; + list_t *floating = ws->current.ws_floating; for (int k = 0; k < floating->length; ++k) { struct sway_container *floater = floating->items[k]; render_floating_container(soutput, damage, floater); diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index c300558ab..692fb4472 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -111,8 +111,9 @@ static void copy_pending_state(struct sway_container *container, state->using_csd = view->using_csd; } else if (container->type == C_WORKSPACE) { state->ws_fullscreen = container->sway_workspace->fullscreen; - state->ws_floating = container->sway_workspace->floating; + state->ws_floating = create_list(); state->children = create_list(); + list_cat(state->ws_floating, container->sway_workspace->floating); list_cat(state->children, container->children); } else { state->children = create_list(); @@ -189,6 +190,7 @@ static void transaction_apply(struct sway_transaction *transaction) { // Any child containers which are being deleted will be cleaned up in // transaction_destroy(). list_free(container->current.children); + list_free(container->current.ws_floating); memcpy(&container->current, &instruction->state, sizeof(struct sway_container_state)); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 762b80816..ba5e0400a 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -724,7 +724,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT; if (button == btn_move && state == WLR_BUTTON_PRESSED && (mod_pressed || on_titlebar)) { - while (cont->parent->layout != L_FLOATING) { + while (cont->parent->type != C_WORKSPACE) { cont = cont->parent; } seat_begin_move(seat, cont, button); @@ -746,7 +746,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, BTN_LEFT : BTN_RIGHT; if (mod_pressed && button == btn_resize) { struct sway_container *floater = cont; - while (floater->parent->layout != L_FLOATING) { + while (floater->parent->type != C_WORKSPACE) { floater = floater->parent; } edge = 0; diff --git a/sway/input/seat.c b/sway/input/seat.c index d35c62a08..caee37a6b 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -688,7 +688,8 @@ void seat_set_focus_warp(struct sway_seat *seat, // If we've focused a floating container, bring it to the front. // We do this by putting it at the end of the floating list. if (container && container_is_floating(container)) { - list_move_to_end(container->parent->children, container); + list_move_to_end( + container->parent->sway_workspace->floating, container); } // clean up unfocused empty workspace on new output @@ -850,7 +851,7 @@ void seat_set_exclusive_client(struct sway_seat *seat, struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *con) { if (con->type == C_WORKSPACE && !con->children->length && - !con->sway_workspace->floating->children->length) { + !con->sway_workspace->floating->length) { return con; } if (con->type == C_VIEW) { @@ -873,7 +874,7 @@ struct sway_container *seat_get_focus_inactive_tiling(struct sway_seat *seat, struct sway_seat_container *current; wl_list_for_each(current, &seat->focus_stack, link) { struct sway_container *con = current->container; - if (con->layout != L_FLOATING && !container_is_floating_or_child(con) && + if (!container_is_floating_or_child(con) && container_has_ancestor(current->container, ancestor)) { return con; } @@ -884,13 +885,13 @@ struct sway_container *seat_get_focus_inactive_tiling(struct sway_seat *seat, struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat, struct sway_container *ancestor) { if (ancestor->type == C_WORKSPACE && - !ancestor->sway_workspace->floating->children->length) { + !ancestor->sway_workspace->floating->length) { return NULL; } struct sway_seat_container *current; wl_list_for_each(current, &seat->focus_stack, link) { struct sway_container *con = current->container; - if (con->layout != L_FLOATING && container_is_floating_or_child(con) && + if (container_is_floating_or_child(con) && container_has_ancestor(current->container, ancestor)) { return con; } @@ -898,11 +899,6 @@ struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat, return NULL; } -static bool impl_focus_active_child(struct sway_container *con, void *data) { - struct sway_container *parent = data; - return con->parent == parent && con->layout != L_FLOATING; -} - struct sway_container *seat_get_active_child(struct sway_seat *seat, struct sway_container *parent) { if (parent->type == C_VIEW) { @@ -911,7 +907,7 @@ struct sway_container *seat_get_active_child(struct sway_seat *seat, struct sway_seat_container *current; wl_list_for_each(current, &seat->focus_stack, link) { struct sway_container *con = current->container; - if (con->parent == parent && con->layout != L_FLOATING) { + if (con->parent == parent) { return con; } } diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 4c2bcc986..f40af0433 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -23,8 +23,6 @@ static const char *ipc_json_layout_description(enum sway_container_layout l) { return "tabbed"; case L_STACKED: return "stacked"; - case L_FLOATING: - return "floating"; case L_NONE: break; } @@ -180,10 +178,11 @@ static void ipc_json_describe_workspace(struct sway_container *workspace, // Floating json_object *floating_array = json_object_new_array(); - struct sway_container *floating = workspace->sway_workspace->floating; - for (int i = 0; i < floating->children->length; ++i) { - struct sway_container *floater = floating->children->items[i]; - json_object_array_add(floating_array, ipc_json_describe_container_recursive(floater)); + list_t *floating = workspace->sway_workspace->floating; + for (int i = 0; i < floating->length; ++i) { + struct sway_container *floater = floating->items[i]; + json_object_array_add(floating_array, + ipc_json_describe_container_recursive(floater)); } json_object_object_add(object, "floating_nodes", floating_array); } diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 494a84616..cf4a5d9a7 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 2a428ca5e..ea20991ce 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 49ec806ef..2f22a3dde 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 8d8f42dc9..c27ff2c33 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 7a2c1950f..b77a9bb2e 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 a6d1870c9..292f2c9ae 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); +}