From b28d304b235843342819e19238cc5556c1800cf9 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 24 May 2022 17:24:03 -0700
Subject: [PATCH] Only include controller_type.h in SDL_joystick.c
It has a huge array of controllers and we only want it instantiated once
---
src/joystick/SDL_joystick.c | 7 +++++++
src/joystick/SDL_joystick_c.h | 3 +++
src/joystick/windows/SDL_rawinputjoystick.c | 3 +--
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 5288c552a41..362c515709e 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -2062,6 +2062,13 @@ SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 produc
return type;
}
+SDL_bool
+SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id)
+{
+ EControllerType eType = GuessControllerType(vendor_id, product_id);
+ return (eType == k_eControllerType_XBoxOneController);
+}
+
SDL_bool
SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id)
{
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index a7aa6b7145d..d6f3888e162 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -62,6 +62,9 @@ extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromVIDPID(Uint16
extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name);
extern SDL_GameControllerType SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 product, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
+/* Function to return whether a joystick is an Xbox One controller */
+extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
+
/* Function to return whether a joystick is an Xbox One Elite controller */
extern SDL_bool SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id);
diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c
index ca9bd7d3793..d515e2a769d 100644
--- a/src/joystick/windows/SDL_rawinputjoystick.c
+++ b/src/joystick/windows/SDL_rawinputjoystick.c
@@ -40,7 +40,6 @@
#include "SDL_timer.h"
#include "../usb_ids.h"
#include "../SDL_sysjoystick.h"
-#include "../controller_type.h"
#include "../../core/windows/SDL_windows.h"
#include "../../core/windows/SDL_hid.h"
#include "../hidapi/SDL_hidapijoystick_c.h"
@@ -746,7 +745,7 @@ RAWINPUT_AddDevice(HANDLE hDevice)
device->product_id = (Uint16)rdi.hid.dwProductId;
device->version = (Uint16)rdi.hid.dwVersionNumber;
device->is_xinput = SDL_TRUE;
- device->is_xboxone = GuessControllerType(device->vendor_id, device->product_id) == k_eControllerType_XBoxOneController;
+ device->is_xboxone = SDL_IsJoystickXboxOne(device->vendor_id, device->product_id);
/* Get HID Top-Level Collection Preparsed Data */
size = 0;