Make joystick platform code init on demand

This makes joystick support initialize the first time a joystick
function is called, including those gamepad functions that are layered
on top of joystick functions.

Related to #1284.
Related to #1646.
This commit is contained in:
Camilla Löwy
2020-07-12 18:31:29 +02:00
parent f760b124ca
commit 782e6b6cef
19 changed files with 101 additions and 49 deletions
+9 -5
View File
@@ -309,7 +309,7 @@ static void removeCallback(void* context,
// Initialize joystick interface
//
void _glfwInitJoysticksNS(void)
GLFWbool _glfwPlatformInitJoysticks(void)
{
CFMutableArrayRef matching;
const long usages[] =
@@ -328,7 +328,7 @@ void _glfwInitJoysticksNS(void)
if (!matching)
{
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to create array");
return;
return GLFW_FALSE;
}
for (size_t i = 0; i < sizeof(usages) / sizeof(long); i++)
@@ -383,19 +383,23 @@ void _glfwInitJoysticksNS(void)
// Execute the run loop once in order to register any initially-attached
// joysticks
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false);
return GLFW_TRUE;
}
// Close all opened joystick handles
//
void _glfwTerminateJoysticksNS(void)
void _glfwPlatformTerminateJoysticks(void)
{
int jid;
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
closeJoystick(_glfw.joysticks + jid);
CFRelease(_glfw.ns.hidManager);
_glfw.ns.hidManager = NULL;
if (_glfw.ns.hidManager)
{
CFRelease(_glfw.ns.hidManager);
_glfw.ns.hidManager = NULL;
}
}