aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tamino Bauknecht <dev@tb6.eu>2023-10-18 22:30:10 +0200
committerLibravatar Kenny Levinsen <kl@kl.wtf>2023-10-23 11:05:08 +0200
commit0dfaf7ea639570ed8fcbc8c1592740b0791b7705 (patch)
tree5231828e3770fa856dbff3ff238f38e89da3df27
parentgitignore: Ignore clangd-generated directory .cache/ (diff)
downloadsway-0dfaf7ea639570ed8fcbc8c1592740b0791b7705.tar.gz
sway-0dfaf7ea639570ed8fcbc8c1592740b0791b7705.tar.zst
sway-0dfaf7ea639570ed8fcbc8c1592740b0791b7705.zip
config/output: Allow approximation of output refresh rate
Previous behavior was that only if resolution and refresh rate match exactly, the mode was accepted. As fallback, the mode with the highest refresh rate and the same resolution was chosen. New behavior is that the mode with the closest match for the refresh rate is used with a limit of up to 1Hz. The fallback behavior stays the same. Additionally, the logging was made more verbose.
-rw-r--r--sway/config/output.c27
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}