Added stubs, implemented on Linux and Cocoa.

This commit is contained in:
Camilla Berglund
2012-09-07 01:01:34 +02:00
parent 8cf093a19d
commit 93a1d1c226
8 changed files with 76 additions and 7 deletions
+18
View File
@@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif // _GLFW_USE_LINUX_JOYSTICKS
@@ -51,6 +52,7 @@ static int openJoystickDevice(int joy, const char* path)
{
#ifdef _GLFW_USE_LINUX_JOYSTICKS
char numAxes, numButtons;
char name[256];
int fd, version;
fd = open(path, O_RDONLY | O_NONBLOCK);
@@ -68,6 +70,11 @@ static int openJoystickDevice(int joy, const char* path)
return GL_FALSE;
}
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
strncpy(name, "Unknown", sizeof(name));
_glfwLibrary.X11.joystick[joy].name = strdup(name);
ioctl(fd, JSIOCGAXES, &numAxes);
_glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes;
@@ -214,6 +221,7 @@ void _glfwTerminateJoysticks(void)
close(_glfwLibrary.X11.joystick[i].fd);
free(_glfwLibrary.X11.joystick[i].axis);
free(_glfwLibrary.X11.joystick[i].button);
free(_glfwLibrary.X11.joystick[i].name);
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
}
@@ -302,3 +310,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return numButtons;
}
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return _glfwLibrary.X11.joystick[joy].name;
}