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
+13 -3
View File
@@ -443,9 +443,9 @@ void _glfwInitJoysticks(void)
if (refCF)
{
CFStringGetCString(refCF,
(char*) &(joystick->product),
256,
CFStringGetSystemEncoding());
joystick->product,
sizeof(joystick->product),
kCFStringEncodingUTF8);
}
joystick->numAxes = 0;
@@ -625,3 +625,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return button;
}
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return _glfwJoysticks[joy].product;
}
+1
View File
@@ -274,6 +274,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
int _glfwPlatformGetJoystickParam(int joy, int param);
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes);
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
const char* _glfwPlatformGetJoystickName(int joy);
// Time input
double _glfwPlatformGetTime(void);
+22
View File
@@ -126,3 +126,25 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
return _glfwPlatformGetJoystickButtons(joy, buttons, numbuttons);
}
//========================================================================
// Get joystick name
//========================================================================
GLFWAPI const char* glfwGetJoystickName(int joy)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return 0;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return 0;
}
return _glfwPlatformGetJoystickName(joy);
}
+11
View File
@@ -211,3 +211,14 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return button;
}
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return "";
}
+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;
}
+1
View File
@@ -240,6 +240,7 @@ typedef struct _GLFWlibraryX11
int numButtons;
float* axis;
unsigned char* button;
char* name;
} joystick[GLFW_JOYSTICK_LAST + 1];
} _GLFWlibraryX11;