| Summary: | Guide button on MFi Gamepad cannot be polled | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Caleb Cornett <spydog> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | minor | ||
| Priority: | P2 | CC: | amaranth72, flibitijibibo, spydog |
| Version: | 2.0.9 | ||
| Hardware: | iPhone/iPod touch | ||
| OS: | iOS (All) | ||
| Attachments: | MFi Guide Button Patch | ||
|
Description
Caleb Cornett
2019-01-18 00:33:07 UTC
Example of what applications have to do if events can't be polled (hopefully you can, but in rare cases you can only GetState): https://github.com/FNA-XNA/FNA/pull/232 Unfortunately Apple doesn't provide APIs to query the state of the pause button on MFi controllers, they only have a callback which occurs at some point during the button press. I suppose it would theoretically be possible to delay the release event for a frame, but it would add some code complexity. It's also worth mentioning that you can *never* guarantee that you'll receive all input events if you only poll instead of using events. For example you could have a frame hitch while the user quickly presses and releases a button, and if the button is supposed to perform an action it would be missed completely if you check the button's state every frame instead of doing the action when a press or release event is received from event polling. Yes, this can't be fixed with Apple's current API. However, if you're using the game controller API, the guide button will remain "pressed" for 250 ms. Take a look at SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS in SDL_gamecontroller.c for details. Created attachment 3588 [details]
MFi Guide Button Patch
Thanks for pointing me in the right direction, Sam. The behavior you described isn't currently working, but I've figured out why. SDL_GameControllerGetButton() doesn't detect the delayed press because the joystick->buttons array does not contain an element for the Guide button. This also has the side effect that polling for the Guide button with this function returns garbage data outside the bounds of the joystick->buttons array (since the array contains nbuttons-1 elements and Guide is always the nbuttons'th button). I've attached a small patch that fixes both problems, enabling the detection of the delayed Guide press from SDL_GameControllerGetButton and thereby fixing the out-of-bounds access issue. Thanks Caleb, the patch looks good. I've applied it at https://hg.libsdl.org/SDL/rev/1fc2169984ad |