From 9c73cf536ab1cb6bba41d2e52178b1d14d69175f Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 20 Feb 2016 21:44:51 -0800 Subject: [PATCH] SDL: Fix joystick initialization on BSD --- CHANGES | 1 + src/platform/sdl/sdl-events.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGES b/CHANGES index ebdfdf9a0..dcb2c45dd 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Bugfixes: - GBA BIOS: Fix RegisterRamReset setting DISPCNT to the wrong value - OpenGL: Correct boolean vector strcmp strings for uniforms - Wii: Fix tilting direction + - SDL: Fix joystick initialization on BS Misc: - GBA: Slightly optimize GBAProcessEvents - Qt: Add preset for DualShock 4 diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 323877e60..22852ca09 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -57,6 +57,19 @@ bool GBASDLInitEvents(struct GBASDLEvents* context) { SDL_JoystickListInit(&context->joysticks, nJoysticks); if (nJoysticks > 0) { GBASDLUpdateJoysticks(context); + // Some OSes don't do hotplug detection + if (!SDL_JoystickListSize(&context->joysticks)) { + int i; + for (i = 0; i < nJoysticks; ++i) { + struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&context->joysticks); + joystick->joystick = SDL_JoystickOpen(i); + joystick->id = SDL_JoystickInstanceID(joystick->joystick); + joystick->index = SDL_JoystickListSize(&context->joysticks) - 1; +#if SDL_VERSION_ATLEAST(2, 0, 0) + joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick); +#endif + } + } } context->playersAttached = 0;