Fix infinite loop when focusing sticky containers via workspace command

In a multi-output setup, if a sticky container is on one output and
focus is on the other output, and you run (eg) `workspace 1` to focus
the workspace containing the sticky container, an infinite loop would
occur. It would loop infinitely because it would remove the sticky
container from the workspace, add it back to the same workspace, and
then decrement the iterator variable.

The fix just wraps the loop in a workspace comparison.
master
Ryan Dwyer 6 years ago
parent 1818c58e40
commit 50f3a7ff5c

@ -411,12 +411,14 @@ bool workspace_switch(struct sway_container *workspace,
struct sway_container *floating = struct sway_container *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) {
for (int i = 0; i < floating->children->length; ++i) { for (int i = 0; i < floating->children->length; ++i) {
struct sway_container *floater = floating->children->items[i]; struct sway_container *floater = floating->children->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, floater); container_add_child(workspace->sway_workspace->floating,
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);
@ -424,6 +426,7 @@ bool workspace_switch(struct sway_container *workspace,
--i; --i;
} }
} }
}
wlr_log(WLR_DEBUG, "Switching to workspace %p:%s", wlr_log(WLR_DEBUG, "Switching to workspace %p:%s",
workspace, workspace->name); workspace, workspace->name);

Loading…
Cancel
Save