mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
Haptic/Linux: Keep track of device numbers properly to track duplicates.
Fixes Bugzilla #3014.
This commit is contained in:
parent
d797582376
commit
0c3830a9a9
@ -59,6 +59,7 @@ typedef struct SDL_hapticlist_item
|
|||||||
{
|
{
|
||||||
char *fname; /* Dev path name (like /dev/input/event1) */
|
char *fname; /* Dev path name (like /dev/input/event1) */
|
||||||
SDL_Haptic *haptic; /* Associated haptic. */
|
SDL_Haptic *haptic; /* Associated haptic. */
|
||||||
|
dev_t dev_num;
|
||||||
struct SDL_hapticlist_item *next;
|
struct SDL_hapticlist_item *next;
|
||||||
} SDL_hapticlist_item;
|
} SDL_hapticlist_item;
|
||||||
|
|
||||||
@ -236,15 +237,11 @@ void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const
|
|||||||
static int
|
static int
|
||||||
MaybeAddDevice(const char *path)
|
MaybeAddDevice(const char *path)
|
||||||
{
|
{
|
||||||
dev_t dev_nums[MAX_HAPTICS];
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int fd;
|
int fd;
|
||||||
int k;
|
|
||||||
int duplicate;
|
|
||||||
int success;
|
int success;
|
||||||
SDL_hapticlist_item *item;
|
SDL_hapticlist_item *item;
|
||||||
|
|
||||||
|
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -255,15 +252,11 @@ MaybeAddDevice(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check for duplicates */
|
/* check for duplicates */
|
||||||
duplicate = 0;
|
for (item = SDL_hapticlist; item != NULL; item = item->next) {
|
||||||
for (k = 0; (k < numhaptics) && !duplicate; ++k) {
|
if (item->dev_num == sb.st_rdev) {
|
||||||
if (sb.st_rdev == dev_nums[k]) {
|
return -1; /* duplicate. */
|
||||||
duplicate = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try to open */
|
/* try to open */
|
||||||
fd = open(path, O_RDWR, 0);
|
fd = open(path, O_RDWR, 0);
|
||||||
@ -293,6 +286,8 @@ MaybeAddDevice(const char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item->dev_num = sb.st_rdev;
|
||||||
|
|
||||||
/* TODO: should we add instance IDs? */
|
/* TODO: should we add instance IDs? */
|
||||||
if (SDL_hapticlist_tail == NULL) {
|
if (SDL_hapticlist_tail == NULL) {
|
||||||
SDL_hapticlist = SDL_hapticlist_tail = item;
|
SDL_hapticlist = SDL_hapticlist_tail = item;
|
||||||
@ -301,8 +296,6 @@ MaybeAddDevice(const char *path)
|
|||||||
SDL_hapticlist_tail = item;
|
SDL_hapticlist_tail = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_nums[numhaptics] = sb.st_rdev;
|
|
||||||
|
|
||||||
++numhaptics;
|
++numhaptics;
|
||||||
|
|
||||||
/* !!! TODO: Send a haptic add event? */
|
/* !!! TODO: Send a haptic add event? */
|
||||||
@ -546,7 +539,6 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
|
|||||||
int ret;
|
int ret;
|
||||||
SDL_hapticlist_item *item;
|
SDL_hapticlist_item *item;
|
||||||
|
|
||||||
|
|
||||||
/* Find the joystick in the haptic list. */
|
/* Find the joystick in the haptic list. */
|
||||||
for (item = SDL_hapticlist; item; item = item->next) {
|
for (item = SDL_hapticlist; item; item = item->next) {
|
||||||
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
|
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user