diff options
author | 2020-02-10 18:42:45 +0100 | |
---|---|---|
committer | 2020-02-11 20:52:02 -0500 | |
commit | 555b0d408706a4eddc75d04f58f7f1e84dc409e8 (patch) | |
tree | 522a8aae57cc3e6f6878e60ff1e8dfa6ddd0f5e6 | |
parent | config: fix validation exit code and log level (diff) | |
download | sway-555b0d408706a4eddc75d04f58f7f1e84dc409e8.tar.gz sway-555b0d408706a4eddc75d04f58f7f1e84dc409e8.tar.zst sway-555b0d408706a4eddc75d04f58f7f1e84dc409e8.zip |
Fix output scale auto-detection
Closes: https://github.com/swaywm/sway/issues/4960
-rw-r--r-- | sway/config/output.c | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/sway/config/output.c b/sway/config/output.c index ec21b512..e1925c93 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -283,8 +283,28 @@ static bool phys_size_is_aspect_ratio(struct wlr_output *output) { | |||
283 | #define MM_PER_INCH 25.4 | 283 | #define MM_PER_INCH 25.4 |
284 | 284 | ||
285 | static int compute_default_scale(struct wlr_output *output) { | 285 | static int compute_default_scale(struct wlr_output *output) { |
286 | int width, height; | 286 | struct wlr_box box = { .width = output->width, .height = output->height }; |
287 | wlr_output_transformed_resolution(output, &width, &height); | 287 | if (output->pending.committed & WLR_OUTPUT_STATE_MODE) { |
288 | switch (output->pending.mode_type) { | ||
289 | case WLR_OUTPUT_STATE_MODE_FIXED: | ||
290 | box.width = output->pending.mode->width; | ||
291 | box.height = output->pending.mode->height; | ||
292 | break; | ||
293 | case WLR_OUTPUT_STATE_MODE_CUSTOM: | ||
294 | box.width = output->pending.custom_mode.width; | ||
295 | box.height = output->pending.custom_mode.height; | ||
296 | break; | ||
297 | } | ||
298 | } | ||
299 | enum wl_output_transform transform = output->transform; | ||
300 | if (output->pending.committed & WLR_OUTPUT_STATE_TRANSFORM) { | ||
301 | transform = output->pending.transform; | ||
302 | } | ||
303 | wlr_box_transform(&box, &box, transform, box.width, box.height); | ||
304 | |||
305 | int width = box.width; | ||
306 | int height = box.height; | ||
307 | |||
288 | if (height < HIDPI_MIN_HEIGHT) { | 308 | if (height < HIDPI_MIN_HEIGHT) { |
289 | return 1; | 309 | return 1; |
290 | } | 310 | } |
@@ -349,18 +369,6 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { | |||
349 | output->current_mode = wlr_output->pending.mode; | 369 | output->current_mode = wlr_output->pending.mode; |
350 | } | 370 | } |
351 | 371 | ||
352 | float scale; | ||
353 | if (oc && oc->scale > 0) { | ||
354 | scale = oc->scale; | ||
355 | } else { | ||
356 | scale = compute_default_scale(wlr_output); | ||
357 | sway_log(SWAY_DEBUG, "Auto-detected output scale: %f", scale); | ||
358 | } | ||
359 | if (scale != wlr_output->scale) { | ||
360 | sway_log(SWAY_DEBUG, "Set %s scale to %f", oc->name, scale); | ||
361 | wlr_output_set_scale(wlr_output, scale); | ||
362 | } | ||
363 | |||
364 | if (oc) { | 372 | if (oc) { |
365 | enum scale_filter_mode scale_filter_old = output->scale_filter; | 373 | enum scale_filter_mode scale_filter_old = output->scale_filter; |
366 | switch (oc->scale_filter) { | 374 | switch (oc->scale_filter) { |
@@ -393,6 +401,20 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) { | |||
393 | wlr_output_set_transform(wlr_output, oc->transform); | 401 | wlr_output_set_transform(wlr_output, oc->transform); |
394 | } | 402 | } |
395 | 403 | ||
404 | // Apply the scale last before the commit, because the scale auto-detection | ||
405 | // reads the pending output size | ||
406 | float scale; | ||
407 | if (oc && oc->scale > 0) { | ||
408 | scale = oc->scale; | ||
409 | } else { | ||
410 | scale = compute_default_scale(wlr_output); | ||
411 | sway_log(SWAY_DEBUG, "Auto-detected output scale: %f", scale); | ||
412 | } | ||
413 | if (scale != wlr_output->scale) { | ||
414 | sway_log(SWAY_DEBUG, "Set %s scale to %f", oc->name, scale); | ||
415 | wlr_output_set_scale(wlr_output, scale); | ||
416 | } | ||
417 | |||
396 | sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); | 418 | sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); |
397 | if (!wlr_output_commit(wlr_output)) { | 419 | if (!wlr_output_commit(wlr_output)) { |
398 | // Failed to modeset, maybe the output is missing a CRTC. Leave the | 420 | // Failed to modeset, maybe the output is missing a CRTC. Leave the |