mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
joystick: Make sure recentering events happen before disconnect events.
Fixes Bugzilla #5063.
This commit is contained in:
parent
f2ff953ef7
commit
07f231eeae
@ -1074,14 +1074,46 @@ static void UpdateEventsForDeviceRemoval()
|
|||||||
SDL_small_free(events, isstack);
|
SDL_small_free(events, isstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Tell the app that everything is centered/unpressed... */
|
||||||
|
for (i = 0; i < joystick->naxes; i++) {
|
||||||
|
if (joystick->axes[i].has_initial_value) {
|
||||||
|
SDL_PrivateJoystickAxis(joystick, i, joystick->axes[i].zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < joystick->nbuttons; i++) {
|
||||||
|
SDL_PrivateJoystickButton(joystick, i, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < joystick->nhats; i++) {
|
||||||
|
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
|
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
|
||||||
{
|
{
|
||||||
SDL_Joystick *joystick;
|
SDL_Joystick *joystick = NULL;
|
||||||
int player_index;
|
int player_index;
|
||||||
|
|
||||||
#if !SDL_EVENTS_DISABLED
|
#if !SDL_EVENTS_DISABLED
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Find this joystick... */
|
||||||
|
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
|
||||||
|
if (joystick->instance_id == device_instance) {
|
||||||
|
SDL_PrivateJoystickForceRecentering(joystick);
|
||||||
|
joystick->attached = SDL_FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !SDL_EVENTS_DISABLED
|
||||||
|
SDL_zero(event);
|
||||||
event.type = SDL_JOYDEVICEREMOVED;
|
event.type = SDL_JOYDEVICEREMOVED;
|
||||||
|
|
||||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||||
@ -1092,15 +1124,6 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
|
|||||||
UpdateEventsForDeviceRemoval();
|
UpdateEventsForDeviceRemoval();
|
||||||
#endif /* !SDL_EVENTS_DISABLED */
|
#endif /* !SDL_EVENTS_DISABLED */
|
||||||
|
|
||||||
/* Mark this joystick as no longer attached */
|
|
||||||
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
|
|
||||||
if (joystick->instance_id == device_instance) {
|
|
||||||
joystick->attached = SDL_FALSE;
|
|
||||||
joystick->force_recentering = SDL_TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_LockJoysticks();
|
SDL_LockJoysticks();
|
||||||
player_index = SDL_GetPlayerIndexForJoystickID(device_instance);
|
player_index = SDL_GetPlayerIndexForJoystickID(device_instance);
|
||||||
if (player_index >= 0) {
|
if (player_index >= 0) {
|
||||||
@ -1349,22 +1372,9 @@ SDL_JoystickUpdate(void)
|
|||||||
SDL_UnlockJoysticks();
|
SDL_UnlockJoysticks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* !!! FIXME: only one thing sets force_recentering now (the Darwin code), see if that can be removed. */
|
||||||
if (joystick->force_recentering) {
|
if (joystick->force_recentering) {
|
||||||
/* Tell the app that everything is centered/unpressed... */
|
SDL_PrivateJoystickForceRecentering(joystick);
|
||||||
for (i = 0; i < joystick->naxes; i++) {
|
|
||||||
if (joystick->axes[i].has_initial_value) {
|
|
||||||
SDL_PrivateJoystickAxis(joystick, i, joystick->axes[i].zero);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < joystick->nbuttons; i++) {
|
|
||||||
SDL_PrivateJoystickButton(joystick, i, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < joystick->nhats; i++) {
|
|
||||||
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
|
|
||||||
}
|
|
||||||
|
|
||||||
joystick->force_recentering = SDL_FALSE;
|
joystick->force_recentering = SDL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user