X11: Added a test for a weird X11 error we get with Xinerama, rarely.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 30 Jun 2015 15:00:48 -0400
changeset 9789137993bad5c7
parent 9788 ecda7d71342e
child 9790 d968c87f2a5d
X11: Added a test for a weird X11 error we get with Xinerama, rarely.
src/video/x11/SDL_x11modes.c
     1.1 --- a/src/video/x11/SDL_x11modes.c	Tue Jun 30 14:41:17 2015 -0400
     1.2 +++ b/src/video/x11/SDL_x11modes.c	Tue Jun 30 15:00:48 2015 -0400
     1.3 @@ -192,6 +192,21 @@
     1.4  #endif
     1.5      return SDL_TRUE;
     1.6  }
     1.7 +
     1.8 +/* !!! FIXME: remove this later. */
     1.9 +/* we have a weird bug where XineramaQueryScreens() throws an X error, so this
    1.10 +   is here to help track it down (and not crash, too!). */
    1.11 +static SDL_bool xinerama_triggered_error = SDL_FALSE;
    1.12 +static int
    1.13 +X11_XineramaFailed(Display * d, XErrorEvent * e)
    1.14 +{
    1.15 +    xinerama_triggered_error = SDL_TRUE;
    1.16 +    fprintf(stderr, "XINERAMA X ERROR: type=%d serial=%lu err=%u req=%u minor=%u\n",
    1.17 +            e->type, e->serial, (unsigned int) e->error_code,
    1.18 +            (unsigned int) e->request_code, (unsigned int) e->minor_code);
    1.19 +    fflush(stderr);
    1.20 +    return 0;
    1.21 +}
    1.22  #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
    1.23  
    1.24  #if SDL_VIDEO_DRIVER_X11_XRANDR
    1.25 @@ -398,7 +413,15 @@
    1.26       *       or newer of the Nvidia binary drivers
    1.27       */
    1.28      if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
    1.29 +        int (*handler) (Display *, XErrorEvent *);
    1.30 +        X11_XSync(data->display, False);
    1.31 +        handler = X11_XSetErrorHandler(X11_XineramaFailed);
    1.32          xinerama = X11_XineramaQueryScreens(data->display, &screencount);
    1.33 +        X11_XSync(data->display, False);
    1.34 +        X11_XSetErrorHandler(handler);
    1.35 +        if (xinerama_triggered_error) {
    1.36 +            xinerama = 0;
    1.37 +        }
    1.38          if (xinerama) {
    1.39              use_xinerama = xinerama_major * 100 + xinerama_minor;
    1.40          }