src/joystick/linux/SDL_sysjoystick.c
changeset 12846 c54ce7eddcbe
parent 12793 26634e392a7f
child 12847 baae9331abc0
     1.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Wed Jun 12 07:55:48 2019 -0700
     1.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Wed Jun 12 10:32:36 2019 -0700
     1.3 @@ -609,17 +609,18 @@
     1.4          for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) {
     1.5              if (test_bit(i, absbit) || test_bit(i + 1, absbit)) {
     1.6                  struct input_absinfo absinfo;
     1.7 +                int hat_index = (i - ABS_HAT0X) / 2;
     1.8  
     1.9                  if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
    1.10                      continue;
    1.11                  }
    1.12  #ifdef DEBUG_INPUT_EVENTS
    1.13 -                printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
    1.14 +                printf("Joystick has hat %d\n", hat_index);
    1.15                  printf("Values = { %d, %d, %d, %d, %d }\n",
    1.16                         absinfo.value, absinfo.minimum, absinfo.maximum,
    1.17                         absinfo.fuzz, absinfo.flat);
    1.18  #endif /* DEBUG_INPUT_EVENTS */
    1.19 -                ++joystick->nhats;
    1.20 +                joystick->hwdata->hats_indices[joystick->nhats++] = hat_index;
    1.21              }
    1.22          }
    1.23          if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
    1.24 @@ -762,7 +763,7 @@
    1.25          {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
    1.26      };
    1.27  
    1.28 -    the_hat = &stick->hwdata->hats[hat];
    1.29 +    the_hat = &stick->hwdata->hats[stick->hwdata->hats_indices[hat]];
    1.30      if (value < 0) {
    1.31          value = 0;
    1.32      } else if (value == 0) {