| | |
| | | |
| | | /* X11 driver bootstrap functions */ |
| | | |
| | | static int |
| | | X11_Available(void) |
| | | { |
| | | Display *display = NULL; |
| | | if (SDL_X11_LoadSymbols()) { |
| | | display = X11_XOpenDisplay(NULL); |
| | | if (display != NULL) { |
| | | X11_XCloseDisplay(display); |
| | | } |
| | | SDL_X11_UnloadSymbols(); |
| | | } |
| | | return (display != NULL); |
| | | } |
| | | static int (*orig_x11_errhandler) (Display *, XErrorEvent *) = NULL; |
| | | |
| | | static void |
| | | X11_DeleteDevice(SDL_VideoDevice * device) |
| | |
| | | device->Vulkan_UnloadLibrary(device); |
| | | } |
| | | if (data->display) { |
| | | X11_XSetErrorHandler(orig_x11_errhandler); |
| | | X11_XCloseDisplay(data->display); |
| | | } |
| | | SDL_free(data->windowlist); |
| | |
| | | |
| | | /* An error handler to reset the vidmode and then call the default handler. */ |
| | | static SDL_bool safety_net_triggered = SDL_FALSE; |
| | | static int (*orig_x11_errhandler) (Display *, XErrorEvent *) = NULL; |
| | | static int |
| | | X11_SafetyNetErrHandler(Display * d, XErrorEvent * e) |
| | | { |
| | |
| | | SDL_VideoDevice *device; |
| | | SDL_VideoData *data; |
| | | const char *display = NULL; /* Use the DISPLAY environment variable */ |
| | | Display *x11_display = NULL; |
| | | |
| | | if (!SDL_X11_LoadSymbols()) { |
| | | return NULL; |
| | |
| | | /* Need for threading gl calls. This is also required for the proprietary |
| | | nVidia driver to be threaded. */ |
| | | X11_XInitThreads(); |
| | | |
| | | /* Open the display first to be sure that X11 is available */ |
| | | x11_display = X11_XOpenDisplay(display); |
| | | |
| | | if (!x11_display) { |
| | | SDL_X11_UnloadSymbols(); |
| | | return NULL; |
| | | } |
| | | |
| | | /* Initialize all variables that we clean on shutdown */ |
| | | device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); |
| | |
| | | |
| | | data->global_mouse_changed = SDL_TRUE; |
| | | |
| | | /* FIXME: Do we need this? |
| | | if ( (SDL_strncmp(X11_XDisplayName(display), ":", 1) == 0) || |
| | | (SDL_strncmp(X11_XDisplayName(display), "unix:", 5) == 0) ) { |
| | | local_X11 = 1; |
| | | } else { |
| | | local_X11 = 0; |
| | | } |
| | | */ |
| | | data->display = X11_XOpenDisplay(display); |
| | | #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC |
| | | /* On some systems if linking without -lX11, it fails and you get following message. |
| | | * Xlib: connection to ":0.0" refused by server |
| | | * Xlib: XDM authorization key matches an existing client! |
| | | * |
| | | * It succeeds if retrying 1 second later |
| | | * or if running xhost +localhost on shell. |
| | | */ |
| | | if (data->display == NULL) { |
| | | SDL_Delay(1000); |
| | | data->display = X11_XOpenDisplay(display); |
| | | } |
| | | #endif |
| | | if (data->display == NULL) { |
| | | SDL_free(device->driverdata); |
| | | SDL_free(device); |
| | | SDL_SetError("Couldn't open X11 display"); |
| | | return NULL; |
| | | } |
| | | data->display = x11_display; |
| | | #ifdef X11_DEBUG |
| | | X11_XSynchronize(data->display, True); |
| | | #endif |
| | |
| | | |
| | | VideoBootStrap X11_bootstrap = { |
| | | "x11", "SDL X11 video driver", |
| | | X11_Available, X11_CreateDevice |
| | | X11_CreateDevice |
| | | }; |
| | | |
| | | static int (*handler) (Display *, XErrorEvent *) = NULL; |