sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 4cdc4ac63aeb7f5e17c42ad3317978bd31e1fde2
parent f67ed6772c27d7ba163e8caa3c9eb8481712a716
Author: Simon Ser <contact@emersion.fr>
Date:   Fri, 30 Jul 2021 23:00:10 +0200

Fallback to other output modes if preferred mode fails

Sometimes the preferred mode is not available due to hardware
constraints (e.g. GPU or cable bandwidth limitations). In these
cases it's better to fallback to lower modes than to end up with
a black screen.

Diffstat:
Msway/config/output.c | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/sway/config/output.c b/sway/config/output.c @@ -357,8 +357,26 @@ static void queue_output_config(struct output_config *oc, set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate, oc->custom_mode == 1); } else if (!wl_list_empty(&wlr_output->modes)) { - struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); - wlr_output_set_mode(wlr_output, mode); + sway_log(SWAY_DEBUG, "Set preferred mode"); + struct wlr_output_mode *preferred_mode = + wlr_output_preferred_mode(wlr_output); + wlr_output_set_mode(wlr_output, preferred_mode); + + if (!wlr_output_test(wlr_output)) { + 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_set_mode(wlr_output, mode); + if (wlr_output_test(wlr_output)) { + break; + } + } + } } if (oc && (oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN || config->reloading)) {