Navigation Menu

Skip to content

Commit

Permalink
joystick/linux: Allow for custom joystick names
Browse files Browse the repository at this point in the history
When not using the old Linux input event interface, SDL parses the
name of a device to know what it's capable of. It expects the
name to match the following string: "Analog %d-axis %d-button %d-hat".

This patch allows to use devices with a custom name.
For instance: "My Joystick Device (Analog 2-axis 6-button 2-hat)"

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 src/joystick/linux/SDL_sysjoystick.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  • Loading branch information
pcercuei committed Sep 22, 2020
1 parent 045a6ba commit 1202966
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/joystick/linux/SDL_sysjoystick.c
Expand Up @@ -583,7 +583,7 @@ static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd)
SDL_bool handled;
unsigned char n;
int tmp_naxes, tmp_nhats, tmp_nballs;
const char *name;
const char *name, *ptr;
char *env, env_name[128];
int i;

Expand All @@ -604,8 +604,9 @@ static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd)
name = SDL_SYS_JoystickName(joystick->index);

/* Generic analog joystick support */
if ( SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat") ) {
if ( SDL_sscanf(name,"Analog %d-axis %*d-button %d-hat",
ptr = SDL_strstr(name, "Analog");
if ( ptr != NULL && SDL_strstr(ptr, "-hat") ) {
if ( SDL_sscanf(ptr,"Analog %d-axis %*d-button %d-hat",
&tmp_naxes, &tmp_nhats) == 2 ) {

joystick->naxes = tmp_naxes;
Expand Down

0 comments on commit 1202966

Please sign in to comment.