You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
authorSam Lantinga
Sat, 21 Jun 2014 21:30:49 -0700
changeset 89038e09eceea61e
parent 8902 5192470456ae
child 8904 c38e754cafd3
You shouldn't get axis and hat events when your application doesn't have focus (unless you use the SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS hint)
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Sat Jun 21 20:40:00 2014 -0700
     1.2 +++ b/src/joystick/SDL_joystick.c	Sat Jun 21 21:30:49 2014 -0700
     1.3 @@ -502,21 +502,22 @@
     1.4          return 0;
     1.5      }
     1.6  
     1.7 +    /* We ignore events if we don't have keyboard focus, except for centering
     1.8 +     * events.
     1.9 +     */
    1.10 +    if (SDL_PrivateJoystickShouldIgnoreEvent()) {
    1.11 +        if ((value > 0 && value >= joystick->axes[axis]) ||
    1.12 +            (value < 0 && value <= joystick->axes[axis])) {
    1.13 +            return 0;
    1.14 +        }
    1.15 +    }
    1.16 +
    1.17      /* Update internal joystick state */
    1.18      if (value == joystick->axes[axis]) {
    1.19          return 0;
    1.20      }
    1.21      joystick->axes[axis] = value;
    1.22  
    1.23 -    /* We ignore events if we don't have keyboard focus, except for centering
    1.24 -     * events.
    1.25 -     */
    1.26 -    if (SDL_PrivateJoystickShouldIgnoreEvent()) {
    1.27 -        if (!(joystick->closed && joystick->uncentered)) {
    1.28 -            return 0;
    1.29 -        }
    1.30 -    }
    1.31 -
    1.32      /* Post the event, if desired */
    1.33      posted = 0;
    1.34  #if !SDL_EVENTS_DISABLED
    1.35 @@ -542,18 +543,20 @@
    1.36          return 0;
    1.37      }
    1.38  
    1.39 -    /* Update internal joystick state */
    1.40 -    joystick->hats[hat] = value;
    1.41 -
    1.42      /* We ignore events if we don't have keyboard focus, except for centering
    1.43       * events.
    1.44       */
    1.45      if (SDL_PrivateJoystickShouldIgnoreEvent()) {
    1.46 -        if (!(joystick->closed && joystick->uncentered)) {
    1.47 +        if (value != SDL_HAT_CENTERED) {
    1.48              return 0;
    1.49          }
    1.50      }
    1.51  
    1.52 +    /* Update internal joystick state */
    1.53 +    if (value == joystick->hats[hat]) {
    1.54 +        return 0;
    1.55 +    }
    1.56 +    joystick->hats[hat] = value;
    1.57  
    1.58      /* Post the event, if desired */
    1.59      posted = 0;
    1.60 @@ -633,11 +636,16 @@
    1.61  
    1.62      /* We ignore events if we don't have keyboard focus, except for button
    1.63       * release. */
    1.64 -    if (state == SDL_PRESSED && SDL_PrivateJoystickShouldIgnoreEvent()) {
    1.65 -        return 0;
    1.66 +    if (SDL_PrivateJoystickShouldIgnoreEvent()) {
    1.67 +        if (state == SDL_PRESSED) {
    1.68 +            return 0;
    1.69 +        }
    1.70      }
    1.71  
    1.72      /* Update internal joystick state */
    1.73 +    if (state == joystick->buttons[button]) {
    1.74 +        return 0;
    1.75 +    }
    1.76      joystick->buttons[button] = state;
    1.77  
    1.78      /* Post the event, if desired */