wayland: estimate scaled (logical) width/height, if not provided

This makes us slightly more resilient against a missing XDG output
interface.

We use the “real” (the physical) dimensions, combined with the scaling
factor, to estimate the logical dimensions.

This works out correctly with  non-fractional scaling, but not
otherwise.
This commit is contained in:
Daniel Eklöf 2021-12-13 19:15:17 +01:00
parent fe851a6936
commit 97174913e0
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -385,13 +385,19 @@ output_update_ppi(struct monitor *mon)
break;
}
mon->ppi.scaled.x = mon->dim.px_scaled.width / x_inches;
mon->ppi.scaled.y = mon->dim.px_scaled.height / y_inches;
int scaled_width = mon->dim.px_scaled.width;
int scaled_height = mon->dim.px_scaled.height;
float px_diag = sqrt(
pow(mon->dim.px_scaled.width, 2) +
pow(mon->dim.px_scaled.height, 2));
if (scaled_width == 0 && scaled_height == 0 && mon->scale > 0) {
/* Estimate scaled width/height if none has been provided */
scaled_width = mon->dim.px_real.width / mon->scale;
scaled_height = mon->dim.px_real.height / mon->scale;
}
mon->ppi.scaled.x = scaled_width / x_inches;
mon->ppi.scaled.y = scaled_height / y_inches;
float px_diag = sqrt(pow(scaled_width, 2) + pow(scaled_height, 2));
mon->dpi = px_diag / mon->inch * mon->scale;
}