Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ dep_option(SDL_HIDAPI_LIBUSB "Use libusb for low level joystick drivers" O
dep_option(SDL_HIDAPI_LIBUSB_SHARED "Dynamically load libusb support" ON "SDL_HIDAPI_LIBUSB;SDL_DEPS_SHARED" OFF)
dep_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" ON SDL_HIDAPI OFF)
dep_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON SDL_HIDAPI OFF)
option(SDL_DSU_JOYSTICK "Enable DSU client joystick support" ON)
set_option(SDL_LIBUDEV "Enable libudev support" ON)
set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
set_option(SDL_CCACHE "Use Ccache to speed up build" OFF)
Expand Down Expand Up @@ -1374,6 +1375,34 @@ if(SDL_JOYSTICK)
"${SDL3_SOURCE_DIR}/src/joystick/virtual/*.h"
)
endif()

# DSU (DualShock UDP) client support
if(SDL_DSU_JOYSTICK)
# Disable DSU for platforms that don't support UDP sockets
if(EMSCRIPTEN)
message(STATUS "DSU joystick disabled on Emscripten (no UDP socket support)")
set(SDL_DSU_JOYSTICK OFF)
else()
set(SDL_JOYSTICK_DSU 1)
sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/joystick/dsu/*.c"
"${SDL3_SOURCE_DIR}/src/joystick/dsu/*.h"
)

# DSU requires network libraries
if(WIN32)
sdl_link_dependency(dsu LIBS ws2_32)
elseif(HAIKU)
sdl_link_dependency(dsu LIBS network)
elseif(APPLE)
# macOS/iOS have sockets built-in, no extra linking needed
elseif(ANDROID)
# Android has sockets built-in, no extra linking needed
elseif(UNIX)
# Other Unix systems typically have sockets built-in
endif()
endif()
endif()
endif()

if(SDL_VIDEO)
Expand Down
50 changes: 50 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,56 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_WGI "SDL_JOYSTICK_WGI"

/**
* A variable controlling whether the DSU (DualShock UDP) joystick driver should be used.
*
* This variable can be set to the following values:
*
* - "0": DSU driver is disabled
* - "1": DSU driver is enabled (default)
*
* The DSU driver allows SDL to connect to DSU servers (DS4Windows, BetterJoy, etc.)
* to receive controller data over UDP, including motion sensors and touchpad data.
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.2.0.
*/
#define SDL_HINT_JOYSTICK_DSU "SDL_JOYSTICK_DSU"

/**
* A variable controlling the DSU server address.
*
* The default value is "127.0.0.1"
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.2.0.
*/
#define SDL_HINT_DSU_SERVER "SDL_DSU_SERVER"

/**
* A variable controlling the DSU server port.
*
* The default value is "26760"
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.2.0.
*/
#define SDL_HINT_DSU_SERVER_PORT "SDL_DSU_SERVER_PORT"

/**
* A variable controlling the DSU client port.
*
* The default value is "0" (auto-select)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.2.0.
*/
#define SDL_HINT_DSU_CLIENT_PORT "SDL_DSU_CLIENT_PORT"

/**
* A variable containing a list of wheel style controllers.
*
Expand Down
1 change: 1 addition & 0 deletions include/build_config/SDL_build_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
#cmakedefine SDL_JOYSTICK_RAWINPUT 1
#cmakedefine SDL_JOYSTICK_USBHID 1
#cmakedefine SDL_JOYSTICK_VIRTUAL 1
#cmakedefine SDL_JOYSTICK_DSU 1
#cmakedefine SDL_JOYSTICK_VITA 1
#cmakedefine SDL_JOYSTICK_WGI 1
#cmakedefine SDL_JOYSTICK_XINPUT 1
Expand Down
1 change: 1 addition & 0 deletions include/build_config/SDL_build_config_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ typedef unsigned int uintptr_t;
#define SDL_JOYSTICK_HIDAPI 1
#define SDL_JOYSTICK_RAWINPUT 1
#define SDL_JOYSTICK_VIRTUAL 1
#define SDL_JOYSTICK_DSU 1
#ifdef HAVE_WINDOWS_GAMING_INPUT_H
#define SDL_JOYSTICK_WGI 1
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/joystick/SDL_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#include "./virtual/SDL_virtualjoystick_c.h"
#endif

#ifdef SDL_JOYSTICK_DSU
#include "./dsu/SDL_dsujoystick_c.h"
#endif

static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#ifdef SDL_JOYSTICK_HIDAPI // Highest priority driver for supported devices
&SDL_HIDAPI_JoystickDriver,
Expand Down Expand Up @@ -100,6 +104,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#ifdef SDL_JOYSTICK_VIRTUAL
&SDL_VIRTUAL_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_DSU
&SDL_DSU_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_VITA
&SDL_VITA_JoystickDriver,
#endif
Expand Down
1 change: 1 addition & 0 deletions src/joystick/SDL_sysjoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ extern SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver;
extern SDL_JoystickDriver SDL_IOS_JoystickDriver;
extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
extern SDL_JoystickDriver SDL_DSU_JoystickDriver;
extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
Expand Down
Loading
Loading