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

[rcore] [GLFW] [SDL] Add `GetGamepadGUID() #4733

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 7 additions & 0 deletions src/platforms/rcore_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,13 @@ int SetGamepadMappings(const char *mappings)
return 0;
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
TRACELOG(LOG_WARNING, "GetGamepadGUID() not implemented on target platform");
return "";
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/rcore_desktop_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,12 @@ int SetGamepadMappings(const char *mappings)
return glfwUpdateGamepadMappings(mappings);
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
return glfwGetJoystickGUID(gamepad);
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
7 changes: 7 additions & 0 deletions src/platforms/rcore_desktop_rgfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,13 @@ int SetGamepadMappings(const char *mappings)
return 0;
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
TRACELOG(LOG_WARNING, "GetGamepadGUID() not implemented on target platform");
return "";
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
16 changes: 16 additions & 0 deletions src/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
#define MAX_CLIPBOARD_BUFFER_LENGTH 1024 // Size of the clipboard buffer used on GetClipboardText()
#endif

#ifndef MAX_JOYSTICKGUID_BUFFER_LENGTH
#define MAX_JOYSTICKGUID_BUFFER_LENGTH 64 // Size of the joystick GUID buffer used on GetGamepadGUID(), must be at least 33 bytes
#endif

#if ((defined(SDL_MAJOR_VERSION) && (SDL_MAJOR_VERSION == 3)) && (defined(SDL_MINOR_VERSION) && (SDL_MINOR_VERSION >= 1)))
#ifndef PLATFORM_DESKTOP_SDL3
#define PLATFORM_DESKTOP_SDL3
Expand Down Expand Up @@ -1236,6 +1240,18 @@ int SetGamepadMappings(const char *mappings)
return SDL_GameControllerAddMapping(mappings);
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
static char buffer[MAX_JOYSTICKGUID_BUFFER_LENGTH] = { 0 };

SDL_JoystickGUID joystickGUID = SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(platform.gamepad[gamepad]));

SDL_JoystickGetGUIDString(joystickGUID, buffer, MAX_JOYSTICKGUID_BUFFER_LENGTH -1);

return buffer;
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
7 changes: 7 additions & 0 deletions src/platforms/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ int SetGamepadMappings(const char *mappings)
return 0;
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
TRACELOG(LOG_WARNING, "GetGamepadGUID() not implemented on target platform");
return "";
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
7 changes: 7 additions & 0 deletions src/platforms/rcore_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ int SetGamepadMappings(const char *mappings)
return 0;
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
TRACELOG(LOG_WARNING, "GetGamepadGUID() not implemented on target platform");
return "";
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
11 changes: 9 additions & 2 deletions src/platforms/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ bool WindowShouldClose(void)
// REF: https://emscripten.org/docs/porting/asyncify.html

// WindowShouldClose() is not called on a web-ready raylib application if using emscripten_set_main_loop()
// and encapsulating one frame execution on a UpdateDrawFrame() function,
// and encapsulating one frame execution on a UpdateDrawFrame() function,
// allowing the browser to manage execution asynchronously

// Optionally we can manage the time we give-control-back-to-browser if required,
// but it seems below line could generate stuttering on some browsers
emscripten_sleep(12);

return false;
}

Expand Down Expand Up @@ -914,6 +914,13 @@ int SetGamepadMappings(const char *mappings)
return 0;
}

// Get gamepad GUID
const char *GetGamepadGUID(int gamepad)
{
TRACELOG(LOG_WARNING, "GetGamepadGUID() not implemented on target platform");
return "";
}

// Set gamepad vibration
void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration)
{
Expand Down
1 change: 1 addition & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ RLAPI int GetGamepadButtonPressed(void); // Get the last ga
RLAPI int GetGamepadAxisCount(int gamepad); // Get gamepad axis count for a gamepad
RLAPI float GetGamepadAxisMovement(int gamepad, int axis); // Get axis movement value for a gamepad axis
RLAPI int SetGamepadMappings(const char *mappings); // Set internal gamepad mappings (SDL_GameControllerDB)
RLAPI const char *GetGamepadGUID(int gamepad); // Get gamepad GUID
RLAPI void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float duration); // Set gamepad vibration for both motors (duration in seconds)

// Input-related functions: mouse
Expand Down
Loading