x11: Don't let XRRSetScreenSize fire a BadMatch error.

This is a workaround and not a proper fix, but this is possibly complicated,
and possibly a corner case, so this will do for 2.0.16, if not the
foreseeable future.

Reference issue #4561
This commit is contained in:
Ryan C. Gordon 2021-07-31 15:56:30 -04:00
parent 3a4b217d6c
commit d0effadf68
No known key found for this signature in database
GPG key ID: FA148B892AB48044

View file

@ -995,6 +995,15 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
}
}
/* This catches an error from XRRSetScreenSize, as a workaround for now. */
/* !!! FIXME: remove this later when we have a better solution. */
static int (*PreXRRSetScreenSizeErrorHandler)(Display *, XErrorEvent *) = NULL;
static int
SDL_XRRSetScreenSizeErrHandler(Display *d, XErrorEvent *e)
{
return (e->error_code == BadMatch) ? 0 : PreXRRSetScreenSizeErrorHandler(d, e);
}
int
X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode)
{
@ -1040,7 +1049,17 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode
mm_width = mode->w * DisplayWidthMM(display, data->screen) / DisplayWidth(display, data->screen);
mm_height = mode->h * DisplayHeightMM(display, data->screen) / DisplayHeight(display, data->screen);
/* !!! FIXME: this can get into a problem scenario when a window is
bigger than a physical monitor in a configuration where one screen
spans multiple physical monitors. A detailed reproduction case is
discussed at https://github.com/libsdl-org/SDL/issues/4561 ...
for now we cheat and just catch the X11 error and carry on, which
is likely to cause subtle issues but is better than outright
crashing */
PreXRRSetScreenSizeErrorHandler = X11_XSetErrorHandler(SDL_XRRSetScreenSizeErrHandler);
X11_XRRSetScreenSize(display, RootWindow(display, data->screen), mode->w, mode->h, mm_width, mm_height);
X11_XSetErrorHandler(PreXRRSetScreenSizeErrorHandler);
status = X11_XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,