Skip to content

Commit

Permalink
x11: Fix mode switching when running under XWayland
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kontrabant committed Apr 17, 2024
1 parent bed6c5b commit a2eb269
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/video/SDL_video.c
Expand Up @@ -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;
}

Expand Down
11 changes: 7 additions & 4 deletions src/video/x11/SDL_x11modes.c
Expand Up @@ -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
Expand Down

0 comments on commit a2eb269

Please sign in to comment.