Fixed recentering triggers when the application doesn't have focus
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 4bcb69a..41af66d 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -156,16 +156,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
switch (axis) {
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
- /* Shift it to be 0 - 32767 */
- if (controllerlist->joystick->force_recentering) {
- int triggerMapping = controllerlist->mapping.axes[axis];
- if (triggerMapping >= 0) {
- controllerlist->joystick->axes[triggerMapping] = (Sint16)-32768;
- }
- value = 0;
- } else {
- value = value / 2 + 16384;
- }
+ value = value / 2 + 16384;
break;
default:
break;
@@ -1017,10 +1008,12 @@ SDL_GameControllerOpen(int device_index)
int leftTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT];
int rightTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT];
if (leftTriggerMapping >= 0) {
- gamecontroller->joystick->axes[leftTriggerMapping] = (Sint16)-32768;
+ gamecontroller->joystick->axes[leftTriggerMapping] =
+ gamecontroller->joystick->axes_zero[leftTriggerMapping] = (Sint16)-32768;
}
if (rightTriggerMapping >= 0) {
- gamecontroller->joystick->axes[rightTriggerMapping] = (Sint16)-32768;
+ gamecontroller->joystick->axes[rightTriggerMapping] =
+ gamecontroller->joystick->axes_zero[rightTriggerMapping] = (Sint16)-32768;
}
}
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 49b8cbc..c426a39 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -142,8 +142,8 @@ SDL_JoystickOpen(int device_index)
joystick->name = NULL;
if (joystick->naxes > 0) {
- joystick->axes = (Sint16 *) SDL_malloc
- (joystick->naxes * sizeof(Sint16));
+ joystick->axes = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
+ joystick->axes_zero = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
}
if (joystick->nhats > 0) {
joystick->hats = (Uint8 *) SDL_malloc
@@ -167,6 +167,7 @@ SDL_JoystickOpen(int device_index)
}
if (joystick->axes) {
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
+ SDL_memset(joystick->axes_zero, 0, joystick->naxes * sizeof(Sint16));
}
if (joystick->hats) {
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
@@ -579,8 +580,8 @@ SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
- if ((value > 0 && value >= joystick->axes[axis]) ||
- (value < 0 && value <= joystick->axes[axis])) {
+ if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) ||
+ (value < joystick->axes_zero[axis] && value <= joystick->axes[axis])) {
return 0;
}
}
@@ -753,7 +754,7 @@ SDL_JoystickUpdate(void)
/* Tell the app that everything is centered/unpressed... */
for (i = 0; i < joystick->naxes; i++) {
- SDL_PrivateJoystickAxis(joystick, i, 0);
+ SDL_PrivateJoystickAxis(joystick, i, joystick->axes_zero[i]);
}
for (i = 0; i < joystick->nbuttons; i++) {
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index 1015840..f4cad05 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -36,6 +36,7 @@ struct _SDL_Joystick
int naxes; /* Number of axis controls on the joystick */
Sint16 *axes; /* Current axis states */
+ Sint16 *axes_zero; /* Zero point on the axis (-32768 for triggers) */
int nhats; /* Number of hats on the joystick */
Uint8 *hats; /* Current hat states */