From 49eeee387bbb4977c6486e6aa797074bad177513 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Fri, 27 Dec 2024 16:05:40 -0500 Subject: [PATCH] output: handle outputs that are enabled but not yet added output_config_apply() currently assumes that any enabled outputs have already been added to the wlr_output_layout. However, at startup, wlroots will report that outputs are enabled if they were previously in use by e.g. the Linux console - but they are not yet in the layout. output_config_apply() never encountered this case before now because the initial modeset was performed by another code path, but now with the new autoEnableOutputs option (next commit), it needs to be able to handle the initial modeset as well. --- src/output.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/output.c b/src/output.c index 821b5094..a75f6e13 100644 --- a/src/output.c +++ b/src/output.c @@ -565,8 +565,6 @@ output_config_apply(struct server *server, struct output *output = output_from_wlr_output(server, o); struct wlr_output_state *os = &output->pending; bool output_enabled = head->state.enabled && !output->leased; - bool need_to_add = output_enabled && !o->enabled; - bool need_to_remove = !output_enabled && o->enabled; wlr_output_state_set_enabled(os, output_enabled); if (output_enabled) { @@ -601,12 +599,19 @@ output_config_apply(struct server *server, break; } - /* Only do Layout specific actions if the commit went trough */ - if (need_to_add) { - add_output_to_layout(server, output); - } + /* + * Add or remove output from layout only if the commit went + * through. Note that at startup, the output may have already + * been enabled but not yet been added to the layout. + */ + bool was_in_layout = + !!wlr_output_layout_get(server->output_layout, o); if (output_enabled) { + if (!was_in_layout) { + add_output_to_layout(server, output); + } + struct wlr_box pos = {0}; wlr_output_layout_get_box(server->output_layout, o, &pos); if (pos.x != head->state.x || pos.y != head->state.y) { @@ -618,9 +623,7 @@ output_config_apply(struct server *server, wlr_output_layout_add(server->output_layout, o, head->state.x, head->state.y); } - } - - if (need_to_remove) { + } else if (was_in_layout) { regions_evacuate_output(output); lab_cosmic_workspace_group_output_leave(