Added SDL_HINT_JOYSTICK_GAMEINPUT

This commit is contained in:
Sam Lantinga
2024-08-09 09:19:32 -07:00
parent 0acf8343bb
commit c2085dad8f
2 changed files with 30 additions and 12 deletions

View File

@@ -1226,6 +1226,21 @@ extern "C" {
*/ */
#define SDL_HINT_JOYSTICK_FLIGHTSTICK_DEVICES_EXCLUDED "SDL_JOYSTICK_FLIGHTSTICK_DEVICES_EXCLUDED" #define SDL_HINT_JOYSTICK_FLIGHTSTICK_DEVICES_EXCLUDED "SDL_JOYSTICK_FLIGHTSTICK_DEVICES_EXCLUDED"
/**
* A variable controlling whether GameInput should be used for
* controller handling on Windows.
*
* The variable can be set to the following values:
*
* - "0": GameInput is not used.
* - "1": GameInput is used. (default)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.0.0.
*/
#define SDL_HINT_JOYSTICK_GAMEINPUT "SDL_JOYSTICK_GAMEINPUT"
/** /**
* A variable containing a list of devices known to have a GameCube form * A variable containing a list of devices known to have a GameCube form
* factor. * factor.

View File

@@ -234,6 +234,10 @@ static int GAMEINPUT_JoystickInit(void)
{ {
HRESULT hR; HRESULT hR;
if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_GAMEINPUT, SDL_TRUE)) {
return 0;
}
if (!g_hGameInputDLL) { if (!g_hGameInputDLL) {
g_hGameInputDLL = SDL_LoadObject("gameinput.dll"); g_hGameInputDLL = SDL_LoadObject("gameinput.dll");
if (!g_hGameInputDLL) { if (!g_hGameInputDLL) {
@@ -310,23 +314,22 @@ static void GAMEINPUT_JoystickDetect(void)
static SDL_bool GAMEINPUT_JoystickIsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name) static SDL_bool GAMEINPUT_JoystickIsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
{ {
int idx = 0;
GAMEINPUT_InternalDevice *elem = NULL;
SDL_AssertJoysticksLocked(); SDL_AssertJoysticksLocked();
if (g_pGameInput) {
if (vendor_id == USB_VENDOR_MICROSOFT && if (vendor_id == USB_VENDOR_MICROSOFT &&
product_id == USB_PRODUCT_XBOX_ONE_XBOXGIP_CONTROLLER) { product_id == USB_PRODUCT_XBOX_ONE_XBOXGIP_CONTROLLER) {
/* The Xbox One controller shows up as a hardcoded raw input VID/PID, which we definitely handle */ /* The Xbox One controller shows up as a hardcoded raw input VID/PID, which we definitely handle */
return SDL_TRUE; return SDL_TRUE;
} }
for (idx = 0; idx < g_GameInputList.count; ++idx) { for (int i = 0; i < g_GameInputList.count; ++i) {
elem = g_GameInputList.devices[idx]; GAMEINPUT_InternalDevice *elem = g_GameInputList.devices[i];
if (elem && vendor_id == elem->info->vendorId && product_id == elem->info->productId) { if (elem && vendor_id == elem->info->vendorId && product_id == elem->info->productId) {
return SDL_TRUE; return SDL_TRUE;
} }
} }
}
return SDL_FALSE; return SDL_FALSE;
} }