Skip to content
Draft
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
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,35 @@ if(SDL_JOYSTICK)
file(GLOB JOYSTICK_VIRTUAL_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/virtual/*.c)
list(APPEND SOURCE_FILES ${JOYSTICK_VIRTUAL_SOURCES})
endif()

# DSU (DualShock UDP) client support
option(SDL_DSU_JOYSTICK "Enable DSU client joystick support" ON)
if(SDL_DSU_JOYSTICK)
set(SDL_JOYSTICK_DSU 1)
file(GLOB JOYSTICK_DSU_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dsu/*.c)
list(APPEND SOURCE_FILES ${JOYSTICK_DSU_SOURCES})

# DSU requires network libraries on Unix-like systems
if(UNIX AND NOT APPLE AND NOT ANDROID)
if(NOT WIN32)
# Check if we need to link against socket libraries
include(CheckFunctionExists)
check_function_exists(socket HAVE_SOCKET_IN_LIBC)
if(NOT HAVE_SOCKET_IN_LIBC)
# Try to find socket in libsocket (Solaris)
check_library_exists(socket socket "" HAVE_LIBSOCKET)
if(HAVE_LIBSOCKET)
list(APPEND EXTRA_LIBS socket)
endif()
# Try to find inet_addr in libnsl (Solaris)
check_library_exists(nsl inet_addr "" HAVE_LIBNSL)
if(HAVE_LIBNSL)
list(APPEND EXTRA_LIBS nsl)
endif()
endif()
endif()
endif()
endif()
endif()

if(SDL_VIDEO)
Expand Down Expand Up @@ -1984,6 +2013,10 @@ elseif(WINDOWS)
# Libraries for Win32 native and MinGW
if(NOT WINDOWS_STORE)
list(APPEND EXTRA_LIBS kernel32 user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)
# Add Winsock library for DSU support
if(SDL_DSU_JOYSTICK)
list(APPEND EXTRA_LIBS ws2_32)
endif()
endif()

if(WINDOWS_STORE)
Expand Down Expand Up @@ -2468,6 +2501,11 @@ elseif(HAIKU)

CheckPTHREAD()
list(APPEND EXTRA_LIBS root be media game device textencoding)

# Add network library for DSU support on Haiku
if(SDL_DSU_JOYSTICK)
list(APPEND EXTRA_LIBS network)
endif()

elseif(RISCOS)
if(SDL_MISC)
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
#cmakedefine SDL_JOYSTICK_RAWINPUT @SDL_JOYSTICK_RAWINPUT@
#cmakedefine SDL_JOYSTICK_EMSCRIPTEN @SDL_JOYSTICK_EMSCRIPTEN@
#cmakedefine SDL_JOYSTICK_VIRTUAL @SDL_JOYSTICK_VIRTUAL@
#cmakedefine SDL_JOYSTICK_DSU @SDL_JOYSTICK_DSU@
#cmakedefine SDL_JOYSTICK_VITA @SDL_JOYSTICK_VITA@
#cmakedefine SDL_JOYSTICK_PSP @SDL_JOYSTICK_PSP@
#cmakedefine SDL_JOYSTICK_PS2 @SDL_JOYSTICK_PS2@
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ typedef unsigned int uintptr_t;
#define SDL_JOYSTICK_RAWINPUT 1
#endif
#define SDL_JOYSTICK_VIRTUAL 1
#define SDL_JOYSTICK_DSU 1
#ifdef HAVE_WINDOWS_GAMING_INPUT_H
#define SDL_JOYSTICK_WGI 1
#endif
Expand Down
34 changes: 34 additions & 0 deletions include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,40 @@ extern "C" {
*/
#define SDL_HINT_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED "SDL_JOYSTICK_HIDAPI_XBOX_ONE_HOME_LED"

/**
* 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.
*/
#define SDL_HINT_JOYSTICK_DSU "SDL_JOYSTICK_DSU"

/**
* A variable controlling the DSU server address.
*
* The default value is "127.0.0.1"
*/
#define SDL_HINT_DSU_SERVER "SDL_DSU_SERVER"

/**
* A variable controlling the DSU server port.
*
* The default value is "26760"
*/
#define SDL_HINT_DSU_SERVER_PORT "SDL_DSU_SERVER_PORT"

/**
* A variable controlling the DSU client port.
*
* The default value is "0" (auto-select)
*/
#define SDL_HINT_DSU_CLIENT_PORT "SDL_DSU_CLIENT_PORT"

/**
* A variable controlling whether IOKit should be used for controller
* handling.
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 @@ -51,6 +51,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 /* Before WINDOWS_ driver, as WINDOWS wants to check if this driver is handling things */
&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
Loading
Loading