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

Add support for sensor to joystick on Linux (evdev) #7697

Merged
merged 3 commits into from
Jun 26, 2023
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
13 changes: 13 additions & 0 deletions src/SDL_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ int SDL_powerof2(int x)

return value;
}

SDL_bool SDL_endswith(const char *string, const char *suffix)
{
size_t string_length = string ? SDL_strlen(string) : 0;
size_t suffix_length = suffix ? SDL_strlen(suffix) : 0;

if (suffix_length > 0 && suffix_length <= string_length) {
if (SDL_memcmp(string + string_length - suffix_length, suffix, suffix_length) == 0) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
2 changes: 2 additions & 0 deletions src/SDL_utils_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
/* Return the smallest power of 2 greater than or equal to 'x' */
int SDL_powerof2(int x);

SDL_bool SDL_endswith(const char *string, const char *suffix);

#endif /* SDL_utils_h_ */
16 changes: 1 addition & 15 deletions src/joystick/SDL_gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

/* This is the gamepad API for Simple DirectMedia Layer */

#include "../SDL_utils_c.h"
#include "SDL_sysjoystick.h"
#include "SDL_joystick_c.h"
#include "SDL_gamepad_c.h"
Expand Down Expand Up @@ -2056,21 +2057,6 @@ SDL_bool SDL_IsGamepad(SDL_JoystickID instance_id)
return retval;
}

#ifdef __LINUX__
static SDL_bool SDL_endswith(const char *string, const char *suffix)
{
size_t string_length = string ? SDL_strlen(string) : 0;
size_t suffix_length = suffix ? SDL_strlen(suffix) : 0;

if (suffix_length > 0 && suffix_length <= string_length) {
if (SDL_memcmp(string + string_length - suffix_length, suffix, suffix_length) == 0) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
#endif

/*
* Return 1 if the gamepad should be ignored by SDL
*/
Expand Down
Loading