Skip to content

Commit

Permalink
Include the child serial numbers in the serial number for a HIDAPI co…
Browse files Browse the repository at this point in the history
…mbined device
  • Loading branch information
slouken committed Aug 9, 2022
1 parent 523beda commit d90c0d4
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/joystick/hidapi/SDL_hidapi_combined.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "SDL_joystick.h"
#include "SDL_gamecontroller.h"
#include "SDL_hidapijoystick_c.h"

#include "../SDL_sysjoystick.h"

static SDL_bool
HIDAPI_DriverCombined_IsSupportedDevice(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
Expand Down Expand Up @@ -63,6 +63,8 @@ static SDL_bool
HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
{
int i;
char *serial = NULL, *new_serial;
size_t serial_length = 0, new_length;

for (i = 0; i < device->num_children; ++i) {
SDL_HIDAPI_Device *child = device->children[i];
Expand All @@ -71,9 +73,36 @@ HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
child = device->children[i];
child->driver->CloseJoystick(child, joystick);
}
if (serial) {
SDL_free(serial);
}
return SDL_FALSE;
}

/* Extend the serial number with the child serial number */
if (joystick->serial) {
new_length = serial_length + 1 + SDL_strlen(joystick->serial);
new_serial = (char *)SDL_realloc(serial, new_length);
if (new_serial) {
if (serial) {
SDL_strlcat(new_serial, ",", new_length);
SDL_strlcat(new_serial, joystick->serial, new_length);
} else {
SDL_strlcpy(new_serial, joystick->serial, new_length);
}
SDL_free(serial);
serial = new_serial;
serial_length = new_length;
}
}
}

/* Update the joystick with the combined serial numbers */
if (joystick->serial) {
SDL_free(joystick->serial);
}
joystick->serial = serial;

return SDL_TRUE;
}

Expand Down

0 comments on commit d90c0d4

Please sign in to comment.