mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-03-23 21:55:12 +00:00
Fixed recentering triggers when the application doesn't have focus
This commit is contained in:
parent
72164985b0
commit
8bc5c57d2e
|
@ -156,16 +156,7 @@ int SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
|
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
|
||||||
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
|
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
|
||||||
/* Shift it to be 0 - 32767 */
|
value = value / 2 + 16384;
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1017,10 +1008,12 @@ SDL_GameControllerOpen(int device_index)
|
||||||
int leftTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT];
|
int leftTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT];
|
||||||
int rightTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT];
|
int rightTriggerMapping = gamecontroller->mapping.axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT];
|
||||||
if (leftTriggerMapping >= 0) {
|
if (leftTriggerMapping >= 0) {
|
||||||
gamecontroller->joystick->axes[leftTriggerMapping] = (Sint16)-32768;
|
gamecontroller->joystick->axes[leftTriggerMapping] =
|
||||||
|
gamecontroller->joystick->axes_zero[leftTriggerMapping] = (Sint16)-32768;
|
||||||
}
|
}
|
||||||
if (rightTriggerMapping >= 0) {
|
if (rightTriggerMapping >= 0) {
|
||||||
gamecontroller->joystick->axes[rightTriggerMapping] = (Sint16)-32768;
|
gamecontroller->joystick->axes[rightTriggerMapping] =
|
||||||
|
gamecontroller->joystick->axes_zero[rightTriggerMapping] = (Sint16)-32768;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,8 +142,8 @@ SDL_JoystickOpen(int device_index)
|
||||||
joystick->name = NULL;
|
joystick->name = NULL;
|
||||||
|
|
||||||
if (joystick->naxes > 0) {
|
if (joystick->naxes > 0) {
|
||||||
joystick->axes = (Sint16 *) SDL_malloc
|
joystick->axes = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
|
||||||
(joystick->naxes * sizeof(Sint16));
|
joystick->axes_zero = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
|
||||||
}
|
}
|
||||||
if (joystick->nhats > 0) {
|
if (joystick->nhats > 0) {
|
||||||
joystick->hats = (Uint8 *) SDL_malloc
|
joystick->hats = (Uint8 *) SDL_malloc
|
||||||
|
@ -167,6 +167,7 @@ SDL_JoystickOpen(int device_index)
|
||||||
}
|
}
|
||||||
if (joystick->axes) {
|
if (joystick->axes) {
|
||||||
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
|
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
|
||||||
|
SDL_memset(joystick->axes_zero, 0, joystick->naxes * sizeof(Sint16));
|
||||||
}
|
}
|
||||||
if (joystick->hats) {
|
if (joystick->hats) {
|
||||||
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
|
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
|
||||||
|
@ -579,8 +580,8 @@ SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
|
||||||
* events.
|
* events.
|
||||||
*/
|
*/
|
||||||
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
|
||||||
if ((value > 0 && value >= joystick->axes[axis]) ||
|
if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) ||
|
||||||
(value < 0 && value <= joystick->axes[axis])) {
|
(value < joystick->axes_zero[axis] && value <= joystick->axes[axis])) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -753,7 +754,7 @@ SDL_JoystickUpdate(void)
|
||||||
|
|
||||||
/* Tell the app that everything is centered/unpressed... */
|
/* Tell the app that everything is centered/unpressed... */
|
||||||
for (i = 0; i < joystick->naxes; i++) {
|
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++) {
|
for (i = 0; i < joystick->nbuttons; i++) {
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct _SDL_Joystick
|
||||||
|
|
||||||
int naxes; /* Number of axis controls on the joystick */
|
int naxes; /* Number of axis controls on the joystick */
|
||||||
Sint16 *axes; /* Current axis states */
|
Sint16 *axes; /* Current axis states */
|
||||||
|
Sint16 *axes_zero; /* Zero point on the axis (-32768 for triggers) */
|
||||||
|
|
||||||
int nhats; /* Number of hats on the joystick */
|
int nhats; /* Number of hats on the joystick */
|
||||||
Uint8 *hats; /* Current hat states */
|
Uint8 *hats; /* Current hat states */
|
||||||
|
|
Loading…
Reference in a new issue