Include the child serial numbers in the serial number for a HIDAPI combined device
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/joystick/hidapi/SDL_hidapi_combined.c b/src/joystick/hidapi/SDL_hidapi_combined.c
index a0ed2fe..6ccbcbf 100644
--- a/src/joystick/hidapi/SDL_hidapi_combined.c
+++ b/src/joystick/hidapi/SDL_hidapi_combined.c
@@ -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)
@@ -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];
@@ -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;
}