On Sun, 20 Sep 2026 19:46:43 -0700 Thomas Frohwein <[email protected]> wrote:
> Hi, > > Compared to SDL2, SDL3's game controller support has made some steps > back on OpenBSD. I can't pinpoint the root cause for this yet, but the > entries in the game controller DB file (SDL_gamepad_db.h) have changed > and this is clearly part of the issue of worse detection of the > controllers currently. > > As a workaround that restores the functionality of pretty much all the > gamecontrollers that work on SDL2, I am planning to put SDL2's file in > place of SDL3's. This is done with very few changes to the file > itself. This is not intended to be a long-term solution, but will > hopefully also allow me to show the issue clearly to upstream. > > In addition, the Y axis inversion bug known from SDL2 still persists > here, so I'm including the patch for this that is already in SDL2 (see > [2]). > > I'm planning to commit this if there's no protest. > > Diff attached this time due to length of the DB file. Better diff below which avoids putting the large SDL_gamepad_db.h file into the ports tree, instead using BUILD_DEPENDS=devel/sdl2:patch. Same functional result. Instigated by bentley@ > > [1] https://marc.info/?l=openbsd-ports-cvs&m=177144101826115&w=2 > [2] > https://github.com/libsdl-org/SDL/issues/7609#issuecomment-1614143591 Index: Makefile =================================================================== RCS file: /cvs/ports/devel/sdl3/Makefile,v diff -u -p -r1.10 Makefile --- Makefile 16 Sep 2026 18:31:11 -0000 1.10 +++ Makefile 21 Sep 2026 15:23:38 -0000 @@ -3,7 +3,7 @@ COMMENT = cross-platform multimedia lib V = 3.4.16 DISTNAME = SDL3-${V} PKGNAME = ${DISTNAME:L} -REVISION = 0 +REVISION = 1 SHARED_LIBS += SDL3 0.1 # 3.4.0 @@ -24,7 +24,8 @@ SITES = https://libsdl.org/release/ \ MODULES = devel/cmake MODCMAKE_LDFLAGS = -L${LOCALBASE}/lib -L${X11BASE}/lib -liconv -BUILD_DEPENDS = wayland/libinput-openbsd +BUILD_DEPENDS = devel/sdl2:patch \ + wayland/libinput-openbsd LIB_DEPENDS = converters/libiconv \ devel/fribidi \ wayland/wayland \ @@ -52,5 +53,11 @@ CONFIGURE_ARGS = -DSDL_ALSA=OFF \ CONFIGURE_ARGS += -DSDL_TESTS=OFF CFLAGS += -I${LOCALBASE}/include -I${X11BASE}/include + +post-extract: + ln -sf ${WRKDIR}/devel/sdl2/*/src/joystick/SDL_gamecontrollerdb.h \ + ${WRKSRC}/src/joystick/SDL_gamepad_db.h + sed -i 's/s_ControllerMappings/s_GamepadMappings/g' \ + ${WRKSRC}/src/joystick/SDL_gamepad_db.h .include <bsd.port.mk> Index: patches/patch-src_joystick_bsd_SDL_bsdjoystick_c =================================================================== RCS file: patches/patch-src_joystick_bsd_SDL_bsdjoystick_c diff -N patches/patch-src_joystick_bsd_SDL_bsdjoystick_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-src_joystick_bsd_SDL_bsdjoystick_c 21 Sep 2026 15:23:38 -0000 @@ -0,0 +1,26 @@ +restore Y/RY axis inversion for XInput controllers for now, pending +a more permanent upstream solution to this +https://github.com/libsdl-org/SDL/issues/7609#issuecomment-1522831640 + +Index: src/joystick/bsd/SDL_bsdjoystick.c +--- src/joystick/bsd/SDL_bsdjoystick.c.orig ++++ src/joystick/bsd/SDL_bsdjoystick.c +@@ -683,6 +683,18 @@ static void BSD_JoystickUpdate(SDL_Joystick *joy) + // scaleaxe + v = (Sint32)hid_get_data(REP_BUF_DATA(rep), &hitem); + v = (((SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN) * (v - hitem.logical_minimum)) / (hitem.logical_maximum - hitem.logical_minimum)) + SDL_JOYSTICK_AXIS_MIN; ++#ifdef __OpenBSD__ ++ /* XInput controllermapping relies on inverted Y axes. ++ * These devices have a 16bit signed space, as opposed ++ * to older DInput devices (8bit unsigned), so ++ * hitem.logical_maximum can be used to differentiate them. ++ */ ++ if ((joyaxe == JOYAXE_Y || joyaxe == JOYAXE_RY) ++ && hitem.logical_maximum > 255) { ++ if (v != 0) ++ v = ~v; ++ } ++#endif + SDL_SendJoystickAxis(timestamp, joy, naxe, v); + } else if (usage == HUG_HAT_SWITCH) { + v = (Sint32)hid_get_data(REP_BUF_DATA(rep), &hitem);
