src/video/x11/SDL_x11video.c
changeset 6498 93d9b2a2eb0e
parent 6484 b904bb684095
child 6569 1f4e69a8e5e6
equal deleted inserted replaced
6497:e844e2632149 6498:93d9b2a2eb0e
   112     SDL_free(data->windowlist);
   112     SDL_free(data->windowlist);
   113     SDL_free(device->driverdata);
   113     SDL_free(device->driverdata);
   114     SDL_free(device);
   114     SDL_free(device);
   115 
   115 
   116     SDL_X11_UnloadSymbols();
   116     SDL_X11_UnloadSymbols();
       
   117 }
       
   118 
       
   119 /* An error handler to reset the vidmode and then call the default handler. */
       
   120 static SDL_bool safety_net_triggered = SDL_FALSE;
       
   121 static int (*orig_x11_errhandler) (Display *, XErrorEvent *) = NULL;
       
   122 static int
       
   123 X11_SafetyNetErrHandler(Display * d, XErrorEvent * e)
       
   124 {
       
   125     /* if we trigger an error in our error handler, don't try again. */
       
   126     if (!safety_net_triggered) {
       
   127         safety_net_triggered = SDL_TRUE;
       
   128         SDL_VideoDevice *device = SDL_GetVideoDevice();
       
   129         if (device != NULL) {
       
   130             int i;
       
   131             for (i = 0; i < device->num_displays; i++) {
       
   132                 SDL_VideoDisplay *display = &device->displays[i];
       
   133                 if (SDL_memcmp(&display->current_mode, &display->desktop_mode,
       
   134                                sizeof (SDL_DisplayMode)) != 0) {
       
   135                     X11_SetDisplayMode(device, display, &display->desktop_mode);
       
   136                 }
       
   137             }
       
   138         }
       
   139     }
       
   140 
       
   141     if (orig_x11_errhandler != NULL) {
       
   142         return orig_x11_errhandler(d, e);  /* probably terminate. */
       
   143     }
       
   144 
       
   145     return 0;
   117 }
   146 }
   118 
   147 
   119 static SDL_VideoDevice *
   148 static SDL_VideoDevice *
   120 X11_CreateDevice(int devindex)
   149 X11_CreateDevice(int devindex)
   121 {
   150 {
   170         return NULL;
   199         return NULL;
   171     }
   200     }
   172 #ifdef X11_DEBUG
   201 #ifdef X11_DEBUG
   173     XSynchronize(data->display, True);
   202     XSynchronize(data->display, True);
   174 #endif
   203 #endif
       
   204 
       
   205     /* Hook up an X11 error handler to recover the desktop resolution. */
       
   206     safety_net_triggered = SDL_FALSE;
       
   207     orig_x11_errhandler = XSetErrorHandler(X11_SafetyNetErrHandler);
   175 
   208 
   176     /* Set the function pointers */
   209     /* Set the function pointers */
   177     device->VideoInit = X11_VideoInit;
   210     device->VideoInit = X11_VideoInit;
   178     device->VideoQuit = X11_VideoQuit;
   211     device->VideoQuit = X11_VideoQuit;
   179     device->GetDisplayModes = X11_GetDisplayModes;
   212     device->GetDisplayModes = X11_GetDisplayModes;