diff options
-rw-r--r-- | sway/config/output.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/sway/config/output.c b/sway/config/output.c index 0985b0e8..eefde22b 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -249,6 +249,8 @@ static void set_mode(struct wlr_output *output, struct wlr_output_state *pending | |||
249 | // as (int)(1000 * mHz / 1000.f) | 249 | // as (int)(1000 * mHz / 1000.f) |
250 | // round() the result to avoid any error | 250 | // round() the result to avoid any error |
251 | int mhz = (int)roundf(refresh_rate * 1000); | 251 | int mhz = (int)roundf(refresh_rate * 1000); |
252 | // If no target refresh rate is given, match highest available | ||
253 | mhz = mhz <= 0 ? INT_MAX : mhz; | ||
252 | 254 | ||
253 | if (wl_list_empty(&output->modes) || custom) { | 255 | if (wl_list_empty(&output->modes) || custom) { |
254 | sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name); | 256 | sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name); |
@@ -258,23 +260,28 @@ static void set_mode(struct wlr_output *output, struct wlr_output_state *pending | |||
258 | } | 260 | } |
259 | 261 | ||
260 | struct wlr_output_mode *mode, *best = NULL; | 262 | struct wlr_output_mode *mode, *best = NULL; |
263 | int best_diff_mhz = INT_MAX; | ||
261 | wl_list_for_each(mode, &output->modes, link) { | 264 | wl_list_for_each(mode, &output->modes, link) { |
262 | if (mode->width == width && mode->height == height) { | 265 | if (mode->width == width && mode->height == height) { |
263 | if (mode->refresh == mhz) { | 266 | int diff_mhz = abs(mode->refresh - mhz); |
264 | best = mode; | 267 | if (diff_mhz < best_diff_mhz) { |
265 | break; | 268 | best_diff_mhz = diff_mhz; |
266 | } | ||
267 | if (best == NULL || mode->refresh > best->refresh) { | ||
268 | best = mode; | 269 | best = mode; |
270 | if (best_diff_mhz == 0) { | ||
271 | break; | ||
272 | } | ||
269 | } | 273 | } |
270 | } | 274 | } |
271 | } | 275 | } |
272 | if (!best) { | 276 | if (best) { |
273 | sway_log(SWAY_ERROR, "Configured mode for %s not available", output->name); | 277 | sway_log(SWAY_INFO, "Assigning configured mode (%dx%d@%.3fHz) to %s", |
274 | sway_log(SWAY_INFO, "Picking preferred mode instead"); | 278 | best->width, best->height, best->refresh / 1000.f, output->name); |
275 | best = wlr_output_preferred_mode(output); | ||
276 | } else { | 279 | } else { |
277 | sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name); | 280 | best = wlr_output_preferred_mode(output); |
281 | sway_log(SWAY_INFO, "Configured mode (%dx%d@%.3fHz) not available, " | ||
282 | "applying preferred mode (%dx%d@%.3fHz)", | ||
283 | width, height, refresh_rate, | ||
284 | best->width, best->height, best->refresh / 1000.f); | ||
278 | } | 285 | } |
279 | wlr_output_state_set_mode(pending, best); | 286 | wlr_output_state_set_mode(pending, best); |
280 | } | 287 | } |