From b54f6044a5a15f06e121794d38294cbdc8379d1c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 14 Nov 2024 21:09:17 -0800
Subject: [PATCH] Removed Linux Steam Controller support
The HIDAPI driver has all the functionality we need on Linux
---
CMakeLists.txt | 3 -
Xcode/SDL/SDL.xcodeproj/project.pbxproj | 16 ---
src/joystick/linux/SDL_sysjoystick.c | 141 +++++------------------
src/joystick/steam/SDL_steamcontroller.c | 49 --------
src/joystick/steam/SDL_steamcontroller.h | 37 ------
5 files changed, 29 insertions(+), 217 deletions(-)
delete mode 100644 src/joystick/steam/SDL_steamcontroller.c
delete mode 100644 src/joystick/steam/SDL_steamcontroller.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index acc7a606a7508..f8211a49662eb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1295,7 +1295,6 @@ if(ANDROID)
set(SDL_JOYSTICK_ANDROID 1)
sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/joystick/android/*.c"
- "${SDL3_SOURCE_DIR}/src/joystick/steam/*.c"
)
set(HAVE_SDL_JOYSTICK TRUE)
endif()
@@ -1741,7 +1740,6 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
set(SDL_JOYSTICK_LINUX 1)
sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/joystick/linux/*.c"
- "${SDL3_SOURCE_DIR}/src/joystick/steam/*.c"
)
set(HAVE_SDL_JOYSTICK TRUE)
endif()
@@ -2146,7 +2144,6 @@ elseif(APPLE)
if(SDL_JOYSTICK)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/apple/*.m")
if(IOS OR TVOS OR VISIONOS OR WATCHOS)
- sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/steam/*.c")
set(SDL_JOYSTICK_MFI 1)
if(IOS OR VISIONOS OR WATCHOS)
set(SDL_FRAMEWORK_COREMOTION 1)
diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
index fa24e8d615b00..2513ef271ba72 100644
--- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj
+++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
@@ -346,8 +346,6 @@
A7D8BBA523E2514500DCD162 /* SDL_events_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A94223E2514000DCD162 /* SDL_events_c.h */; };
A7D8BBAB23E2514500DCD162 /* SDL_windowevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A94323E2514000DCD162 /* SDL_windowevents_c.h */; };
A7D8BBB123E2514500DCD162 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A94423E2514000DCD162 /* SDL_assert.c */; };
- A7D8BBC523E2561500DCD162 /* SDL_steamcontroller.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A7A723E2513E00DCD162 /* SDL_steamcontroller.c */; };
- A7D8BBC723E2561500DCD162 /* SDL_steamcontroller.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A7A523E2513E00DCD162 /* SDL_steamcontroller.h */; };
A7D8BBD223E2574800DCD162 /* SDL_uikitappdelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A62F23E2513D00DCD162 /* SDL_uikitappdelegate.h */; };
A7D8BBD323E2574800DCD162 /* SDL_uikitappdelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A61E23E2513D00DCD162 /* SDL_uikitappdelegate.m */; };
A7D8BBD423E2574800DCD162 /* SDL_uikitclipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D8A62123E2513D00DCD162 /* SDL_uikitclipboard.h */; };
@@ -798,8 +796,6 @@
A7D8A78823E2513E00DCD162 /* SDL_sysmutex_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sysmutex_c.h; sourceTree = "<group>"; };
A7D8A79E23E2513E00DCD162 /* SDL_gamepad_db.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gamepad_db.h; sourceTree = "<group>"; };
A7D8A7A023E2513E00DCD162 /* SDL_sysjoystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_sysjoystick.c; sourceTree = "<group>"; };
- A7D8A7A523E2513E00DCD162 /* SDL_steamcontroller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_steamcontroller.h; sourceTree = "<group>"; };
- A7D8A7A723E2513E00DCD162 /* SDL_steamcontroller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_steamcontroller.c; sourceTree = "<group>"; };
A7D8A7A923E2513E00DCD162 /* SDL_joystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_joystick.c; sourceTree = "<group>"; };
A7D8A7AD23E2513E00DCD162 /* SDL_gamepad.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gamepad.c; sourceTree = "<group>"; };
A7D8A7C223E2513E00DCD162 /* SDL_hidapi_xbox360.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_xbox360.c; sourceTree = "<group>"; };
@@ -1857,7 +1853,6 @@
A7D8A7CC23E2513E00DCD162 /* darwin */,
A7D8A79F23E2513E00DCD162 /* dummy */,
A7D8A7BE23E2513E00DCD162 /* hidapi */,
- A7D8A7A123E2513E00DCD162 /* steam */,
75E09157241EA924004729E1 /* virtual */,
F362B9152B3349E200D30B94 /* controller_list.h */,
F3820712284F3609004DD584 /* controller_type.c */,
@@ -1883,15 +1878,6 @@
path = dummy;
sourceTree = "<group>";
};
- A7D8A7A123E2513E00DCD162 /* steam */ = {
- isa = PBXGroup;
- children = (
- A7D8A7A723E2513E00DCD162 /* SDL_steamcontroller.c */,
- A7D8A7A523E2513E00DCD162 /* SDL_steamcontroller.h */,
- );
- path = steam;
- sourceTree = "<group>";
- };
A7D8A7AA23E2513E00DCD162 /* apple */ = {
isa = PBXGroup;
children = (
@@ -2601,7 +2587,6 @@
F310138F2C1F2CB700FBE946 /* SDL_sysstdlib.h in Headers */,
F3F7D8F52933074E00816151 /* SDL_stdinc.h in Headers */,
F362B91B2B3349E200D30B94 /* SDL_steam_virtual_gamepad.h in Headers */,
- A7D8BBC723E2561500DCD162 /* SDL_steamcontroller.h in Headers */,
F3F7D9312933074E00816151 /* SDL_surface.h in Headers */,
A7D8B85A23E2514400DCD162 /* SDL_sysaudio.h in Headers */,
A7D8AAD423E2514100DCD162 /* SDL_syshaptic.h in Headers */,
@@ -2905,7 +2890,6 @@
E4F257922C81903800FCEAFC /* Metal_Blit.metal in Sources */,
A7D8AF2423E2514100DCD162 /* SDL_cocoametalview.m in Sources */,
A7D8B86023E2514400DCD162 /* SDL_audiotypecvt.c in Sources */,
- A7D8BBC523E2561500DCD162 /* SDL_steamcontroller.c in Sources */,
A7D8AD3223E2514100DCD162 /* SDL_blit_N.c in Sources */,
A7D8BB7B23E2514500DCD162 /* SDL_dropevents.c in Sources */,
A7D8BACD23E2514500DCD162 /* e_atan2.c in Sources */,
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index d6b0e1e37b494..ed7cf8f2aeffb 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -46,7 +46,6 @@
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#include "../usb_ids.h"
-#include "../steam/SDL_steamcontroller.h"
#include "SDL_sysjoystick_c.h"
#include "../hidapi/SDL_hidapijoystick_c.h"
@@ -158,9 +157,6 @@ typedef struct SDL_joylist_item
struct joystick_hwdata *hwdata;
struct SDL_joylist_item *next;
- // Steam Controller support
- bool m_bSteamController;
-
bool checked_mapping;
SDL_GamepadMapping *mapping;
} SDL_joylist_item;
@@ -664,64 +660,6 @@ static void HandlePendingRemovals(void)
}
}
-static bool SteamControllerConnectedCallback(const char *name, SDL_GUID guid, SDL_JoystickID *device_instance)
-{
- Uint16 vendor, product, version;
- SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version, NULL);
- if (SDL_JoystickHandledByAnotherDriver(&SDL_LINUX_JoystickDriver, vendor, product, version, name)) {
- return false;
- }
-
- SDL_joylist_item *item = (SDL_joylist_item *)SDL_calloc(1, sizeof(SDL_joylist_item));
- if (!item) {
- return false;
- }
-
- item->path = SDL_strdup("");
- item->name = SDL_strdup(name);
- item->guid = guid;
- item->m_bSteamController = true;
-
- if ((!item->path) || (!item->name)) {
- FreeJoylistItem(item);
- return false;
- }
-
- *device_instance = item->device_instance = SDL_GetNextObjectID();
- SDL_LockJoysticks();
- if (!SDL_joylist_tail) {
- SDL_joylist = SDL_joylist_tail = item;
- } else {
- SDL_joylist_tail->next = item;
- SDL_joylist_tail = item;
- }
-
- // Need to increment the joystick count before we post the event
- ++numjoysticks;
-
- SDL_PrivateJoystickAdded(item->device_instance);
- SDL_UnlockJoysticks();
-
- return true;
-}
-
-static void SteamControllerDisconnectedCallback(SDL_JoystickID device_instance)
-{
- SDL_joylist_item *item;
- SDL_joylist_item *prev = NULL;
-
- SDL_LockJoysticks();
- for (item = SDL_joylist; item; item = item->next) {
- // found it, remove it.
- if (item->device_instance == device_instance) {
- RemoveJoylistItem(item, prev);
- break;
- }
- prev = item;
- }
- SDL_UnlockJoysticks();
-}
-
static bool StrIsInteger(const char *string)
{
const char *p;
@@ -1023,8 +961,6 @@ static void LINUX_JoystickDetect(void)
}
HandlePendingRemovals();
-
- SDL_UpdateSteamControllers();
}
static bool LINUX_JoystickIsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
@@ -1060,9 +996,6 @@ static bool LINUX_JoystickInit(void)
SDL_free(envcopy);
}
- SDL_InitSteamControllers(SteamControllerConnectedCallback,
- SteamControllerDisconnectedCallback);
-
// Force immediate joystick detection if using fallback
last_joy_detect_time = 0;
last_input_dir_mtime = 0;
@@ -1523,52 +1456,43 @@ static bool PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item
joystick->hwdata->item_sensor = item_sensor;
joystick->hwdata->guid = item->guid;
joystick->hwdata->effect.id = -1;
- joystick->hwdata->m_bSteamController = item->m_bSteamController;
SDL_memset(joystick->hwdata->key_map, 0xFF, sizeof(joystick->hwdata->key_map));
SDL_memset(joystick->hwdata->abs_map, 0xFF, sizeof(joystick->hwdata->abs_map));
- if (item->m_bSteamController) {
- joystick->hwdata->fd = -1;
- joystick->hwdata->fd_sensor = -1;
- SDL_GetSteamControllerInputs(&joystick->nbuttons,
- &joystick->naxes,
- &joystick->nhats);
- } else {
- int fd = -1, fd_sensor = -1;
- // Try read-write first, so we can do rumble
- fd = open(item->path, O_RDWR | O_CLOEXEC, 0);
- if (fd < 0) {
- // Try read-only again, at least we'll get events in this case
- fd = open(item->path, O_RDONLY | O_CLOEXEC, 0);
- }
- if (fd < 0) {
- return SDL_SetError("Unable to open %s", item->path);
- }
- // If opening sensor fail, continue with buttons and axes only
- if (item_sensor) {
- fd_sensor = open(item_sensor->path, O_RDONLY | O_CLOEXEC, 0);
- }
-
- joystick->hwdata->fd = fd;
- joystick->hwdata->fd_sensor = fd_sensor;
- joystick->hwdata->fname = SDL_strdup(item->path);
- if (!joystick->hwdata->fname) {
- close(fd);
- if (fd_sensor >= 0) {
- close(fd_sensor);
- }
- return false;
- }
+ int fd = -1, fd_sensor = -1;
+ // Try read-write first, so we can do rumble
+ fd = open(item->path, O_RDWR | O_CLOEXEC, 0);
+ if (fd < 0) {
+ // Try read-only again, at least we'll get events in this case
+ fd = open(item->path, O_RDONLY | O_CLOEXEC, 0);
+ }
+ if (fd < 0) {
+ return SDL_SetError("Unable to open %s", item->path);
+ }
+ // If opening sensor fail, continue with buttons and axes only
+ if (item_sensor) {
+ fd_sensor = open(item_sensor->path, O_RDONLY | O_CLOEXEC, 0);
+ }
- // Set the joystick to non-blocking read mode
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ joystick->hwdata->fd = fd;
+ joystick->hwdata->fd_sensor = fd_sensor;
+ joystick->hwdata->fname = SDL_strdup(item->path);
+ if (!joystick->hwdata->fname) {
+ close(fd);
if (fd_sensor >= 0) {
- fcntl(fd_sensor, F_SETFL, O_NONBLOCK);
+ close(fd_sensor);
}
+ return false;
+ }
- // Get the number of buttons and axes on the joystick
- ConfigJoystick(joystick, fd, fd_sensor);
+ // Set the joystick to non-blocking read mode
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ if (fd_sensor >= 0) {
+ fcntl(fd_sensor, F_SETFL, O_NONBLOCK);
}
+
+ // Get the number of buttons and axes on the joystick
+ ConfigJoystick(joystick, fd, fd_sensor);
return true;
}
@@ -2207,11 +2131,6 @@ static void LINUX_JoystickUpdate(SDL_Joystick *joystick)
SDL_AssertJoysticksLocked();
- if (joystick->hwdata->m_bSteamController) {
- SDL_UpdateSteamController(joystick);
- return;
- }
-
if (joystick->hwdata->classic) {
HandleClassicEvents(joystick);
} else {
@@ -2298,8 +2217,6 @@ static void LINUX_JoystickQuit(void)
SDL_UDEV_Quit();
}
#endif
-
- SDL_QuitSteamControllers();
}
/*
diff --git a/src/joystick/steam/SDL_steamcontroller.c b/src/joystick/steam/SDL_steamcontroller.c
deleted file mode 100644
index d2bd3eccf2b3f..0000000000000
--- a/src/joystick/steam/SDL_steamcontroller.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2024 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.
-*/
-#include "SDL_internal.h"
-
-#include "../SDL_sysjoystick.h"
-#include "../SDL_joystick_c.h"
-#include "SDL_steamcontroller.h"
-
-void SDL_InitSteamControllers(SteamControllerConnectedCallback_t connectedCallback,
- SteamControllerDisconnectedCallback_t disconnectedCallback)
-{
-}
-
-void SDL_GetSteamControllerInputs(int *nbuttons, int *naxes, int *nhats)
-{
- *nbuttons = 0;
- *naxes = 0;
- *nhats = 0;
-}
-
-void SDL_UpdateSteamControllers(void)
-{
-}
-
-void SDL_UpdateSteamController(SDL_Joystick *joystick)
-{
-}
-
-void SDL_QuitSteamControllers(void)
-{
-}
diff --git a/src/joystick/steam/SDL_steamcontroller.h b/src/joystick/steam/SDL_steamcontroller.h
deleted file mode 100644
index 8468aa0a90454..0000000000000
--- a/src/joystick/steam/SDL_steamcontroller.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2024 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_steamcontroller_h_
-#define SDL_steamcontroller_h_
-
-#include "SDL_internal.h"
-
-typedef bool (*SteamControllerConnectedCallback_t)(const char *name, SDL_GUID guid, SDL_JoystickID *device_instance);
-typedef void (*SteamControllerDisconnectedCallback_t)(SDL_JoystickID device_instance);
-
-void SDL_InitSteamControllers(SteamControllerConnectedCallback_t connectedCallback,
- SteamControllerDisconnectedCallback_t disconnectedCallback);
-void SDL_GetSteamControllerInputs(int *nbuttons, int *naxes, int *nhats);
-void SDL_UpdateSteamControllers(void);
-void SDL_UpdateSteamController(SDL_Joystick *joystick);
-void SDL_QuitSteamControllers(void);
-
-#endif // SDL_steamcontroller_h_