From 86d849197255d5ccf4983da5a0b6abb57a596051 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 31 Jan 2019 15:09:40 -0800 Subject: [PATCH] input: Fix issues with XInput on Windows glfwInit() will call _glfwPlatformInit(), which on Win32 will call _glfwInitJoysticksWin32(), which will try to create an XInput gamepad using the SDL device ID for XInput. However, at this point in time, the default mappings for controllers hasn't been initialized, so we end up with an XInput gamepad with no mappings. Fix this by loading the mappings before calling glfwInit(). --- src/init.c | 26 +++++++++++++------------- src/input.c | 11 ++++++++--- src/internal.h | 2 ++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/init.c b/src/init.c index 4f424c4a9..17dcb2062 100644 --- a/src/init.c +++ b/src/init.c @@ -227,6 +227,19 @@ GLFWAPI int glfwInit(void) memset(&_glfw, 0, sizeof(_glfw)); _glfw.hints.init = _glfwInitHints; + { + int i; + + for (i = 0; _glfwDefaultMappings[i]; i++) + { + if (!_glfwInputUpdateGamepadMappings(_glfwDefaultMappings[i])) + { + terminate(); + return GLFW_FALSE; + } + } + } + if (!_glfwPlatformInit()) { terminate(); @@ -248,19 +261,6 @@ GLFWAPI int glfwInit(void) glfwDefaultWindowHints(); - { - int i; - - for (i = 0; _glfwDefaultMappings[i]; i++) - { - if (!glfwUpdateGamepadMappings(_glfwDefaultMappings[i])) - { - terminate(); - return GLFW_FALSE; - } - } - } - return GLFW_TRUE; } diff --git a/src/input.c b/src/input.c index 33ed06045..5b8201676 100644 --- a/src/input.c +++ b/src/input.c @@ -1083,15 +1083,13 @@ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun) return cbfun; } -GLFWAPI int glfwUpdateGamepadMappings(const char* string) +int _glfwInputUpdateGamepadMappings(const char* string) { int jid; const char* c = string; assert(string != NULL); - _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - while (*c) { if ((*c >= '0' && *c <= '9') || @@ -1143,6 +1141,13 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string) return GLFW_TRUE; } +GLFWAPI int glfwUpdateGamepadMappings(const char* string) +{ + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); + + return _glfwInputUpdateGamepadMappings(string); +} + GLFWAPI int glfwJoystickIsGamepad(int jid) { _GLFWjoystick* js; diff --git a/src/internal.h b/src/internal.h index e8df80a07..f0e388477 100644 --- a/src/internal.h +++ b/src/internal.h @@ -722,6 +722,8 @@ void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value); void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value); void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value); +int _glfwInputUpdateGamepadMappings(const char* string); + void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement); void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);