From be4d8330bd32a490ad58b9e90c85a67a280fb28a Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sat, 29 Mar 2025 12:29:14 +0100 Subject: [PATCH] port: add settings for HIDAPI and raw input --- port/src/input.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/port/src/input.c b/port/src/input.c index 7475c2b2b..ce6f4b5b9 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -74,6 +74,9 @@ static s32 connectedMask = 0; static s32 numJoysticks = 0; +static s32 useHIDAPI = 1; +static s32 useRawInput = 1; + static s32 mouseEnabled = 1; static s32 mouseX, mouseY; static s32 mouseDX, mouseDY; @@ -674,24 +677,29 @@ static inline void inputLoadBinds(void) s32 inputInit(void) { + // Set SDL hints before initializing the controller subsystem. + if (useHIDAPI) { + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS3, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1"); + // the two hints below enable Rumble and Motion Sensor for PS4/5 pads connected via bluetooth + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); + } + if (useRawInput) { + SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT, "1"); + } + if (!SDL_WasInit(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC)) { SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC); } - // Set SDL hints before loading controller mappings - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS3, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); // Enables Rumble and Motion Sensor functionality when under Bluetooth connectivity. - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); // same case as PS4_Rumble hint. - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT, "1"); - SDL_SetHint(SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT, "1"); - // try to load controller db from an external file in the save folder if (fsFileSize("$S/" CONTROLLERDB_FNAME)) { const char *dbpath = fsFullPath("$S/" CONTROLLERDB_FNAME); @@ -1496,6 +1504,8 @@ PD_CONSTRUCTOR static void inputConfigInit(void) configRegisterFloat("Input.MouseSpeedY", &mouseSensY, -10.f, 10.f); configRegisterInt("Input.FakeGamepads", &fakeControllers, 0, 4); configRegisterInt("Input.FirstGamepadNum", &firstController, 0, 3); + configRegisterInt("Input.UseHIDAPI", &useHIDAPI, 0, 1); + configRegisterInt("Input.UseRawInput", &useRawInput, 0, 1); char secname[] = "Input.Player1.Binds"; char keyname[256] = { 0 };