From d4de4cbe57dedbe07b0ea8a14aea31eb07a41c3f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 15 Nov 2023 18:07:25 +0100 Subject: [PATCH 1/5] config/output: avoid no-op enabled output change Ensure that allow_reconfiguration is always set even if we skip the enabled change. --- sway/config/output.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sway/config/output.c b/sway/config/output.c index eefde22b6..36028ad3f 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -392,14 +392,18 @@ static void queue_output_config(struct output_config *oc, struct wlr_output *wlr_output = output->wlr_output; - if (oc && (!oc->enabled || oc->power == 0)) { - sway_log(SWAY_DEBUG, "Turning off output %s", wlr_output->name); - wlr_output_state_set_enabled(pending, false); - return; + pending->allow_reconfiguration = true; + + bool enabled = !oc || (oc->enabled != 0 && oc->power != 0); + if (wlr_output->enabled != enabled) { + sway_log(SWAY_DEBUG, "Turning %s output %s", + enabled ? "on" : "off", wlr_output->name); + wlr_output_state_set_enabled(pending, enabled); } - sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name); - wlr_output_state_set_enabled(pending, true); + if (!enabled) { + return; + } if (oc && oc->drm_mode.type != 0 && oc->drm_mode.type != (uint32_t) -1) { sway_log(SWAY_DEBUG, "Set %s modeline", From 5b72fccb677b42e5435e86e60825cda3ab200056 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 15 Nov 2023 18:18:15 +0100 Subject: [PATCH 2/5] config/output: skip no-op preferred mode change --- sway/config/output.c | 49 ++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/sway/config/output.c b/sway/config/output.c index 36028ad3f..a99842581 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -303,6 +303,34 @@ static void set_modeline(struct wlr_output *output, #endif } +static void set_preferred_mode(struct wlr_output *wlr_output, + struct wlr_output_state *pending) { + struct wlr_output_mode *preferred_mode = + wlr_output_preferred_mode(wlr_output); + if (wlr_output->current_mode == preferred_mode) { + return; + } + + sway_log(SWAY_DEBUG, "Set %s preferred mode", wlr_output->name); + wlr_output_state_set_mode(pending, preferred_mode); + + if (!wlr_output_test_state(wlr_output, pending)) { + sway_log(SWAY_DEBUG, "Preferred mode rejected, " + "falling back to another mode"); + struct wlr_output_mode *mode; + wl_list_for_each(mode, &wlr_output->modes, link) { + if (mode == preferred_mode) { + continue; + } + + wlr_output_state_set_mode(pending, mode); + if (wlr_output_test_state(wlr_output, pending)) { + break; + } + } + } +} + /* Some manufacturers hardcode the aspect-ratio of the output in the physical * size field. */ static bool phys_size_is_aspect_ratio(struct wlr_output *output) { @@ -415,26 +443,7 @@ static void queue_output_config(struct output_config *oc, set_mode(wlr_output, pending, oc->width, oc->height, oc->refresh_rate, oc->custom_mode == 1); } else if (!wl_list_empty(&wlr_output->modes)) { - sway_log(SWAY_DEBUG, "Set preferred mode"); - struct wlr_output_mode *preferred_mode = - wlr_output_preferred_mode(wlr_output); - wlr_output_state_set_mode(pending, preferred_mode); - - if (!wlr_output_test_state(wlr_output, pending)) { - sway_log(SWAY_DEBUG, "Preferred mode rejected, " - "falling back to another mode"); - struct wlr_output_mode *mode; - wl_list_for_each(mode, &wlr_output->modes, link) { - if (mode == preferred_mode) { - continue; - } - - wlr_output_state_set_mode(pending, mode); - if (wlr_output_test_state(wlr_output, pending)) { - break; - } - } - } + set_preferred_mode(wlr_output, pending); } if (oc && (oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN || config->reloading)) { From b03d8f685e17f8d37b9be60368cf81732c6977a0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 15 Nov 2023 18:21:06 +0100 Subject: [PATCH 3/5] config/output: skip no-op modeline change --- sway/config/output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/config/output.c b/sway/config/output.c index a99842581..c8f581204 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -293,9 +293,9 @@ static void set_modeline(struct wlr_output *output, sway_log(SWAY_ERROR, "Modeline can only be set to DRM output"); return; } - sway_log(SWAY_DEBUG, "Assigning custom modeline to %s", output->name); struct wlr_output_mode *mode = wlr_drm_connector_add_mode(output, drm_mode); - if (mode) { + if (mode && output->current_mode != mode) { + sway_log(SWAY_DEBUG, "Assigning custom modeline to %s", output->name); wlr_output_state_set_mode(pending, mode); } #else From 80b7b149250ea76f89a053a4032f0afeb3c3f53f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 15 Nov 2023 18:21:50 +0100 Subject: [PATCH 4/5] output/config: skip no-op fixed mode change --- sway/config/output.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sway/config/output.c b/sway/config/output.c index c8f581204..1fba8db96 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -274,6 +274,9 @@ static void set_mode(struct wlr_output *output, struct wlr_output_state *pending } } if (best) { + if (best == output->current_mode) { + return; + } sway_log(SWAY_INFO, "Assigning configured mode (%dx%d@%.3fHz) to %s", best->width, best->height, best->refresh / 1000.f, output->name); } else { From eb7cfbf8e4c5f764cf023d16d19737221c93825d Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 16 Nov 2023 00:34:50 +0100 Subject: [PATCH 5/5] wip --- sway/config/output.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sway/config/output.c b/sway/config/output.c index 1fba8db96..87e8e5c6d 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -493,7 +493,8 @@ static void queue_output_config(struct output_config *oc, wlr_output_state_set_scale(pending, scale); } - if (oc && oc->adaptive_sync != -1) { + bool cur_adaptive_sync = wlr_output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED; + if (oc && oc->adaptive_sync != -1 && oc->adaptive_sync != cur_adaptive_sync) { sway_log(SWAY_DEBUG, "Set %s adaptive sync to %d", wlr_output->name, oc->adaptive_sync); wlr_output_state_set_adaptive_sync_enabled(pending, oc->adaptive_sync == 1); @@ -533,8 +534,17 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { struct wlr_output_state pending = {0}; queue_output_config(oc, output, &pending); - sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); - if (!wlr_output_commit_state(wlr_output, &pending)) { + sway_log(SWAY_DEBUG, "HEY 0x%x", pending.committed); + + bool ok; + if (pending.committed == 0 && wlr_output->commit_seq != 0) { + sway_log(SWAY_DEBUG, "Skipping no-op commit for output %s", wlr_output->name); + ok = true; + } else { + sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); + ok = wlr_output_commit_state(wlr_output, &pending); + } + if (!ok) { // Failed to commit output changes, maybe the output is missing a CRTC. // Leave the output disabled for now and try again when the output gets // the mode we asked for.