wayland: Fix DPI calculation with scaled outputs

`driverdata->width` and `driverdata->height` represent the width and height in logical pixels on scaled outputs with xdg_output. However, to correctly calculate the display's DPI value, we need to use its native resolution.

For example, on a 27" 4K screen with 175% scaling, we have `width` == 2192 and `height` == 1233, resulting in a bogus value of 92dpi, whereas 162dpi are correct for 3840x2160 pixels at 27 inches.

Tested on GNOME mutter 45.1.
This commit is contained in:
Yussuf Khalil 2023-11-12 13:16:31 +01:00 committed by Frank Praznik
parent f3419d8c04
commit 63e9827b90

View file

@ -619,17 +619,17 @@ static void display_handle_done(void *data,
/* Calculate the display DPI */ /* Calculate the display DPI */
if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) { if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) {
driverdata->hdpi = driverdata->physical_height ? (((float)driverdata->height) * 25.4f / driverdata->physical_height) : 0.0f; driverdata->hdpi = driverdata->physical_height ? (((float)driverdata->native_height) * 25.4f / driverdata->physical_height) : 0.0f;
driverdata->vdpi = driverdata->physical_width ? (((float)driverdata->width) * 25.4f / driverdata->physical_width) : 0.0f; driverdata->vdpi = driverdata->physical_width ? (((float)driverdata->native_width) * 25.4f / driverdata->physical_width) : 0.0f;
driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->height, driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->native_height,
driverdata->width, driverdata->native_width,
((float)driverdata->physical_height) / 25.4f, ((float)driverdata->physical_height) / 25.4f,
((float)driverdata->physical_width) / 25.4f); ((float)driverdata->physical_width) / 25.4f);
} else { } else {
driverdata->hdpi = driverdata->physical_width ? (((float)driverdata->width) * 25.4f / driverdata->physical_width) : 0.0f; driverdata->hdpi = driverdata->physical_width ? (((float)driverdata->native_width) * 25.4f / driverdata->physical_width) : 0.0f;
driverdata->vdpi = driverdata->physical_height ? (((float)driverdata->height) * 25.4f / driverdata->physical_height) : 0.0f; driverdata->vdpi = driverdata->physical_height ? (((float)driverdata->native_height) * 25.4f / driverdata->physical_height) : 0.0f;
driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->width, driverdata->ddpi = SDL_ComputeDiagonalDPI(driverdata->native_width,
driverdata->height, driverdata->native_height,
((float)driverdata->physical_width) / 25.4f, ((float)driverdata->physical_width) / 25.4f,
((float)driverdata->physical_height) / 25.4f); ((float)driverdata->physical_height) / 25.4f);
} }