Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix joystick events in WaitEventTimeout, fix HapticRumbleSupported return value #238

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/sdl2_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,16 @@ SDL_WaitEventTimeout(SDL2_Event *event2, int timeout)
SDL_Event event3;
const int retval = SDL3_WaitEventTimeout(event2 ? &event3 : NULL, timeout);
if ((retval == 1) && event2) {
/* Ensure joystick and haptic IDs are updated before calling Event3to2() */
switch (event3.type) {
case SDL_EVENT_JOYSTICK_ADDED:
case SDL_EVENT_GAMEPAD_ADDED:
case SDL_EVENT_GAMEPAD_REMOVED:
case SDL_EVENT_JOYSTICK_REMOVED:
SDL_NumJoysticks(); /* Refresh */
SDL_NumHaptics(); /* Refresh */
break;
}
Event3to2(&event3, event2);
}
return retval;
Expand Down Expand Up @@ -8700,6 +8710,15 @@ SDL_HapticIndex(SDL_Haptic *haptic)
return -1;
}

SDL_DECLSPEC int SDLCALL
SDL_HapticRumbleSupported(SDL_Haptic *haptic)
{
if (SDL3_GetHapticID(haptic) == 0) {
return -1;
}
return SDL3_HapticRumbleSupported(haptic) ? SDL2_TRUE : SDL2_FALSE;
}

static Uint16 HapticFeatures3to2(Uint32 features)
{
Uint16 features2 = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/sdl3_syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ SDL3_SYM_RENAMED_RETCODE(bool,HapticPause,PauseHaptic,(SDL_Haptic *a),(a),return
SDL3_SYM_RENAMED_RETCODE(bool,HapticRumbleInit,InitHapticRumble,(SDL_Haptic *a),(a),return)
SDL3_SYM_RENAMED_RETCODE(bool,HapticRumblePlay,PlayHapticRumble,(SDL_Haptic *a, float b, Uint32 c),(a,b,c),return)
SDL3_SYM_RENAMED_RETCODE(bool,HapticRumbleStop,StopHapticRumble,(SDL_Haptic *a),(a),return)
SDL3_SYM_PASSTHROUGH_RETCODE(bool,HapticRumbleSupported,(SDL_Haptic *a),(a),return)
SDL3_SYM_RENAMED_RETCODE(bool,HapticRunEffect,RunHapticEffect,(SDL_Haptic *a, int b, Uint32 c),(a,b,c),return)
SDL3_SYM_RENAMED_RETCODE(bool,HapticSetAutocenter,SetHapticAutocenter,(SDL_Haptic *a, int b),(a,b),return)
SDL3_SYM_RENAMED_RETCODE(bool,HapticSetGain,SetHapticGain,(SDL_Haptic *a, int b),(a,b),return)
Expand Down Expand Up @@ -544,6 +543,7 @@ SDL3_SYM_PASSTHROUGH(void,OnApplicationWillTerminate,(void),(),)
SDL3_SYM(SDL_AudioDeviceID,OpenAudioDevice,(SDL_AudioDeviceID a, const SDL_AudioSpec *b),(a,b),return)
SDL3_SYM(SDL_Gamepad *,OpenGamepad,(SDL_JoystickID a),(a),return)
SDL3_SYM(SDL_Haptic*,OpenHaptic,(SDL_HapticID a),(a),return)
SDL3_SYM(bool,HapticRumbleSupported,(SDL_Haptic *),(a),return)
SDL3_SYM(SDL_IOStream*,OpenIO,(const SDL_IOStreamInterface *a, void *b),(a,b),return)
SDL3_SYM(SDL_Joystick *,OpenJoystick,(SDL_JoystickID a),(a),return)
SDL3_SYM(SDL_Sensor *,OpenSensor,(SDL_SensorID a),(a),return)
Expand Down
Loading