Adds function SDL_JoystickGetDeviceHWID() to get the hardware ID of a joystick so devices can be uniquely referenced over program executions.
An example would be one SDL application launching another SDL application, passing it the HWID of the joystick that is to be the "primary" controller.
This commit is contained in:
parent
f6027780aa
commit
f1003e7110
6 changed files with 41 additions and 0 deletions
|
@ -144,6 +144,12 @@ extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
|
|||
*/
|
||||
extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
|
||||
|
||||
/**
|
||||
* Return the HWID for the joystick at this index
|
||||
* This can be called before any joysticks are opened.
|
||||
*/
|
||||
extern DECLSPEC const char *SDLCALL SDL_JoystickGetDeviceHWID(int device_index);
|
||||
|
||||
/**
|
||||
* Get the USB vendor ID of a joystick, if available.
|
||||
* This can be called before any joysticks are opened.
|
||||
|
|
|
@ -196,6 +196,7 @@
|
|||
#define SDL_JoystickNameForIndex SDL_JoystickNameForIndex_REAL
|
||||
#define SDL_JoystickOpen SDL_JoystickOpen_REAL
|
||||
#define SDL_JoystickName SDL_JoystickName_REAL
|
||||
#define SDL_JoystickGetDeviceHWID SDL_JoystickGetDeviceHWID_REAL
|
||||
#define SDL_JoystickGetDeviceGUID SDL_JoystickGetDeviceGUID_REAL
|
||||
#define SDL_JoystickGetGUID SDL_JoystickGetGUID_REAL
|
||||
#define SDL_JoystickGetGUIDString SDL_JoystickGetGUIDString_REAL
|
||||
|
|
|
@ -229,6 +229,7 @@ SDL_DYNAPI_PROC(SDL_Joystick*,SDL_JoystickOpen,(int a),(a),return)
|
|||
SDL_DYNAPI_PROC(const char*,SDL_JoystickName,(SDL_Joystick *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetDeviceGUID,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetGUID,(SDL_Joystick *a),(a),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_JoystickGetDeviceHWID,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_JoystickGetGUIDString,(SDL_JoystickGUID a, char *b, int c),(a,b,c),)
|
||||
SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetGUIDFromString,(const char *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickGetAttached,(SDL_Joystick *a),(a),return)
|
||||
|
|
|
@ -1448,6 +1448,21 @@ int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id)
|
|||
return device_index;
|
||||
}
|
||||
|
||||
/* return the hwid for this index */
|
||||
const char * SDL_JoystickGetDeviceHWID(int device_index)
|
||||
{
|
||||
SDL_JoystickDriver *driver;
|
||||
const char *hwid = NULL;
|
||||
|
||||
SDL_LockJoysticks();
|
||||
if (SDL_GetDriverAndJoystickIndex(device_index, &driver, &device_index)) {
|
||||
hwid = driver->GetDeviceHWID(device_index);
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
return hwid;
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
|
||||
{
|
||||
if (!SDL_PrivateJoystickValid(joystick)) {
|
||||
|
|
|
@ -138,6 +138,9 @@ typedef struct _SDL_JoystickDriver
|
|||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void (*Quit)(void);
|
||||
|
||||
/* Function to get the hardware-id of a joystick */
|
||||
const char *(*GetDeviceHWID)(int device_index);
|
||||
|
||||
} SDL_JoystickDriver;
|
||||
|
||||
/* The available joystick drivers */
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/joystick.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_joystick.h"
|
||||
|
@ -73,6 +74,7 @@ typedef struct SDL_joylist_item
|
|||
|
||||
/* Steam Controller support */
|
||||
SDL_bool m_bSteamController;
|
||||
char *hwid; /* 0f34:123e */
|
||||
} SDL_joylist_item;
|
||||
|
||||
static SDL_joylist_item *SDL_joylist = NULL;
|
||||
|
@ -339,6 +341,9 @@ MaybeAddDevice(const char *path)
|
|||
return -1;
|
||||
}
|
||||
|
||||
sprintf( namebuf, "%x:%x", major( sb.st_rdev ), minor( sb.st_rdev ) );
|
||||
item->hwid = SDL_strdup(namebuf);
|
||||
|
||||
item->device_instance = SDL_GetNextJoystickInstanceID();
|
||||
if (SDL_joylist_tail == NULL) {
|
||||
SDL_joylist = SDL_joylist_tail = item;
|
||||
|
@ -391,6 +396,7 @@ MaybeRemoveDevice(const char *path)
|
|||
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item->hwid);
|
||||
SDL_free(item);
|
||||
return retval;
|
||||
}
|
||||
|
@ -458,6 +464,7 @@ static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickG
|
|||
if ((item->path == NULL) || (item->name == NULL)) {
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item->hwid);
|
||||
SDL_free(item);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
@ -594,6 +601,12 @@ LINUX_JoystickGetDeviceGUID( int device_index )
|
|||
return JoystickByDevIndex(device_index)->guid;
|
||||
}
|
||||
|
||||
static const char *
|
||||
LINUX_JoystickGetDeviceHWID( int device_index )
|
||||
{
|
||||
return JoystickByDevIndex(device_index)->hwid;
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
static SDL_JoystickID
|
||||
LINUX_JoystickGetDeviceInstanceID(int device_index)
|
||||
|
@ -1089,6 +1102,7 @@ LINUX_JoystickQuit(void)
|
|||
next = item->next;
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item->hwid);
|
||||
SDL_free(item);
|
||||
}
|
||||
|
||||
|
@ -1118,6 +1132,7 @@ SDL_JoystickDriver SDL_LINUX_JoystickDriver =
|
|||
LINUX_JoystickUpdate,
|
||||
LINUX_JoystickClose,
|
||||
LINUX_JoystickQuit,
|
||||
LINUX_JoystickGetDeviceHWID,
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_LINUX */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue