From d5f5885c941d9f74f131734b253133108c759e20 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 10 Jul 2020 18:04:45 +0200 Subject: config/output: don't change output state before commit Previously, we called output_disable prior to wlr_output_commit. This mutates Sway's output state before the output commit actually succeeds. This results in Sway's state getting out-of-sync with wlroots'. An alternative fix [1] was to revert the changes made by output_disable in case of failure. This is a little complicated. Instead, this patch makes it so Sway's internal state is never changed before a successful wlr_output commit. We had two output flags: enabled and configured. However enabled was set prior to the output becoming enabled, and was used to prevent the output event handlers (specifically, the mode handler) from calling apply_output_config again (infinite loop). Rename enabled to enabling and use it exclusively for this purpose. Rename configure to enabled, because that's what it really means. [1]: https://github.com/swaywm/sway/pull/5521 Closes: https://github.com/swaywm/sway/issues/5483 (cherry picked from commit 5432f00adfdd8375fb422ad9033253d17f04efc7) --- sway/config/output.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'sway/config/output.c') diff --git a/sway/config/output.c b/sway/config/output.c index 68aafbe1..b59cabd4 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -397,17 +397,8 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { struct wlr_output *wlr_output = output->wlr_output; - bool was_enabled = output->enabled; - if (oc && !oc->enabled) { - // Output is configured to be disabled - sway_log(SWAY_DEBUG, "Disabling output %s", oc->name); - if (output->enabled) { - output_disable(output); - wlr_output_layout_remove(root->output_layout, wlr_output); - } - } else { - output->enabled = true; - } + // Flag to prevent the output mode event handler from calling us + output->enabling = (!oc || oc->enabled); queue_output_config(oc, output); @@ -421,11 +412,18 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { // Leave the output disabled for now and try again when the output gets // the mode we asked for. sway_log(SWAY_ERROR, "Failed to commit output %s", wlr_output->name); - output->enabled = was_enabled; + output->enabling = false; return false; } + output->enabling = false; + if (oc && !oc->enabled) { + sway_log(SWAY_DEBUG, "Disabling output %s", oc->name); + if (output->enabled) { + output_disable(output); + wlr_output_layout_remove(root->output_layout, wlr_output); + } return true; } @@ -468,8 +466,8 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { output->width = output_box->width; output->height = output_box->height; - if (!output->configured) { - output_configure(output); + if (!output->enabled) { + output_enable(output); } if (oc && oc->max_render_time >= 0) { -- cgit v1.2.3-54-g00ecf