Problems to get touchpad finger position

Hello everyone,

First, thank you, SDL developers and contributors, for making such a good library.

I’m trying to get the PS4 controller (Dualshock Wireless Controller) touchpad information, specifically finger position (X and Y). I don’t know what I’m doing wrong, but the touch Y value (SDL_Event.tfinger.y) is always 0 or 1 (X works fine).

I’m opening the controller with SDL_OpenGamepad(joy_index), activating the motion sensors using SDL_SetGamepadSensorEnabled(SDL_Gamepad_instance, SDL_SENSOR_GYRO, SDL_TRUE) and SDL_SetGamepadSensorEnabled(SDL_Gamepad_instance, SDL_SENSOR_ACCEL, SDL_TRUE). I also enable rumble with SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");.

All other events work as expected. I’m using SDL3 compiled as a static library, but the same behaviour appears with SDL2 and using the system-wide installed package libsdl2-dev (Ubuntu 22.04).

I poll SDL events every 2 ms using SDL_PollEvent, and filter the events manually. The source is available at GitHub - Puara/puara-controller at json.

Thanks in advance

Looking at code and comments in SDL_event.h it seems like the gamepad touchpad events uses a type named SDL_GamepadTouchpadEvent that you access under the name gtouchpad (not tfinger).

1 Like

You’re right! Thank you.

Funny that tfinger also gets some info when I use the gamecontroller touchpad.

SDL_Event is a union so all the different events actually uses the same memory. If you read the wrong one you will just get garbage. If I’m not mistaken, tfinger.x would give you the value of gtouchpad.y because they happen to occupy the same area in memory.

That makes sens. Thank you for the clarification