From 7eff6b1b1ebb0226b8f84156b473839b4a7c4d48 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 8 Nov 2012 16:26:15 +0100 Subject: [PATCH] Initial implementation of joystick name retrieval on Win32. --- src/win32_joystick.c | 13 ++++++++++++- src/win32_platform.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/win32_joystick.c b/src/win32_joystick.c index 3e342168..a9fe04b1 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -225,6 +225,17 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, const char* _glfwPlatformGetJoystickName(int joy) { - return ""; + 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]; } diff --git a/src/win32_platform.h b/src/win32_platform.h index ba10039e..9ee8cc1a 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -208,6 +208,8 @@ typedef struct _GLFWlibraryWin32 } winmm; #endif // _GLFW_NO_DLOAD_WINMM + char* joyNames[GLFW_JOYSTICK_LAST + 1]; + } _GLFWlibraryWin32;