mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 16:44:11 +00:00
Merge branch 'master' into EGL
This commit is contained in:
+14
-4
@@ -68,7 +68,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
int present;
|
||||
char product[256];
|
||||
char name[256];
|
||||
|
||||
IOHIDDeviceInterface** interface;
|
||||
|
||||
@@ -443,9 +443,9 @@ void _glfwInitJoysticks(void)
|
||||
if (refCF)
|
||||
{
|
||||
CFStringGetCString(refCF,
|
||||
(char*) &(joystick->product),
|
||||
256,
|
||||
CFStringGetSystemEncoding());
|
||||
joystick->name,
|
||||
sizeof(joystick->name),
|
||||
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].name;
|
||||
}
|
||||
|
||||
|
||||
@@ -285,6 +285,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);
|
||||
|
||||
@@ -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 NULL;
|
||||
}
|
||||
|
||||
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return _glfwPlatformGetJoystickName(joy);
|
||||
}
|
||||
|
||||
|
||||
+32
-4
@@ -199,15 +199,43 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
|
||||
if (hats > 0)
|
||||
{
|
||||
int j;
|
||||
int value = ji.dwPOV / 100 / 45;
|
||||
if (value < 0 || value > 8) value = 8;
|
||||
int j, value = ji.dwPOV / 100 / 45;
|
||||
|
||||
if (value < 0 || value > 8)
|
||||
value = 8;
|
||||
|
||||
for (j = 0; j < 4 && button < numbuttons; j++)
|
||||
{
|
||||
buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE;
|
||||
if (directions[value] & (1 << j))
|
||||
buttons[button] = GLFW_PRESS;
|
||||
else
|
||||
buttons[button] = GLFW_RELEASE;
|
||||
|
||||
button++;
|
||||
}
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get joystick name
|
||||
//========================================================================
|
||||
|
||||
const char* _glfwPlatformGetJoystickName(int joy)
|
||||
{
|
||||
JOYCAPS jc;
|
||||
const int i = joy - GLFW_JOYSTICK_1;
|
||||
|
||||
if (!isJoystickPresent(joy))
|
||||
return NULL;
|
||||
|
||||
_glfw_joyGetDevCaps(i, &jc, sizeof(JOYCAPS));
|
||||
|
||||
free(_glfwLibrary.Win32.joyNames[i]);
|
||||
_glfwLibrary.Win32.joyNames[i] = _glfwCreateUTF8FromWideString(jc.szPname);
|
||||
|
||||
return _glfwLibrary.Win32.joyNames[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,8 @@ typedef struct _GLFWlibraryWin32
|
||||
} winmm;
|
||||
#endif // _GLFW_NO_DLOAD_WINMM
|
||||
|
||||
char* joyNames[GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
} _GLFWlibraryWin32;
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif // __linux__
|
||||
|
||||
|
||||
@@ -52,6 +53,7 @@ static int openJoystickDevice(int joy, const char* path)
|
||||
{
|
||||
#ifdef __linux__
|
||||
char numAxes, numButtons;
|
||||
char name[256];
|
||||
int fd, version;
|
||||
|
||||
fd = open(path, O_RDONLY | O_NONBLOCK);
|
||||
@@ -69,6 +71,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;
|
||||
|
||||
@@ -237,6 +244,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;
|
||||
}
|
||||
@@ -325,3 +333,16 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
return numButtons;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Get joystick name
|
||||
//========================================================================
|
||||
|
||||
const char* _glfwPlatformGetJoystickName(int joy)
|
||||
{
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
return NULL;
|
||||
|
||||
return _glfwLibrary.X11.joystick[joy].name;
|
||||
}
|
||||
|
||||
|
||||
@@ -209,6 +209,7 @@ typedef struct _GLFWlibraryX11
|
||||
int numButtons;
|
||||
float* axis;
|
||||
unsigned char* button;
|
||||
char* name;
|
||||
} joystick[GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
} _GLFWlibraryX11;
|
||||
|
||||
Reference in New Issue
Block a user