diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 71425096..4820f2d0 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -84,19 +84,18 @@ int _glfwPlatformInit(void) changeToResourcesDirectory(); #endif - _glfwInitTimer(); - - _glfwInitJoysticks(); - - if (!_glfwInitContextAPI()) - return GL_FALSE; - _glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); if (!_glfw.ns.eventSource) return GL_FALSE; CGEventSourceSetLocalEventsSuppressionInterval(_glfw.ns.eventSource, 0.0); + if (!_glfwInitContextAPI()) + return GL_FALSE; + + _glfwInitTimer(); + _glfwInitJoysticks(); + return GL_TRUE; } @@ -121,7 +120,6 @@ void _glfwPlatformTerminate(void) free(_glfw.ns.clipboardString); _glfwTerminateJoysticks(); - _glfwTerminateContextAPI(); } diff --git a/src/win32_init.c b/src/win32_init.c index b5abf2a2..d1335d3a 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -98,7 +98,7 @@ static GLboolean initLibraries(void) // Unload used libraries (DLLs) // -static void freeLibraries(void) +static void terminateLibraries(void) { #ifndef _GLFW_NO_DLOAD_WINMM if (_glfw.win32.winmm.instance != NULL) @@ -204,7 +204,6 @@ int _glfwPlatformInit(void) return GL_FALSE; _glfwInitTimer(); - _glfwInitJoysticks(); return GL_TRUE; @@ -218,18 +217,16 @@ void _glfwPlatformTerminate(void) _glfw.win32.classAtom = 0; } - free(_glfw.win32.clipboardString); - - _glfwTerminateContextAPI(); - - _glfwTerminateJoysticks(); - - freeLibraries(); - - // Restore previous FOREGROUNDLOCKTIMEOUT system setting + // Restore previous foreground lock timeout system setting SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(_glfw.win32.foregroundLockTimeout), SPIF_SENDCHANGE); + + free(_glfw.win32.clipboardString); + + _glfwTerminateJoysticks(); + _glfwTerminateContextAPI(); + terminateLibraries(); } const char* _glfwPlatformGetVersionString(void) diff --git a/src/x11_init.c b/src/x11_init.c index 7d460ba3..d73a504c 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -420,21 +420,10 @@ static void detectEWMH(void) // Initialize X11 display and look for supported X11 extensions // -static GLboolean initDisplay(void) +static GLboolean initExtensions(void) { Bool supported; - _glfw.x11.display = XOpenDisplay(NULL); - if (!_glfw.x11.display) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "X11: Failed to open X display"); - return GL_FALSE; - } - - _glfw.x11.screen = DefaultScreen(_glfw.x11.display); - _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); - _glfw.x11.context = XUniqueContext(); - // Find or create window manager atoms _glfw.x11.WM_STATE = XInternAtom(_glfw.x11.display, "WM_STATE", False); _glfw.x11.WM_DELETE_WINDOW = XInternAtom(_glfw.x11.display, @@ -602,20 +591,28 @@ int _glfwPlatformInit(void) { XInitThreads(); - if (!initDisplay()) + _glfw.x11.display = XOpenDisplay(NULL); + if (!_glfw.x11.display) + { + _glfwInputError(GLFW_API_UNAVAILABLE, "X11: Failed to open X display"); return GL_FALSE; + } - _glfwInitGammaRamp(); + _glfw.x11.screen = DefaultScreen(_glfw.x11.display); + _glfw.x11.root = RootWindow(_glfw.x11.display, _glfw.x11.screen); + _glfw.x11.context = XUniqueContext(); - if (!_glfwInitContextAPI()) + if (!initExtensions()) return GL_FALSE; _glfw.x11.cursor = createNULLCursor(); - if (!_glfwInitJoysticks()) + if (!_glfwInitContextAPI()) return GL_FALSE; _glfwInitTimer(); + _glfwInitJoysticks(); + _glfwInitGammaRamp(); return GL_TRUE; } @@ -631,9 +628,7 @@ void _glfwPlatformTerminate(void) free(_glfw.x11.selection.string); _glfwTerminateJoysticks(); - _glfwTerminateContextAPI(); - terminateDisplay(); } diff --git a/src/x11_joystick.c b/src/x11_joystick.c index 7e5aad37..49164d79 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -159,7 +159,7 @@ static void pollJoystickEvents(void) // Initialize joystick interface // -int _glfwInitJoysticks(void) +void _glfwInitJoysticks(void) { #ifdef __linux__ int i, joy = 0; @@ -174,7 +174,7 @@ int _glfwInitJoysticks(void) if (regcomp(®ex, "^js[0-9]\\+$", 0) != 0) { _glfwInputError(GLFW_PLATFORM_ERROR, "X11: Failed to compile regex"); - return GL_FALSE; + return; } for (i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++) @@ -203,8 +203,6 @@ int _glfwInitJoysticks(void) regfree(®ex); #endif // __linux__ - - return GL_TRUE; } // Close all opened joystick handles diff --git a/src/x11_platform.h b/src/x11_platform.h index 6f94b508..c669a35e 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -238,7 +238,7 @@ void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoMode(_GLFWmonitor* monitor); // Joystick input -int _glfwInitJoysticks(void); +void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); // Unicode support