From 1261ff639d098509a9aa201162c2c81ad708c98b Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sun, 5 Nov 2023 00:41:34 +0000 Subject: [PATCH] [+] GLFWAPI DWORD glfwGetXInputIndexJoystick(int jid); [+] GLFWAPI int glfwGetLinuxFdJoystick(int jid); --- include/GLFW/glfw3native.h | 6 ++++++ src/linux_joystick.c | 22 ++++++++++++++++++++++ src/win32_joystick.c | 23 +++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index fe5814c5..862d1f1b 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -188,6 +188,12 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); * @ingroup native */ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); + +GLFWAPI DWORD glfwGetXInputIndexJoystick(int jid); +#endif + +#if defined(GLFW_EXPOSE_NATIVE_LINUX) +GLFWAPI int glfwGetLinuxFdJoystick(int jid); #endif #if defined(GLFW_EXPOSE_NATIVE_COCOA) diff --git a/src/linux_joystick.c b/src/linux_joystick.c index 8f7e481a..7990f974 100644 --- a/src/linux_joystick.c +++ b/src/linux_joystick.c @@ -438,5 +438,27 @@ void _glfwUpdateGamepadGUIDLinux(char* guid) { } +GLFWAPI int glfwGetLinuxFdJoystick(int jid) +{ + _GLFWjoystick* js; + + _GLFW_REQUIRE_INIT_OR_RETURN(0); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return 0; + } + + js = _glfw.joysticks + jid; + if (!js->connected) + return 0; + + if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_ALL)) + return 0; + + return js->linjs.fd; +} + #endif // GLFW_BUILD_LINUX_JOYSTICK diff --git a/src/win32_joystick.c b/src/win32_joystick.c index 09908f1a..97ab1977 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -766,5 +766,28 @@ void _glfwUpdateGamepadGUIDWin32(char* guid) } } +GLFWAPI DWORD glfwGetXInputIndexJoystick(int jid) +{ + _GLFWjoystick* js; + + _GLFW_REQUIRE_INIT_OR_RETURN(0xFFFFFFFFul); + + if (jid < 0 || jid > GLFW_JOYSTICK_LAST) + { + _glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick ID %i", jid); + return 0xFFFFFFFFul; + } + + js = _glfw.joysticks + jid; + if (!js->connected) + return 0xFFFFFFFFul; + + if (!_glfw.platform.pollJoystick(js, _GLFW_POLL_ALL)) + return 0xFFFFFFFFul; + + return js->win32.index; +} + + #endif // _GLFW_WIN32