wayland: Swap emulated mode dimensions in more cases Some compositors (GNOME for example) don't set the transform flag when dealing with portrait mode displays, so the video modes won't have the width/height swapped in all cases where they should be. Check for both the 90/270 degree transform flag and if the display is taller than it is wide when determining whether to swap the width and height of the emulated video modes, and adjust the comparison logic when size testing against the native mode to account for this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 4698cc5..15349b2 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -416,23 +416,25 @@ AddEmulatedModes(SDL_VideoDisplay *dpy, SDL_bool rot_90)
};
int i;
+ SDL_DisplayMode mode;
const int native_width = dpy->display_modes->w;
const int native_height = dpy->display_modes->h;
for (i = 0; i < SDL_arraysize(mode_list); ++i) {
- /* Only add modes that are smaller than the native mode */
- if ((mode_list[i].w < native_width && mode_list[i].h < native_height) ||
- (mode_list[i].w < native_width && mode_list[i].h == native_height)) {
- SDL_DisplayMode mode = *dpy->display_modes;
-
- if (rot_90) {
- mode.w = mode_list[i].h;
- mode.h = mode_list[i].w;
- } else {
- mode.w = mode_list[i].w;
- mode.h = mode_list[i].h;
- }
+ mode = *dpy->display_modes;
+
+ if (rot_90) {
+ mode.w = mode_list[i].h;
+ mode.h = mode_list[i].w;
+ } else {
+ mode.w = mode_list[i].w;
+ mode.h = mode_list[i].h;
+ }
+ /* Only add modes that are smaller than the native mode. */
+ if ((mode.w < native_width && mode.h < native_height) ||
+ (mode.w < native_width && mode.h == native_height) ||
+ (mode.w == native_width && mode.h < native_height)) {
SDL_AddDisplayMode(dpy, &mode);
}
}
@@ -646,7 +648,9 @@ display_handle_done(void *data,
/* Add emulated modes if wp_viewporter is supported and mode emulation is enabled. */
if (video->viewporter && mode_emulation_enabled) {
- AddEmulatedModes(dpy, (driverdata->transform & WL_OUTPUT_TRANSFORM_90) != 0);
+ const SDL_bool rot_90 = ((driverdata->transform & WL_OUTPUT_TRANSFORM_90) != 0) ||
+ (driverdata->width < driverdata->height);
+ AddEmulatedModes(dpy, rot_90);
}
if (driverdata->index == -1) {