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
master
Ryan Dwyer 6 years ago
parent 389d159c81
commit 2b5a404ac9

@ -40,7 +40,6 @@ enum sway_container_layout {
L_VERT, L_VERT,
L_STACKED, L_STACKED,
L_TABBED, L_TABBED,
L_FLOATING,
}; };
enum sway_container_border { enum sway_container_border {
@ -87,7 +86,7 @@ struct sway_container_state {
// Workspace properties // Workspace properties
struct sway_container *ws_fullscreen; struct sway_container *ws_fullscreen;
struct sway_container *ws_floating; list_t *ws_floating;
}; };
struct sway_container { struct sway_container {

@ -9,7 +9,7 @@ struct sway_view;
struct sway_workspace { struct sway_workspace {
struct sway_container *swayc; struct sway_container *swayc;
struct sway_container *fullscreen; struct sway_container *fullscreen;
struct sway_container *floating; list_t *floating; // struct sway_container
list_t *output_priority; list_t *output_priority;
bool urgent; 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); struct sway_container *workspace_wrap_children(struct sway_container *ws);
void workspace_add_floating(struct sway_container *workspace,
struct sway_container *con);
#endif #endif

@ -33,7 +33,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
// If the container is in a floating split container, // If the container is in a floating split container,
// operate on the split container instead of the child. // operate on the split container instead of the child.
if (container_is_floating_or_child(container)) { if (container_is_floating_or_child(container)) {
while (container->parent->layout != L_FLOATING) { while (container->parent->type != C_WORKSPACE) {
container = container->parent; container = container->parent;
} }
} }

@ -39,7 +39,7 @@ static struct cmd_results *focus_mode(struct sway_container *con,
// If the container is in a floating split container, // If the container is in a floating split container,
// operate on the split container instead of the child. // operate on the split container instead of the child.
if (container_is_floating_or_child(con)) { if (container_is_floating_or_child(con)) {
while (con->parent->layout != L_FLOATING) { while (con->parent->type != C_WORKSPACE) {
con = con->parent; con = con->parent;
} }
} }

@ -449,7 +449,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) {
// If the container is in a floating split container, // If the container is in a floating split container,
// operate on the split container instead of the child. // operate on the split container instead of the child.
if (container_is_floating_or_child(con)) { if (container_is_floating_or_child(con)) {
while (con->parent->layout != L_FLOATING) { while (con->parent->type != C_WORKSPACE) {
con = con->parent; con = con->parent;
} }
} }

@ -16,7 +16,7 @@ static void scratchpad_toggle_auto(void) {
// If the focus is in a floating split container, // If the focus is in a floating split container,
// operate on the split container instead of the child. // operate on the split container instead of the child.
if (container_is_floating_or_child(focus)) { if (container_is_floating_or_child(focus)) {
while (focus->parent->layout != L_FLOATING) { while (focus->parent->type != C_WORKSPACE) {
focus = focus->parent; 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 // Check if there is an unfocused scratchpad window on the current workspace
// and focus it. // and focus it.
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 *floater = struct sway_container *floater = ws->sway_workspace->floating->items[i];
ws->sway_workspace->floating->children->items[i];
if (floater->scratchpad && focus != floater) { if (floater->scratchpad && focus != floater) {
wlr_log(WLR_DEBUG, wlr_log(WLR_DEBUG,
"Focusing other scratchpad window (%s) in this workspace", "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, // If the container is in a floating split container,
// operate on the split container instead of the child. // operate on the split container instead of the child.
if (container_is_floating_or_child(con)) { if (container_is_floating_or_child(con)) {
while (con->parent->layout != L_FLOATING) { while (con->parent->type != C_WORKSPACE) {
con = con->parent; con = con->parent;
} }
} }

@ -72,7 +72,7 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
|| container_has_ancestor(other, current)) { || container_has_ancestor(other, current)) {
error = cmd_results_new(CMD_FAILURE, "swap", error = cmd_results_new(CMD_FAILURE, "swap",
"Cannot swap ancestor and descendant"); "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", error = cmd_results_new(CMD_FAILURE, "swap",
"Swapping with floating containers is not supported"); "Swapping with floating containers is not supported");
} }

@ -22,8 +22,6 @@ static const char *layout_to_str(enum sway_container_layout layout) {
return "L_STACKED"; return "L_STACKED";
case L_TABBED: case L_TABBED:
return "L_TABBED"; return "L_TABBED";
case L_FLOATING:
return "L_FLOATING";
case L_NONE: case L_NONE:
return "L_NONE"; return "L_NONE";
} }

@ -316,31 +316,21 @@ static void send_frame_done_container_iterator(struct sway_container *con,
send_frame_done_iterator, data->when); 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) { static void send_frame_done(struct sway_output *output, struct timespec *when) {
if (output_has_opaque_overlay_layer_surface(output)) { if (output_has_opaque_overlay_layer_surface(output)) {
goto send_frame_overlay; goto send_frame_overlay;
} }
struct send_frame_done_data data = {
.output = output,
.when = when,
};
struct sway_container *workspace = output_get_active_workspace(output); struct sway_container *workspace = output_get_active_workspace(output);
if (workspace->current.ws_fullscreen) { if (workspace->current.ws_fullscreen) {
if (workspace->current.ws_fullscreen->type == C_VIEW) { send_frame_done_container_iterator(
output_view_for_each_surface(output, workspace->current.ws_fullscreen, &data);
workspace->current.ws_fullscreen->sway_view, container_for_each_child(workspace->current.ws_fullscreen,
send_frame_done_iterator, when); send_frame_done_container_iterator, &data);
} else {
send_frame_done_container(output, workspace->current.ws_fullscreen,
when);
}
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
send_frame_done_unmanaged(output, send_frame_done_unmanaged(output,
&root_container.sway_root->xwayland_unmanaged, when); &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, send_frame_done_layer(output,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], when); &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], when);
send_frame_done_container(output, workspace, when); workspace_for_each_container(workspace,
send_frame_done_container(output, workspace->sway_workspace->floating, send_frame_done_container_iterator, &data);
when);
#ifdef HAVE_XWAYLAND #ifdef HAVE_XWAYLAND
send_frame_done_unmanaged(output, send_frame_done_unmanaged(output,

@ -754,8 +754,6 @@ static void render_container(struct sway_output *output,
case L_TABBED: case L_TABBED:
render_container_tabbed(output, damage, con, parent_focused); render_container_tabbed(output, damage, con, parent_focused);
break; 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)) { if (!workspace_is_visible(ws)) {
continue; continue;
} }
list_t *floating = list_t *floating = ws->current.ws_floating;
ws->current.ws_floating->current.children;
for (int k = 0; k < floating->length; ++k) { for (int k = 0; k < floating->length; ++k) {
struct sway_container *floater = floating->items[k]; struct sway_container *floater = floating->items[k];
render_floating_container(soutput, damage, floater); render_floating_container(soutput, damage, floater);

@ -111,8 +111,9 @@ static void copy_pending_state(struct sway_container *container,
state->using_csd = view->using_csd; state->using_csd = view->using_csd;
} else if (container->type == C_WORKSPACE) { } else if (container->type == C_WORKSPACE) {
state->ws_fullscreen = container->sway_workspace->fullscreen; state->ws_fullscreen = container->sway_workspace->fullscreen;
state->ws_floating = container->sway_workspace->floating; state->ws_floating = create_list();
state->children = create_list(); state->children = create_list();
list_cat(state->ws_floating, container->sway_workspace->floating);
list_cat(state->children, container->children); list_cat(state->children, container->children);
} else { } else {
state->children = create_list(); 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 // Any child containers which are being deleted will be cleaned up in
// transaction_destroy(). // transaction_destroy().
list_free(container->current.children); list_free(container->current.children);
list_free(container->current.ws_floating);
memcpy(&container->current, &instruction->state, memcpy(&container->current, &instruction->state,
sizeof(struct sway_container_state)); sizeof(struct sway_container_state));

@ -724,7 +724,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT; uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
if (button == btn_move && state == WLR_BUTTON_PRESSED && if (button == btn_move && state == WLR_BUTTON_PRESSED &&
(mod_pressed || on_titlebar)) { (mod_pressed || on_titlebar)) {
while (cont->parent->layout != L_FLOATING) { while (cont->parent->type != C_WORKSPACE) {
cont = cont->parent; cont = cont->parent;
} }
seat_begin_move(seat, cont, button); seat_begin_move(seat, cont, button);
@ -746,7 +746,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
BTN_LEFT : BTN_RIGHT; BTN_LEFT : BTN_RIGHT;
if (mod_pressed && button == btn_resize) { if (mod_pressed && button == btn_resize) {
struct sway_container *floater = cont; struct sway_container *floater = cont;
while (floater->parent->layout != L_FLOATING) { while (floater->parent->type != C_WORKSPACE) {
floater = floater->parent; floater = floater->parent;
} }
edge = 0; edge = 0;

@ -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. // 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. // We do this by putting it at the end of the floating list.
if (container && container_is_floating(container)) { 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 // 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 *seat_get_focus_inactive(struct sway_seat *seat,
struct sway_container *con) { struct sway_container *con) {
if (con->type == C_WORKSPACE && !con->children->length && if (con->type == C_WORKSPACE && !con->children->length &&
!con->sway_workspace->floating->children->length) { !con->sway_workspace->floating->length) {
return con; return con;
} }
if (con->type == C_VIEW) { 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; struct sway_seat_container *current;
wl_list_for_each(current, &seat->focus_stack, link) { wl_list_for_each(current, &seat->focus_stack, link) {
struct sway_container *con = current->container; 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)) { container_has_ancestor(current->container, ancestor)) {
return con; 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 *seat_get_focus_inactive_floating(struct sway_seat *seat,
struct sway_container *ancestor) { struct sway_container *ancestor) {
if (ancestor->type == C_WORKSPACE && if (ancestor->type == C_WORKSPACE &&
!ancestor->sway_workspace->floating->children->length) { !ancestor->sway_workspace->floating->length) {
return NULL; return NULL;
} }
struct sway_seat_container *current; struct sway_seat_container *current;
wl_list_for_each(current, &seat->focus_stack, link) { wl_list_for_each(current, &seat->focus_stack, link) {
struct sway_container *con = current->container; 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)) { container_has_ancestor(current->container, ancestor)) {
return con; return con;
} }
@ -898,11 +899,6 @@ struct sway_container *seat_get_focus_inactive_floating(struct sway_seat *seat,
return NULL; 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 *seat_get_active_child(struct sway_seat *seat,
struct sway_container *parent) { struct sway_container *parent) {
if (parent->type == C_VIEW) { 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; struct sway_seat_container *current;
wl_list_for_each(current, &seat->focus_stack, link) { wl_list_for_each(current, &seat->focus_stack, link) {
struct sway_container *con = current->container; struct sway_container *con = current->container;
if (con->parent == parent && con->layout != L_FLOATING) { if (con->parent == parent) {
return con; return con;
} }
} }

@ -23,8 +23,6 @@ static const char *ipc_json_layout_description(enum sway_container_layout l) {
return "tabbed"; return "tabbed";
case L_STACKED: case L_STACKED:
return "stacked"; return "stacked";
case L_FLOATING:
return "floating";
case L_NONE: case L_NONE:
break; break;
} }
@ -180,10 +178,11 @@ static void ipc_json_describe_workspace(struct sway_container *workspace,
// Floating // Floating
json_object *floating_array = json_object_new_array(); json_object *floating_array = json_object_new_array();
struct sway_container *floating = workspace->sway_workspace->floating; list_t *floating = workspace->sway_workspace->floating;
for (int i = 0; i < floating->children->length; ++i) { for (int i = 0; i < floating->length; ++i) {
struct sway_container *floater = floating->children->items[i]; struct sway_container *floater = floating->items[i];
json_object_array_add(floating_array, ipc_json_describe_container_recursive(floater)); json_object_array_add(floating_array,
ipc_json_describe_container_recursive(floater));
} }
json_object_object_add(object, "floating_nodes", floating_array); json_object_object_add(object, "floating_nodes", floating_array);
} }

@ -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_children_of(struct sway_container *parent);
static void arrange_floating(struct sway_container *floating) { static void arrange_floating(list_t *floating) {
for (int i = 0; i < floating->children->length; ++i) { for (int i = 0; i < floating->length; ++i) {
struct sway_container *floater = floating->children->items[i]; struct sway_container *floater = floating->items[i];
if (floater->type == C_VIEW) { if (floater->type == C_VIEW) {
view_autoconfigure(floater->sway_view); view_autoconfigure(floater->sway_view);
} else { } else {
@ -154,7 +154,6 @@ static void arrange_floating(struct sway_container *floating) {
} }
container_set_dirty(floater); container_set_dirty(floater);
} }
container_set_dirty(floating);
} }
static void arrange_children_of(struct sway_container *parent) { 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: case L_NONE:
apply_horiz_layout(parent); apply_horiz_layout(parent);
break; break;
case L_FLOATING:
arrange_floating(parent);
break;
} }
// Recurse into child containers // Recurse into child containers

@ -67,7 +67,11 @@ void container_update_textures_recursive(struct sway_container *con) {
} }
if (con->type == C_WORKSPACE) { 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) { static void container_workspace_free(struct sway_workspace *ws) {
list_foreach(ws->output_priority, free); list_foreach(ws->output_priority, free);
list_free(ws->output_priority); list_free(ws->output_priority);
list_free(ws->floating);
free(ws); free(ws);
} }
@ -222,15 +227,14 @@ static struct sway_container *container_workspace_destroy(
for (int i = 0; i < workspace->children->length; i++) { for (int i = 0; i < workspace->children->length; i++) {
container_move_to(workspace->children->items[i], new_workspace); container_move_to(workspace->children->items[i], new_workspace);
} }
struct sway_container *floating = workspace->sway_workspace->floating; list_t *floating = workspace->sway_workspace->floating;
for (int i = 0; i < floating->children->length; i++) { for (int i = 0; i < floating->length; i++) {
container_move_to(floating->children->items[i], struct sway_container *floater = floating->items[i];
new_workspace->sway_workspace->floating); container_remove_child(floater);
workspace_add_floating(new_workspace, floater);
} }
} }
container_destroy_noreaping(workspace->sway_workspace->floating);
return output; return output;
} }
@ -339,10 +343,6 @@ static struct sway_container *container_destroy_noreaping(
} }
bool container_reap_empty(struct sway_container *con) { 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) { switch (con->type) {
case C_ROOT: case C_ROOT:
case C_OUTPUT: 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 // Items at the end of the list are on top, so iterate the list in
// reverse. // reverse.
for (int k = ws->floating->children->length - 1; k >= 0; --k) { for (int k = ws->floating->length - 1; k >= 0; --k) {
struct sway_container *floater = struct sway_container *floater = ws->floating->items[k];
ws->floating->children->items[k];
struct wlr_box box = { struct wlr_box box = {
.x = floater->x, .x = floater->x,
.y = floater->y, .y = floater->y,
@ -664,9 +663,6 @@ struct sway_container *tiling_container_at(
return container_at_tabbed(con, lx, ly, surface, sx, sy); return container_at_tabbed(con, lx, ly, surface, sx, sy);
case L_STACKED: case L_STACKED:
return container_at_stacked(con, lx, ly, surface, sx, sy); 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: case L_NONE:
return NULL; return NULL;
} }
@ -880,9 +876,6 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe
case L_STACKED: case L_STACKED:
lenient_strcat(buffer, "S["); lenient_strcat(buffer, "S[");
break; break;
case L_FLOATING:
lenient_strcat(buffer, "F[");
break;
case L_NONE: case L_NONE:
lenient_strcat(buffer, "D["); lenient_strcat(buffer, "D[");
break; break;
@ -1012,7 +1005,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (enable) { if (enable) {
struct sway_container *old_parent = container_remove_child(container); 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); container_init_floating(container);
if (container->type == C_VIEW) { if (container->type == C_VIEW) {
view_set_tiled(container->sway_view, false); 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) { bool container_is_floating(struct sway_container *container) {
struct sway_container *workspace = container_parent(container, C_WORKSPACE); return container->parent && container->parent->type == C_WORKSPACE &&
if (!workspace) { list_find(container->parent->sway_workspace->floating, container) != -1;
return false;
}
return container->parent == workspace->sway_workspace->floating;
} }
void container_get_box(struct sway_container *container, struct wlr_box *box) { 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); output_get_active_workspace(new_output->sway_output);
if (old_workspace != new_workspace) { if (old_workspace != new_workspace) {
container_remove_child(con); 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(old_workspace);
arrange_windows(new_workspace); arrange_windows(new_workspace);
workspace_detect_urgent(old_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) { bool container_is_floating_or_child(struct sway_container *container) {
do { while (container->parent && container->parent->type != C_WORKSPACE) {
if (container->parent && container->parent->layout == L_FLOATING) {
return true;
}
container = container->parent; container = container->parent;
} while (container && container->type != C_WORKSPACE); }
return container_is_floating(container);
return false;
} }
bool container_is_fullscreen_or_child(struct sway_container *container) { bool container_is_fullscreen_or_child(struct sway_container *container) {

@ -117,9 +117,11 @@ struct sway_container *container_remove_child(struct sway_container *child) {
} }
struct sway_container *parent = child->parent; 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) { if (index != -1) {
list_del(parent->children, index); list_del(list, index);
} }
child->parent = NULL; child->parent = NULL;
container_notify_subtree_changed(parent); container_notify_subtree_changed(parent);
@ -160,7 +162,8 @@ void container_move_to(struct sway_container *container,
struct sway_container *old_output = struct sway_container *old_output =
container_parent(container, C_OUTPUT); container_parent(container, C_OUTPUT);
old_parent = container_remove_child(container); 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 changing output, center it within the workspace
if (old_output != new_ws->parent && !container->is_fullscreen) { if (old_output != new_ws->parent && !container->is_fullscreen) {
container_floating_move_to_center(container); 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) if ((index == parent->children->length - 1 && offs > 0)
|| (index == 0 && offs < 0)) { || (index == 0 && offs < 0)) {
if (current->parent == container->parent) { if (current->parent == container->parent) {
if (parent->parent->layout == L_FLOATING) {
return;
}
if (!parent->is_fullscreen && if (!parent->is_fullscreen &&
(parent->layout == L_TABBED || (parent->layout == L_TABBED ||
parent->layout == L_STACKED)) { parent->layout == L_STACKED)) {
@ -457,14 +457,10 @@ void container_move(struct sway_container *container,
sibling = parent->children->items[index + offs]; sibling = parent->children->items[index + offs];
wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id); wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id);
} }
} else if (!parent->is_fullscreen && } else if (!parent->is_fullscreen && (parent->layout == L_TABBED ||
parent->parent->layout != L_FLOATING &&
(parent->layout == L_TABBED ||
parent->layout == L_STACKED)) { parent->layout == L_STACKED)) {
move_out_of_tabs_stacks(container, current, move_dir, offs); move_out_of_tabs_stacks(container, current, move_dir, offs);
return; return;
} else if (parent->parent->layout == L_FLOATING) {
return;
} else { } else {
wlr_log(WLR_DEBUG, "Moving up to find a parallel container"); wlr_log(WLR_DEBUG, "Moving up to find a parallel container");
current = current->parent; current = current->parent;
@ -802,13 +798,15 @@ struct sway_container *container_replace_child(struct sway_container *child,
if (parent == NULL) { if (parent == NULL) {
return 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) { if (new_child->parent) {
container_remove_child(new_child); container_remove_child(new_child);
} }
parent->children->items[i] = new_child; list->items[i] = new_child;
new_child->parent = parent; new_child->parent = parent;
child->parent = NULL; child->parent = NULL;
@ -973,7 +971,8 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
"Cannot swap ancestor and descendant")) { "Cannot swap ancestor and descendant")) {
return; 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")) { "Swapping with floating containers is not supported")) {
return; return;
} }

@ -105,7 +105,7 @@ void root_scratchpad_show(struct sway_container *con) {
if (con->parent) { if (con->parent) {
container_remove_child(con); 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 // Make sure the container's center point overlaps this workspace
double center_lx = con->x + con->width / 2; double center_lx = con->x + con->width / 2;

@ -531,7 +531,7 @@ static bool should_focus(struct sway_view *view) {
struct sway_container *parent = view->swayc->parent; struct sway_container *parent = view->swayc->parent;
if (parent->type == C_WORKSPACE && prev_focus == parent) { if (parent->type == C_WORKSPACE && prev_focus == parent) {
size_t num_children = parent->children->length + size_t num_children = parent->children->length +
parent->sway_workspace->floating->children->length; parent->sway_workspace->floating->length;
if (num_children == 1) { if (num_children == 1) {
return true; 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 // 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. // launch it as a tiled view in the root of the workspace instead.
if (container_is_floating(target_sibling)) { 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); 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 // 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_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *container = view->swayc; 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 || if (container->parent->layout == L_TABBED ||
container->parent->layout == L_STACKED) { container->parent->layout == L_STACKED) {
if (seat_get_active_child(seat, container->parent) != container) { if (seat_get_active_child(seat, container->parent) != container) {

@ -67,9 +67,7 @@ struct sway_container *workspace_create(struct sway_container *output,
return NULL; return NULL;
} }
swayws->swayc = workspace; swayws->swayc = workspace;
swayws->floating = container_create(C_CONTAINER); swayws->floating = create_list();
swayws->floating->parent = swayws->swayc;
swayws->floating->layout = L_FLOATING;
swayws->output_priority = create_list(); swayws->output_priority = create_list();
workspace->sway_workspace = swayws; workspace->sway_workspace = swayws;
workspace_output_add_priority(workspace, output); 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 = workspace->parent;
struct sway_container *next_output_prev_ws = struct sway_container *next_output_prev_ws =
seat_get_active_child(seat, next_output); seat_get_active_child(seat, next_output);
struct sway_container *floating = list_t *floating = next_output_prev_ws->sway_workspace->floating;
next_output_prev_ws->sway_workspace->floating;
bool has_sticky = false; bool has_sticky = false;
if (workspace != next_output_prev_ws) { if (workspace != next_output_prev_ws) {
for (int i = 0; i < floating->children->length; ++i) { for (int i = 0; i < floating->length; ++i) {
struct sway_container *floater = floating->children->items[i]; struct sway_container *floater = floating->items[i];
if (floater->is_sticky) { if (floater->is_sticky) {
has_sticky = true; has_sticky = true;
container_remove_child(floater); container_remove_child(floater);
container_add_child(workspace->sway_workspace->floating, workspace_add_floating(workspace, floater);
floater);
if (floater == focus) { if (floater == focus) {
seat_set_focus(seat, NULL); seat_set_focus(seat, NULL);
seat_set_focus(seat, floater); seat_set_focus(seat, floater);
@ -455,9 +451,9 @@ bool workspace_is_empty(struct sway_container *ws) {
return false; return false;
} }
// Sticky views are not considered to be part of this workspace // Sticky views are not considered to be part of this workspace
struct sway_container *floating = ws->sway_workspace->floating; list_t *floating = ws->sway_workspace->floating;
for (int i = 0; i < floating->children->length; ++i) { for (int i = 0; i < floating->length; ++i) {
struct sway_container *floater = floating->children->items[i]; struct sway_container *floater = floating->items[i];
if (!floater->is_sticky) { if (!floater->is_sticky) {
return false; return false;
} }
@ -548,9 +544,9 @@ void workspace_for_each_container(struct sway_container *ws,
container_for_each_child(container, f, data); container_for_each_child(container, f, data);
} }
// Floating // 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 = struct sway_container *container =
ws->sway_workspace->floating->children->items[i]; ws->sway_workspace->floating->items[i];
f(container, data); f(container, data);
container_for_each_child(container, f, data); container_for_each_child(container, f, data);
} }
@ -573,9 +569,8 @@ struct sway_container *workspace_find_container(struct sway_container *ws,
} }
} }
// Floating // 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 *child = struct sway_container *child = ws->sway_workspace->floating->items[i];
ws->sway_workspace->floating->children->items[i];
if (test(child, data)) { if (test(child, data)) {
return child; return child;
} }
@ -597,3 +592,18 @@ struct sway_container *workspace_wrap_children(struct sway_container *ws) {
container_add_child(ws, middle); container_add_child(ws, middle);
return 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);
}

Loading…
Cancel
Save