Skip to content

Commit

Permalink
Removed Linux Steam Controller support
Browse files Browse the repository at this point in the history
The HIDAPI driver has all the functionality we need on Linux
  • Loading branch information
slouken committed Nov 15, 2024
1 parent b71151a commit 85b14b8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 217 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions Xcode/SDL/SDL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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>"; };
Expand Down Expand Up @@ -1857,7 +1853,6 @@
A7D8A7CC23E2513E00DCD162 /* darwin */,
A7D8A79F23E2513E00DCD162 /* dummy */,
A7D8A7BE23E2513E00DCD162 /* hidapi */,
A7D8A7A123E2513E00DCD162 /* steam */,
75E09157241EA924004729E1 /* virtual */,
F362B9152B3349E200D30B94 /* controller_list.h */,
F3820712284F3609004DD584 /* controller_type.c */,
Expand All @@ -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 = (
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
141 changes: 29 additions & 112 deletions src/joystick/linux/SDL_sysjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2298,8 +2217,6 @@ static void LINUX_JoystickQuit(void)
SDL_UDEV_Quit();
}
#endif

SDL_QuitSteamControllers();
}

/*
Expand Down
49 changes: 0 additions & 49 deletions src/joystick/steam/SDL_steamcontroller.c

This file was deleted.

37 changes: 0 additions & 37 deletions src/joystick/steam/SDL_steamcontroller.h

This file was deleted.

0 comments on commit 85b14b8

Please sign in to comment.