Don't treat the Wii extension controls as a separate game controller on Linux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 93a3e28..1fd5f5f 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -1954,6 +1954,19 @@ SDL_IsGameController(int device_index)
return SDL_FALSE;
}
+static SDL_bool SDL_endswith(const char *string, const char *suffix)
+{
+ size_t string_length = string ? SDL_strlen(string) : 0;
+ size_t suffix_length = suffix ? SDL_strlen(suffix) : 0;
+
+ if (suffix_length > 0 && suffix_length <= string_length) {
+ if (SDL_memcmp(string + string_length - suffix_length, suffix, suffix_length) == 0) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
/*
* Return 1 if the game controller should be ignored by SDL
*/
@@ -1966,10 +1979,17 @@ SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
Uint32 vidpid;
#if defined(__LINUX__)
- if (name && SDL_strstr(name, "Motion Sensors")) {
+ if (SDL_endswith(name, " Motion Sensors")) {
/* Don't treat the PS3 and PS4 motion controls as a separate game controller */
return SDL_TRUE;
}
+ if (SDL_endswith(name, " Accelerometer") ||
+ SDL_endswith(name, " IR") ||
+ SDL_endswith(name, " Motion Plus") ||
+ SDL_endswith(name, " Nunchuk")) {
+ /* Don't treat the Wii extension controls as a separate game controller */
+ return SDL_TRUE;
+ }
#endif
if (name && SDL_strcmp(name, "uinput-fpc") == 0) {