From d785dab5fd284e3420fa09c3a004740dd05ed934 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Mon, 12 Apr 2021 23:37:53 -0400 Subject: [PATCH] wayland: Add unscaled resolutions to the display mode list --- src/video/wayland/SDL_waylandvideo.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 0608f0fd6..e6dec5e53 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -265,12 +265,32 @@ display_handle_mode(void *data, { SDL_VideoDisplay *display = data; SDL_WaylandOutputData* driverdata = display->driverdata; + SDL_DisplayMode mode; if (flags & WL_OUTPUT_MODE_CURRENT) { driverdata->width = width; driverdata->height = height; driverdata->refresh = refresh; } + + /* Note that the width/height are NOT multiplied by scale_factor! + * This is intentional and is designed to get the unscaled modes, which is + * important for high-DPI games intending to use the display mode as the + * target drawable size. The scaled desktop mode will be added at the end + * when display_handle_done is called (see below). + */ + SDL_zero(mode); + mode.format = SDL_PIXELFORMAT_RGB888; + if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) { + mode.w = height; + mode.h = width; + } else { + mode.w = width; + mode.h = height; + } + mode.refresh_rate = refresh / 1000; /* mHz to Hz */ + mode.driverdata = driverdata->output; + SDL_AddDisplayMode(display, &mode); } static void @@ -288,13 +308,14 @@ display_handle_done(void *data, SDL_zero(mode); mode.format = SDL_PIXELFORMAT_RGB888; - mode.w = driverdata->width / driverdata->scale_factor; - mode.h = driverdata->height / driverdata->scale_factor; if (driverdata->transform & WL_OUTPUT_TRANSFORM_90) { mode.w = driverdata->height / driverdata->scale_factor; mode.h = driverdata->width / driverdata->scale_factor; + } else { + mode.w = driverdata->width / driverdata->scale_factor; + mode.h = driverdata->height / driverdata->scale_factor; } - mode.refresh_rate = driverdata->refresh / 1000; // mHz to Hz + mode.refresh_rate = driverdata->refresh / 1000; /* mHz to Hz */ mode.driverdata = driverdata->output; SDL_AddDisplayMode(display, &mode); display->current_mode = mode;