From ad8a6d2b05c3656f76dea63cac519972456f3dcb Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 27 Dec 2022 10:23:28 -0800
Subject: [PATCH] Split SDL gamepad internal functions into SDL_gamepad_c.h
---
VisualC-GDK/SDL/SDL.vcxproj | 1 +
VisualC-GDK/SDL/SDL.vcxproj.filters | 3 ++
VisualC-WinRT/SDL-UWP.vcxproj | 3 +-
VisualC-WinRT/SDL-UWP.vcxproj.filters | 5 ++-
VisualC/SDL/SDL.vcxproj | 1 +
VisualC/SDL/SDL.vcxproj.filters | 3 ++
src/SDL.c | 1 +
src/joystick/SDL_gamepad.c | 1 +
src/joystick/SDL_gamepad_c.h | 45 +++++++++++++++++++++++++++
src/joystick/SDL_joystick.c | 2 ++
src/joystick/SDL_joystick_c.h | 15 ---------
11 files changed, 63 insertions(+), 17 deletions(-)
create mode 100644 src/joystick/SDL_gamepad_c.h
diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj
index f4640c02cd3a..381213fc0782 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj
+++ b/VisualC-GDK/SDL/SDL.vcxproj
@@ -403,6 +403,7 @@
<ClInclude Include="..\..\src\joystick\controller_type.h" />
<ClInclude Include="..\..\src\joystick\hidapi\SDL_hidapijoystick_c.h" />
<ClInclude Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.h" />
+ <ClInclude Include="..\..\src\joystick\SDL_gamepad_c.h" />
<ClInclude Include="..\..\src\joystick\SDL_gamepad_db.h" />
<ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
<ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters
index 62aff4c97ad8..40c9fd6a77bb 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj.filters
+++ b/VisualC-GDK/SDL/SDL.vcxproj.filters
@@ -483,6 +483,9 @@
<ClInclude Include="..\..\src\haptic\SDL_haptic_c.h">
<Filter>haptic</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\joystick\SDL_gamepad_c.h">
+ <Filter>joystick</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\joystick\SDL_gamepad_db.h">
<Filter>joystick</Filter>
</ClInclude>
diff --git a/VisualC-WinRT/SDL-UWP.vcxproj b/VisualC-WinRT/SDL-UWP.vcxproj
index 1b49d517f4b2..04b21ff445ad 100644
--- a/VisualC-WinRT/SDL-UWP.vcxproj
+++ b/VisualC-WinRT/SDL-UWP.vcxproj
@@ -121,6 +121,7 @@
<ClInclude Include="..\src\haptic\windows\SDL_windowshaptic_c.h" />
<ClInclude Include="..\src\haptic\windows\SDL_xinputhaptic_c.h" />
<ClInclude Include="..\src\joystick\controller_type.h" />
+ <ClInclude Include="..\src\joystick\SDL_gamepad_c.h" />
<ClInclude Include="..\src\joystick\SDL_gamepad_db.h" />
<ClInclude Include="..\src\joystick\SDL_joystick_c.h" />
<ClInclude Include="..\src\joystick\SDL_sysjoystick.h" />
@@ -837,4 +838,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/VisualC-WinRT/SDL-UWP.vcxproj.filters b/VisualC-WinRT/SDL-UWP.vcxproj.filters
index a6be95fe5c83..7127c2c191f7 100644
--- a/VisualC-WinRT/SDL-UWP.vcxproj.filters
+++ b/VisualC-WinRT/SDL-UWP.vcxproj.filters
@@ -162,6 +162,9 @@
<ClInclude Include="..\include\SDL3\SDL_video.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\src\joystick\SDL_gamepad_c.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\src\joystick\SDL_gamepad_db.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -843,4 +846,4 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj
index ea1849f2da87..798033270116 100644
--- a/VisualC/SDL/SDL.vcxproj
+++ b/VisualC/SDL/SDL.vcxproj
@@ -347,6 +347,7 @@
<ClInclude Include="..\..\src\joystick\controller_type.h" />
<ClInclude Include="..\..\src\joystick\hidapi\SDL_hidapijoystick_c.h" />
<ClInclude Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.h" />
+ <ClInclude Include="..\..\src\joystick\SDL_gamepad_c.h" />
<ClInclude Include="..\..\src\joystick\SDL_gamepad_db.h" />
<ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
<ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters
index 260a16a3c691..eb48c1e2dc81 100644
--- a/VisualC/SDL/SDL.vcxproj.filters
+++ b/VisualC/SDL/SDL.vcxproj.filters
@@ -477,6 +477,9 @@
<ClInclude Include="..\..\src\haptic\SDL_haptic_c.h">
<Filter>haptic</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\joystick\SDL_gamepad_c.h">
+ <Filter>joystick</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\joystick\SDL_gamepad_db.h">
<Filter>joystick</Filter>
</ClInclude>
diff --git a/src/SDL.c b/src/SDL.c
index 812995bb0cec..42a8ea273d7b 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -41,6 +41,7 @@
#include "video/SDL_video_c.h"
#include "events/SDL_events_c.h"
#include "haptic/SDL_haptic_c.h"
+#include "joystick/SDL_gamepad_c.h"
#include "joystick/SDL_joystick_c.h"
#include "sensor/SDL_sensor_c.h"
diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index bf59c1db08af..34703fd64579 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -24,6 +24,7 @@
#include "SDL_sysjoystick.h"
#include "SDL_joystick_c.h"
+#include "SDL_gamepad_c.h"
#include "SDL_gamepad_db.h"
#include "controller_type.h"
#include "usb_ids.h"
diff --git a/src/joystick/SDL_gamepad_c.h b/src/joystick/SDL_gamepad_c.h
new file mode 100644
index 000000000000..7316a1de9691
--- /dev/null
+++ b/src/joystick/SDL_gamepad_c.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_gamepad_c_h_
+#define SDL_gamepad_c_h_
+
+#include "SDL_internal.h"
+
+/* Useful functions and variables from SDL_gamepad.c */
+
+/* Initialization and shutdown functions */
+extern int SDL_GamepadInitMappings(void);
+extern void SDL_GamepadQuitMappings(void);
+extern int SDL_GamepadInit(void);
+extern void SDL_GamepadQuit(void);
+
+
+/* Function to return whether a joystick name and GUID is a gamepad */
+extern SDL_bool SDL_IsGamepadNameAndGUID(const char *name, SDL_JoystickGUID guid);
+
+/* Function to return whether a gamepad should be ignored */
+extern SDL_bool SDL_ShouldIgnoreGamepad(const char *name, SDL_JoystickGUID guid);
+
+/* Handle delayed guide button on a gamepad */
+extern void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick);
+
+#endif /* SDL_gamepad_c_h_ */
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 3cd509ae30c6..e1854c3ae174 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -24,6 +24,8 @@
#include "SDL_sysjoystick.h"
#include "../SDL_hints_c.h"
+#include "SDL_gamepad_c.h"
+#include "SDL_joystick_c.h"
#if !SDL_EVENTS_DISABLED
#include "../events/SDL_events_c.h"
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index 45917a19c018..c9e6b491316f 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -52,12 +52,6 @@ extern void SDL_AssertJoysticksLocked(void) SDL_ASSERT_CAPABILITY(SDL_joystick_l
/* Function to get the next available joystick instance ID */
extern SDL_JoystickID SDL_GetNextJoystickInstanceID(void);
-/* Initialization and shutdown functions */
-extern int SDL_GamepadInitMappings(void);
-extern void SDL_GamepadQuitMappings(void);
-extern int SDL_GamepadInit(void);
-extern void SDL_GamepadQuit(void);
-
/* Function to return the device index for a joystick ID, or -1 if not found */
extern int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id);
@@ -137,15 +131,6 @@ extern SDL_bool SDL_IsJoystickVIRTUAL(SDL_JoystickGUID guid);
/* Function to return whether a joystick should be ignored */
extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid);
-/* Function to return whether a joystick name and GUID is a gamepad */
-extern SDL_bool SDL_IsGamepadNameAndGUID(const char *name, SDL_JoystickGUID guid);
-
-/* Function to return whether a gamepad should be ignored */
-extern SDL_bool SDL_ShouldIgnoreGamepad(const char *name, SDL_JoystickGUID guid);
-
-/* Handle delayed guide button on a gamepad */
-extern void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick);
-
/* Internal event queueing functions */
extern void SDL_PrivateJoystickAddTouchpad(SDL_Joystick *joystick, int nfingers);
extern void SDL_PrivateJoystickAddSensor(SDL_Joystick *joystick, SDL_SensorType type, float rate);