Skip to content

Commit 9accdec

Browse files
committed
SDL3 Add DSU joystick driver
Introduces DSU client joystick support for SDL, enabling connection to DSU servers (such as DS4Windows and BetterJoy) to receive controller data over UDP, including motion sensors and touchpad data. Adds build system options, configuration hints, protocol implementation, and driver integration for Windows and other platforms.
1 parent 3383436 commit 9accdec

File tree

10 files changed

+1831
-0
lines changed

10 files changed

+1831
-0
lines changed

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ dep_option(SDL_HIDAPI_LIBUSB "Use libusb for low level joystick drivers" O
380380
dep_option(SDL_HIDAPI_LIBUSB_SHARED "Dynamically load libusb support" ON "SDL_HIDAPI_LIBUSB;SDL_DEPS_SHARED" OFF)
381381
dep_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" ON SDL_HIDAPI OFF)
382382
dep_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON SDL_HIDAPI OFF)
383+
option(SDL_DSU_JOYSTICK "Enable DSU client joystick support" ON)
383384
set_option(SDL_LIBUDEV "Enable libudev support" ON)
384385
set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
385386
set_option(SDL_CCACHE "Use Ccache to speed up build" OFF)
@@ -1374,6 +1375,24 @@ if(SDL_JOYSTICK)
13741375
"${SDL3_SOURCE_DIR}/src/joystick/virtual/*.h"
13751376
)
13761377
endif()
1378+
1379+
# DSU (DualShock UDP) client support
1380+
if(SDL_DSU_JOYSTICK)
1381+
set(SDL_JOYSTICK_DSU 1)
1382+
sdl_glob_sources(
1383+
"${SDL3_SOURCE_DIR}/src/joystick/dsu/*.c"
1384+
"${SDL3_SOURCE_DIR}/src/joystick/dsu/*.h"
1385+
)
1386+
1387+
# DSU requires network libraries
1388+
if(WIN32)
1389+
list(APPEND SDL3_EXTRA_LIBS ws2_32)
1390+
elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
1391+
# Unix systems typically have sockets built-in
1392+
elseif(HAIKU)
1393+
list(APPEND SDL3_EXTRA_LIBS network)
1394+
endif()
1395+
endif()
13771396
endif()
13781397

13791398
if(SDL_VIDEO)

include/SDL3/SDL_hints.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,56 @@ extern "C" {
23192319
*/
23202320
#define SDL_HINT_JOYSTICK_WGI "SDL_JOYSTICK_WGI"
23212321

2322+
/**
2323+
* A variable controlling whether the DSU (DualShock UDP) joystick driver should be used.
2324+
*
2325+
* This variable can be set to the following values:
2326+
*
2327+
* - "0": DSU driver is disabled
2328+
* - "1": DSU driver is enabled (default)
2329+
*
2330+
* The DSU driver allows SDL to connect to DSU servers (DS4Windows, BetterJoy, etc.)
2331+
* to receive controller data over UDP, including motion sensors and touchpad data.
2332+
*
2333+
* This hint should be set before SDL is initialized.
2334+
*
2335+
* \since This hint is available since SDL 3.2.0.
2336+
*/
2337+
#define SDL_HINT_JOYSTICK_DSU "SDL_JOYSTICK_DSU"
2338+
2339+
/**
2340+
* A variable controlling the DSU server address.
2341+
*
2342+
* The default value is "127.0.0.1"
2343+
*
2344+
* This hint should be set before SDL is initialized.
2345+
*
2346+
* \since This hint is available since SDL 3.2.0.
2347+
*/
2348+
#define SDL_HINT_DSU_SERVER "SDL_DSU_SERVER"
2349+
2350+
/**
2351+
* A variable controlling the DSU server port.
2352+
*
2353+
* The default value is "26760"
2354+
*
2355+
* This hint should be set before SDL is initialized.
2356+
*
2357+
* \since This hint is available since SDL 3.2.0.
2358+
*/
2359+
#define SDL_HINT_DSU_SERVER_PORT "SDL_DSU_SERVER_PORT"
2360+
2361+
/**
2362+
* A variable controlling the DSU client port.
2363+
*
2364+
* The default value is "0" (auto-select)
2365+
*
2366+
* This hint should be set before SDL is initialized.
2367+
*
2368+
* \since This hint is available since SDL 3.2.0.
2369+
*/
2370+
#define SDL_HINT_DSU_CLIENT_PORT "SDL_DSU_CLIENT_PORT"
2371+
23222372
/**
23232373
* A variable containing a list of wheel style controllers.
23242374
*

include/build_config/SDL_build_config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
#cmakedefine SDL_JOYSTICK_RAWINPUT 1
314314
#cmakedefine SDL_JOYSTICK_USBHID 1
315315
#cmakedefine SDL_JOYSTICK_VIRTUAL 1
316+
#cmakedefine SDL_JOYSTICK_DSU 1
316317
#cmakedefine SDL_JOYSTICK_VITA 1
317318
#cmakedefine SDL_JOYSTICK_WGI 1
318319
#cmakedefine SDL_JOYSTICK_XINPUT 1

include/build_config/SDL_build_config_windows.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ typedef unsigned int uintptr_t;
231231
#define SDL_JOYSTICK_HIDAPI 1
232232
#define SDL_JOYSTICK_RAWINPUT 1
233233
#define SDL_JOYSTICK_VIRTUAL 1
234+
#define SDL_JOYSTICK_DSU 1
234235
#ifdef HAVE_WINDOWS_GAMING_INPUT_H
235236
#define SDL_JOYSTICK_WGI 1
236237
#endif

src/joystick/SDL_joystick.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#include "./virtual/SDL_virtualjoystick_c.h"
4949
#endif
5050

51+
#ifdef SDL_JOYSTICK_DSU
52+
#include "./dsu/SDL_dsujoystick_c.h"
53+
#endif
54+
5155
static SDL_JoystickDriver *SDL_joystick_drivers[] = {
5256
#ifdef SDL_JOYSTICK_HIDAPI // Highest priority driver for supported devices
5357
&SDL_HIDAPI_JoystickDriver,
@@ -100,6 +104,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
100104
#ifdef SDL_JOYSTICK_VIRTUAL
101105
&SDL_VIRTUAL_JoystickDriver,
102106
#endif
107+
#ifdef SDL_JOYSTICK_DSU
108+
&SDL_DSU_JoystickDriver,
109+
#endif
103110
#ifdef SDL_JOYSTICK_VITA
104111
&SDL_VITA_JoystickDriver,
105112
#endif

src/joystick/SDL_sysjoystick.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ extern SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver;
255255
extern SDL_JoystickDriver SDL_IOS_JoystickDriver;
256256
extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
257257
extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
258+
extern SDL_JoystickDriver SDL_DSU_JoystickDriver;
258259
extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
259260
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
260261
extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;

0 commit comments

Comments
 (0)