Fix workspace assignements after output changes

Fix #4261

The previous method was modifying the same list it was iterating upon
causing an erronous iteration and thus not every workspace got assigned
back to were they should (only the first one).
This commit is contained in:
Anaël Beutot
2020-12-29 21:45:39 +01:00
committed by Michael Stapelberg
parent e6af0a5427
commit 0c09bc24ff

View File

@ -439,29 +439,32 @@ void init_ws_for_output(Output *output) {
Con *previous_focus = con_get_workspace(focused); Con *previous_focus = con_get_workspace(focused);
/* Iterate over all workspaces and check if any of them should be assigned /* Iterate over all workspaces and check if any of them should be assigned
* to this output. */ * to this output.
Con *output_con; * Note: in order to do that we iterate over all_cons and not using another
TAILQ_FOREACH (output_con, &(croot->nodes_head), nodes) { * list that would be updated during iteration by the
if (con_is_internal(output_con)) { * workspace_move_to_output function. */
Con *workspace;
TAILQ_FOREACH (workspace, &all_cons, all_cons) {
if (workspace->type != CT_WORKSPACE || con_is_internal(workspace)) {
continue; continue;
} }
Con *workspace;
TAILQ_FOREACH (workspace, &(output_get_content(output_con)->nodes_head), nodes) {
Con *workspace_out = get_assigned_output(workspace->name, workspace->num); Con *workspace_out = get_assigned_output(workspace->name, workspace->num);
if (output->con != workspace_out) { if (output->con != workspace_out) {
continue; continue;
} }
DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n", DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
workspace->name, workspace_out->name, output_primary_name(output)); workspace->name, output_primary_name(get_output_for_con(workspace)),
output_primary_name(output));
/* Need to copy output's rect since content is not yet rendered. We /* Need to copy output's rect since content is not yet rendered. We
* can't call render_con here because render_output only proceeds * can't call render_con here because render_output only proceeds
* if a workspace exists. */ * if a workspace exists. */
content->rect = output->con->rect; content->rect = output->con->rect;
workspace_move_to_output(workspace, output); workspace_move_to_output(workspace, output);
} }
}
/* Temporarily set the focused container, might not be initialized yet. */ /* Temporarily set the focused container, might not be initialized yet. */
focused = content; focused = content;