Reuse X11 connection from availability check Instead of creating an X11 connection to test that X11 is available, closing the connection, and then reconnecting for real, use the same connection to handle both cases. The X11 connection retry delay mechanism in the case where X11 is dynamically loaded has been removed. It was only necessary to avoid authetnication token reuse from the XOpenDisplay call that used to exist in X11_Available. Now that this call is only made once, it is no longer needed. Also drop unused and inapplicable code from a comment. ***
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index ecb6381..8ae4b6c 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -92,20 +92,6 @@ get_classname()
/* 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 void
X11_DeleteDevice(SDL_VideoDevice * device)
{
@@ -159,10 +145,7 @@ X11_CreateDevice(int devindex)
SDL_VideoDevice *device;
SDL_VideoData *data;
const char *display = NULL; /* Use the DISPLAY environment variable */
-
- if (!X11_Available()) {
- return NULL;
- }
+ Display *x11_display = NULL;
if (!SDL_X11_LoadSymbols()) {
return NULL;
@@ -172,6 +155,14 @@ X11_CreateDevice(int devindex)
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));
if (!device) {
@@ -188,34 +179,7 @@ X11_CreateDevice(int devindex)
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