diff --git a/src/glx_context.c b/src/glx_context.c index 2b302783..d22d5f57 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -45,32 +45,6 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))(); #endif -// Error handler used when creating a context and blank cursor -// -static int errorHandler(Display *display, XErrorEvent* event) -{ - char buffer[8192]; - XGetErrorText(display, - event->error_code, - buffer, sizeof(buffer)); - - _glfwInputError(GLFW_PLATFORM_ERROR, "X11 failure: %s", buffer); - - return 0; -} - -void _glfwGrabXErrorHandler(void) -{ - XSetErrorHandler(errorHandler); -} - -void _glfwReleaseXErrorHandler(void) -{ - // Syncing to make sure all commands are processed - XSync(_glfw.x11.display, False); - XSetErrorHandler(NULL); -} - // Returns the specified attribute of the specified GLXFBConfig // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig // @@ -445,7 +419,6 @@ int _glfwCreateContext(_GLFWwindow* window, } } - _glfw.glx.errorCode = Success; _glfwGrabXErrorHandler(); if (_glfw.glx.ARB_create_context) @@ -517,7 +490,7 @@ int _glfwCreateContext(_GLFWwindow* window, // HACK: This is a fallback for the broken Mesa implementation of // GLX_ARB_create_context_profile, which fails default 1.0 context // creation with a GLXBadProfileARB error in violation of the spec - if (_glfw.glx.errorCode == _glfw.glx.errorBase + GLXBadProfileARB && + if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB && wndconfig->clientAPI == GLFW_OPENGL_API && wndconfig->glProfile == GLFW_OPENGL_ANY_PROFILE && wndconfig->glForward == GL_FALSE) @@ -533,9 +506,7 @@ int _glfwCreateContext(_GLFWwindow* window, if (window->glx.context == NULL) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "GLX: Failed to create context."); - + _glfwInputXError(GLFW_PLATFORM_ERROR, "GLX: Failed to create context"); return GL_FALSE; } diff --git a/src/glx_platform.h b/src/glx_platform.h index b259fe4f..277416c1 100644 --- a/src/glx_platform.h +++ b/src/glx_platform.h @@ -97,9 +97,6 @@ typedef struct _GLFWlibraryGLX // TLS key for per-thread current context/window pthread_key_t current; - // GLX error code received by Xlib error callback - int errorCode; - // GLX extensions PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; diff --git a/src/x11_init.c b/src/x11_init.c index 881d66ac..0f77587b 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -570,6 +570,12 @@ static Cursor createNULLCursor(void) _glfwReleaseXErrorHandler(); + if (cursor == None) + { + _glfwInputXError(GLFW_PLATFORM_ERROR, + "X11: Failed to create null cursor"); + } + return cursor; } @@ -584,6 +590,47 @@ static void terminateDisplay(void) } } +// X error handler +// +static int errorHandler(Display *display, XErrorEvent* event) +{ + _glfw.x11.errorCode = event->error_code; + return 0; +} + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +// Install the X error handler +// +void _glfwGrabXErrorHandler(void) +{ + _glfw.x11.errorCode = Success; + XSetErrorHandler(errorHandler); +} + +// Remove the X error handler +// +void _glfwReleaseXErrorHandler(void) +{ + // Synchronize to make sure all commands are processed + XSync(_glfw.x11.display, False); + XSetErrorHandler(NULL); +} + +// Report X error +// +void _glfwInputXError(int error, const char* message) +{ + char buffer[8192]; + XGetErrorText(_glfw.x11.display, _glfw.x11.errorCode, + buffer, sizeof(buffer)); + + _glfwInputError(error, "%s: %s", message, buffer); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// diff --git a/src/x11_platform.h b/src/x11_platform.h index 775e9c19..b254080f 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -137,6 +137,9 @@ typedef struct _GLFWlibraryX11 // True if window manager supports EWMH GLboolean hasEWMH; + // Error code received by the X error handler + int errorCode; + struct { GLboolean available; int eventBase; @@ -259,5 +262,6 @@ unsigned long _glfwGetWindowProperty(Window window, // X11 error handler void _glfwGrabXErrorHandler(void); void _glfwReleaseXErrorHandler(void); +void _glfwInputXError(int error, const char* message); #endif // _x11_platform_h_