init_ws_for_output: Change loop that assigns existing workspaces
I find the new loop more straightforward and easy to understand. Old loop used to be: foreach assignment: foreach assignment2: // find if this is the first valid output in this assignment foreach workspace: // find matching by assignment name if workspace: move workspace to output New loop is: foreach workspace: foreach assignment: if workspace is assigned to this output: move workspace to output With this, workspace assignments triggered by numbers during output changes should be handled correctly. Fixes #3685
This commit is contained in:
46
src/randr.c
46
src/randr.c
@ -438,34 +438,29 @@ void init_ws_for_output(Output *output) {
|
||||
Con *content = output_get_content(output->con);
|
||||
Con *previous_focus = con_get_workspace(focused);
|
||||
|
||||
/* go through all assignments and move the existing workspaces to this output */
|
||||
struct Workspace_Assignment *assignment;
|
||||
TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) {
|
||||
if (!output_triggers_assignment(output, assignment)) {
|
||||
continue;
|
||||
}
|
||||
Con *workspace = get_existing_workspace_by_name(assignment->name);
|
||||
if (workspace == NULL)
|
||||
continue;
|
||||
|
||||
/* check that this workspace is not already attached (that means the
|
||||
* user configured this assignment twice) */
|
||||
Con *workspace_out = con_get_output(workspace);
|
||||
if (workspace_out == output->con) {
|
||||
LOG("Workspace \"%s\" assigned to output \"%s\", but it is already "
|
||||
"there. Do you have two assignment directives for the same "
|
||||
"workspace in your configuration file?\n",
|
||||
workspace->name, output_primary_name(output));
|
||||
/* Iterate over all workspaces and check if any of them should be assigned
|
||||
* to this output. */
|
||||
Con *output_con;
|
||||
TAILQ_FOREACH (output_con, &(croot->nodes_head), nodes) {
|
||||
if (con_is_internal(output_con)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
|
||||
workspace->name, workspace_out->name, output_primary_name(output));
|
||||
/* Need to copy output's rect since content is not yet rendered. We
|
||||
* can't call render_con here because render_output only proceeds if a
|
||||
* workspace exists. */
|
||||
content->rect = output->con->rect;
|
||||
workspace_move_to_output(workspace, output);
|
||||
Con *workspace;
|
||||
TAILQ_FOREACH (workspace, &(output_get_content(output_con)->nodes_head), nodes) {
|
||||
Con *workspace_out = get_assigned_output(workspace->name, workspace->num);
|
||||
if (output->con != workspace_out) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
|
||||
workspace->name, workspace_out->name, output_primary_name(output));
|
||||
/* Need to copy output's rect since content is not yet rendered. We
|
||||
* can't call render_con here because render_output only proceeds
|
||||
* if a workspace exists. */
|
||||
content->rect = output->con->rect;
|
||||
workspace_move_to_output(workspace, output);
|
||||
}
|
||||
}
|
||||
|
||||
/* Temporarily set the focused container, might not be initialized yet. */
|
||||
@ -485,6 +480,7 @@ void init_ws_for_output(Output *output) {
|
||||
}
|
||||
|
||||
/* otherwise, we create the first assigned ws for this output */
|
||||
struct Workspace_Assignment *assignment;
|
||||
TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) {
|
||||
if (!output_triggers_assignment(output, assignment)) {
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user