Merge pull request #13625 from Dentomologist/sdl_verify_touchpad_present_before_getting_input

SDL: Check if touchpad exists before getting input
This commit is contained in:
Jordan Woyak 2025-05-02 21:08:49 -05:00 committed by GitHub
commit a736d2ed5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 5 deletions

View File

@ -362,11 +362,15 @@ public:
const int touchpad_index = 0;
const int finger_index = 0;
Uint8 state = 0;
SDL_GameControllerGetTouchpadFinger(m_gamecontroller, touchpad_index, finger_index, &state,
&m_touchpad_x, &m_touchpad_y, &m_touchpad_pressure);
m_touchpad_x = m_touchpad_x * 2 - 1;
m_touchpad_y = m_touchpad_y * 2 - 1;
if (SDL_GameControllerGetNumTouchpads(m_gamecontroller) > touchpad_index &&
SDL_GameControllerGetNumTouchpadFingers(m_gamecontroller, touchpad_index) > finger_index)
{
Uint8 state = 0;
SDL_GameControllerGetTouchpadFinger(m_gamecontroller, touchpad_index, finger_index, &state,
&m_touchpad_x, &m_touchpad_y, &m_touchpad_pressure);
m_touchpad_x = m_touchpad_x * 2 - 1;
m_touchpad_y = m_touchpad_y * 2 - 1;
}
return Core::DeviceRemoval::Keep;
}