Don't send the initial joystick axis event if the application is in the background
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 44 45
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 9bc123c..4b41435 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1344,7 +1344,7 @@ SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
info->value = value;
info->zero = value;
info->has_initial_value = SDL_TRUE;
- } else if (value == info->value) {
+ } else if (value == info->value && !info->sending_initial_value) {
return 0;
} else {
info->has_second_value = SDL_TRUE;
@@ -1356,15 +1356,17 @@ SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
return 0;
}
info->sent_initial_value = SDL_TRUE;
- info->value = ~value; /* Just so we pass the check above */
+ info->sending_initial_value = SDL_TRUE;
SDL_PrivateJoystickAxis(joystick, axis, info->initial_value);
+ info->sending_initial_value = SDL_FALSE;
}
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
- if ((value > info->zero && value >= info->value) ||
+ if (info->sending_initial_value ||
+ (value > info->zero && value >= info->value) ||
(value < info->zero && value <= info->value)) {
return 0;
}
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index 91c9a7c..79ba178 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -36,6 +36,7 @@ typedef struct _SDL_JoystickAxisInfo
SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
SDL_bool has_second_value; /* Whether we've seen a second value on the axis yet */
SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
+ SDL_bool sending_initial_value; /* Whether we are sending the initial axis value */
} SDL_JoystickAxisInfo;
typedef struct _SDL_JoystickTouchpadFingerInfo