diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 0309f8c3e..a30fe27d8 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -609,17 +609,18 @@ ConfigJoystick(SDL_Joystick * joystick, int fd) for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) { if (test_bit(i, absbit) || test_bit(i + 1, absbit)) { struct input_absinfo absinfo; + int hat_index = (i - ABS_HAT0X) / 2; if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) { continue; } #ifdef DEBUG_INPUT_EVENTS - printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2); + printf("Joystick has hat %d\n", hat_index); printf("Values = { %d, %d, %d, %d, %d }\n", absinfo.value, absinfo.minimum, absinfo.maximum, absinfo.fuzz, absinfo.flat); #endif /* DEBUG_INPUT_EVENTS */ - ++joystick->nhats; + joystick->hwdata->hats_indices[joystick->nhats++] = hat_index; } } if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) { @@ -762,7 +763,7 @@ HandleHat(SDL_Joystick * stick, Uint8 hat, int axis, int value) {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN} }; - the_hat = &stick->hwdata->hats[hat]; + the_hat = &stick->hwdata->hats[stick->hwdata->hats_indices[hat]]; if (value < 0) { value = 0; } else if (value == 0) { diff --git a/src/joystick/linux/SDL_sysjoystick_c.h b/src/joystick/linux/SDL_sysjoystick_c.h index 3ebdc924c..ef50730a8 100644 --- a/src/joystick/linux/SDL_sysjoystick_c.h +++ b/src/joystick/linux/SDL_sysjoystick_c.h @@ -62,6 +62,8 @@ struct joystick_hwdata /* Steam Controller support */ SDL_bool m_bSteamController; + /* 4 = (ABS_HAT3X-ABS_HAT0X)/2 (see input-event-codes.h in kernel) */ + int hats_indices[4]; }; #endif /* SDL_sysjoystick_c_h_ */