mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
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. ***
This commit is contained in:
parent
052a13738d
commit
8669a87f05
@ -92,20 +92,6 @@ get_classname()
|
|||||||
|
|
||||||
/* X11 driver bootstrap functions */
|
/* 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
|
static void
|
||||||
X11_DeleteDevice(SDL_VideoDevice * device)
|
X11_DeleteDevice(SDL_VideoDevice * device)
|
||||||
{
|
{
|
||||||
@ -159,10 +145,7 @@ X11_CreateDevice(int devindex)
|
|||||||
SDL_VideoDevice *device;
|
SDL_VideoDevice *device;
|
||||||
SDL_VideoData *data;
|
SDL_VideoData *data;
|
||||||
const char *display = NULL; /* Use the DISPLAY environment variable */
|
const char *display = NULL; /* Use the DISPLAY environment variable */
|
||||||
|
Display *x11_display = NULL;
|
||||||
if (!X11_Available()) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SDL_X11_LoadSymbols()) {
|
if (!SDL_X11_LoadSymbols()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -172,6 +155,14 @@ X11_CreateDevice(int devindex)
|
|||||||
nVidia driver to be threaded. */
|
nVidia driver to be threaded. */
|
||||||
X11_XInitThreads();
|
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 */
|
/* Initialize all variables that we clean on shutdown */
|
||||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||||
if (!device) {
|
if (!device) {
|
||||||
@ -188,34 +179,7 @@ X11_CreateDevice(int devindex)
|
|||||||
|
|
||||||
data->global_mouse_changed = SDL_TRUE;
|
data->global_mouse_changed = SDL_TRUE;
|
||||||
|
|
||||||
/* FIXME: Do we need this?
|
data->display = x11_display;
|
||||||
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;
|
|
||||||
}
|
|
||||||
#ifdef X11_DEBUG
|
#ifdef X11_DEBUG
|
||||||
X11_XSynchronize(data->display, True);
|
X11_XSynchronize(data->display, True);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user