Delay delivery of the pause button release on MFI controllers so it doesn't happen in the same frame as the button press

This commit is contained in:
Sam Lantinga 2018-03-08 16:32:22 -08:00
parent 92847022f5
commit 129431b4f4
2 changed files with 37 additions and 29 deletions

View File

@ -31,6 +31,7 @@
#include "SDL_joystick.h"
#include "SDL_hints.h"
#include "SDL_stdinc.h"
#include "SDL_timer.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#include "../steam/SDL_steamcontroller.h"
@ -559,6 +560,8 @@ SDL_SYS_MFIJoystickUpdate(SDL_Joystick * joystick)
Uint8 hatstate = SDL_HAT_CENTERED;
int i;
int updateplayerindex = 0;
const Uint8 pausebutton = joystick->nbuttons - 1; /* The pause button is always last. */
const Uint32 PAUSE_RELEASE_DELAY_MS = 100;
if (controller.extendedGamepad) {
GCExtendedGamepad *gamepad = controller.extendedGamepad;
@ -647,17 +650,21 @@ SDL_SYS_MFIJoystickUpdate(SDL_Joystick * joystick)
}
for (i = 0; i < joystick->hwdata->num_pause_presses; i++) {
/* The pause button is always last. */
Uint8 pausebutton = joystick->nbuttons - 1;
SDL_PrivateJoystickButton(joystick, pausebutton, SDL_PRESSED);
SDL_PrivateJoystickButton(joystick, pausebutton, SDL_RELEASED);
joystick->hwdata->pause_button_down_time = SDL_GetTicks();
if (!joystick->hwdata->pause_button_down_time) {
joystick->hwdata->pause_button_down_time = 1;
}
updateplayerindex = YES;
}
joystick->hwdata->num_pause_presses = 0;
if (joystick->hwdata->pause_button_down_time &&
SDL_TICKS_PASSED(SDL_GetTicks(), joystick->hwdata->pause_button_down_time + PAUSE_RELEASE_DELAY_MS)) {
SDL_PrivateJoystickButton(joystick, pausebutton, SDL_RELEASED);
joystick->hwdata->pause_button_down_time = 0;
}
if (updateplayerindex && controller.playerIndex == -1) {
BOOL usedPlayerIndexSlots[4] = {NO, NO, NO, NO};

View File

@ -35,6 +35,7 @@ typedef struct joystick_hwdata
GCController __unsafe_unretained *controller;
int num_pause_presses;
Uint32 pause_button_down_time;
char *name;
SDL_Joystick *joystick;