From a2eb2697a30695ed71c5983fdc0652e68dd0c061 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Wed, 17 Apr 2024 10:51:33 -0400 Subject: [PATCH] x11: Fix mode switching when running under XWayland XWayland emulates the XRandR interface, so it still needs the actual mode switch call to trigger the mode switching emulation. There is also no need to wait when using XWayland mode switching emulation, as it is handled via viewport scaling and thus instantaneous. --- src/video/SDL_video.c | 7 +++++-- src/video/x11/SDL_x11modes.c | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 738c017b2..962057f86 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1248,8 +1248,11 @@ const SDL_DisplayMode *SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - /* Mode switching is being emulated per-window; nothing to do and cannot fail. */ - if (SDL_ModeSwitchingEmulated(_this)) { + /* Mode switching is being emulated per-window; nothing to do and cannot fail, + * except for XWayland, which still needs the actual mode setting call since + * it's emulated via the XRandR interface. + */ + if (SDL_ModeSwitchingEmulated(_this) && SDL_strcmp(_this->name, "x11") != 0) { return 0; } diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index fc324717f..a36efe4fe 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -921,10 +921,13 @@ int X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SD viddata->last_mode_change_deadline = SDL_GetTicks() + (PENDING_FOCUS_TIME * 2); - if (sdl_display->current_mode != mode) { - data->mode_switch_deadline_ns = SDL_GetTicksNS() + MODE_SWITCH_TIMEOUT_NS; - } else { - data->mode_switch_deadline_ns = 0; + /* XWayland mode switches are emulated with viewports and thus instantaneous. */ + if (!viddata->is_xwayland) { + if (sdl_display->current_mode != mode) { + data->mode_switch_deadline_ns = SDL_GetTicksNS() + MODE_SWITCH_TIMEOUT_NS; + } else { + data->mode_switch_deadline_ns = 0; + } } #ifdef SDL_VIDEO_DRIVER_X11_XRANDR