mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 13:46:37 +00:00
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().
This commit is contained in:
parent
90e22947c6
commit
86d8491972
26
src/init.c
26
src/init.c
@ -227,6 +227,19 @@ GLFWAPI int glfwInit(void)
|
|||||||
memset(&_glfw, 0, sizeof(_glfw));
|
memset(&_glfw, 0, sizeof(_glfw));
|
||||||
_glfw.hints.init = _glfwInitHints;
|
_glfw.hints.init = _glfwInitHints;
|
||||||
|
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; _glfwDefaultMappings[i]; i++)
|
||||||
|
{
|
||||||
|
if (!_glfwInputUpdateGamepadMappings(_glfwDefaultMappings[i]))
|
||||||
|
{
|
||||||
|
terminate();
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!_glfwPlatformInit())
|
if (!_glfwPlatformInit())
|
||||||
{
|
{
|
||||||
terminate();
|
terminate();
|
||||||
@ -248,19 +261,6 @@ GLFWAPI int glfwInit(void)
|
|||||||
|
|
||||||
glfwDefaultWindowHints();
|
glfwDefaultWindowHints();
|
||||||
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; _glfwDefaultMappings[i]; i++)
|
|
||||||
{
|
|
||||||
if (!glfwUpdateGamepadMappings(_glfwDefaultMappings[i]))
|
|
||||||
{
|
|
||||||
terminate();
|
|
||||||
return GLFW_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
src/input.c
11
src/input.c
@ -1083,15 +1083,13 @@ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun)
|
|||||||
return cbfun;
|
return cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI int glfwUpdateGamepadMappings(const char* string)
|
int _glfwInputUpdateGamepadMappings(const char* string)
|
||||||
{
|
{
|
||||||
int jid;
|
int jid;
|
||||||
const char* c = string;
|
const char* c = string;
|
||||||
|
|
||||||
assert(string != NULL);
|
assert(string != NULL);
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
|
|
||||||
|
|
||||||
while (*c)
|
while (*c)
|
||||||
{
|
{
|
||||||
if ((*c >= '0' && *c <= '9') ||
|
if ((*c >= '0' && *c <= '9') ||
|
||||||
@ -1143,6 +1141,13 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string)
|
|||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLFWAPI int glfwUpdateGamepadMappings(const char* string)
|
||||||
|
{
|
||||||
|
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
|
||||||
|
|
||||||
|
return _glfwInputUpdateGamepadMappings(string);
|
||||||
|
}
|
||||||
|
|
||||||
GLFWAPI int glfwJoystickIsGamepad(int jid)
|
GLFWAPI int glfwJoystickIsGamepad(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystick* js;
|
_GLFWjoystick* js;
|
||||||
|
@ -722,6 +722,8 @@ void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
|
|||||||
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
|
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
|
||||||
void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
|
void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
|
||||||
|
|
||||||
|
int _glfwInputUpdateGamepadMappings(const char* string);
|
||||||
|
|
||||||
void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
|
void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
|
||||||
void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
|
void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user