Fixed bug 4600 - Dualshock 4 touchpad press is not detectable with SDL_JoystickGetButton
authorSam Lantinga
Sat, 08 Jun 2019 14:32:19 -0700
changeset 127905196f7a4d659
parent 12789 0b44d4aae5fc
child 12791 74a69d4d9e9a
Fixed bug 4600 - Dualshock 4 touchpad press is not detectable with SDL_JoystickGetButton

Dexter Friedman

When using a Dualshock 4 controller (model numbers CUH-ZCT1U and CUH-ZCT2U), pressing anywhere on the center touchpad does not send an SDL_JOYBUTTONDOWN event. I have verified this with testjoystick:

Repro steps:
1. Plug in a DS4 over USB
2. Compile testjoystick and run: testjoystick.exe 0
3. Press and hold the touchpad. Observe that no lime green box appears

Expected behavior:
A lime green box appears while the touchpad is pressed.

Notes:
I've attached a patch here that works on my PC and produces the expected behavior in testjoystick, for both DS4 model numbers I listed earlier.

If I understand correctly, by exposing this as a joystick button, the gamecontroller API mapping can be modified with a change to gamecontrollerdb.txt in the future.
src/joystick/hidapi/SDL_hidapi_ps4.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c	Sat Jun 08 14:29:05 2019 -0700
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c	Sat Jun 08 14:32:19 2019 -0700
     1.3 @@ -360,7 +360,7 @@
     1.4      HIDAPI_DriverPS4_Rumble(context, joystick, 0, 0, 0);
     1.5  
     1.6      /* Initialize the joystick capabilities */
     1.7 -    joystick->nbuttons = SDL_CONTROLLER_BUTTON_MAX;
     1.8 +    joystick->nbuttons = 16;
     1.9      joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
    1.10      joystick->epowerlevel = SDL_JOYSTICK_POWER_WIRED;
    1.11  
    1.12 @@ -515,6 +515,7 @@
    1.13          Uint8 data = (packet->rgucButtonsHatAndCounter[2] & 0x03);
    1.14  
    1.15          SDL_PrivateJoystickButton(joystick, SDL_CONTROLLER_BUTTON_GUIDE, (data & 0x01) ? SDL_PRESSED : SDL_RELEASED);
    1.16 +        SDL_PrivateJoystickButton(joystick, 15, (data & 0x02) ? SDL_PRESSED : SDL_RELEASED);
    1.17      }
    1.18  
    1.19      axis = ((int)packet->ucTriggerLeft * 257) - 32768;