diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 255ace192..7d891058f 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -135,4 +135,6 @@ void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box); size_t workspace_num_tiling_views(struct sway_workspace *ws); +size_t workspace_num_sticky_containers(struct sway_workspace *ws); + #endif diff --git a/sway/tree/container.c b/sway/tree/container.c index 399325e94..858a839b9 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1414,6 +1414,13 @@ struct sway_container *container_split(struct sway_container *child, struct sway_seat *seat = input_manager_get_default_seat(); bool set_focus = (seat_get_focus(seat) == &child->node); + if (container_is_floating(child) && child->view) { + view_set_tiled(child->view, true); + if (child->view->using_csd) { + child->border = child->saved_border; + } + } + struct sway_container *cont = container_create(NULL); cont->width = child->width; cont->height = child->height; diff --git a/sway/tree/output.c b/sway/tree/output.c index d600c5c31..f15a84b34 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -158,7 +158,7 @@ static void evacuate_sticky(struct sway_workspace *old_ws, if (!sway_assert(new_ws, "New output does not have a workspace")) { return; } - while (old_ws->floating->length) { + while(old_ws->floating->length) { struct sway_container *sticky = old_ws->floating->items[0]; container_detach(sticky); workspace_add_floating(new_ws, sticky); @@ -195,18 +195,23 @@ static void output_evacuate(struct sway_output *output) { new_output = root->noop_output; } - if (workspace_is_empty(workspace)) { - // If floating is not empty, there are sticky containers to move - if (workspace->floating->length) { - evacuate_sticky(workspace, new_output); - } - workspace_begin_destroy(workspace); - continue; - } - struct sway_workspace *new_output_ws = output_get_active_workspace(new_output); + if (workspace_is_empty(workspace)) { + // If the new output has an active workspace (the noop output may + // not have one), move all sticky containers to it + if (new_output_ws && + workspace_num_sticky_containers(workspace) > 0) { + evacuate_sticky(workspace, new_output); + } + + if (workspace_num_sticky_containers(workspace) == 0) { + workspace_begin_destroy(workspace); + continue; + } + } + workspace_output_add_priority(workspace, new_output); output_add_workspace(new_output, workspace); output_sort_workspaces(new_output); diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 3d7b2d8d0..be98c12fb 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -821,3 +821,16 @@ size_t workspace_num_tiling_views(struct sway_workspace *ws) { workspace_for_each_container(ws, count_tiling_views, &count); return count; } + +static void count_sticky_containers(struct sway_container *con, void *data) { + if (container_is_floating(con) && con->is_sticky) { + size_t *count = data; + *count += 1; + } +} + +size_t workspace_num_sticky_containers(struct sway_workspace *ws) { + size_t count = 0; + workspace_for_each_container(ws, count_sticky_containers, &count); + return count; +}