From 35ab48ee615421c666cb75f8fc9935504d530049 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Tue, 5 Dec 2017 12:47:16 -0500 Subject: [PATCH] xinput: copy VID/PID from dinput so autoconfig does not rely solely on HID name --- input/drivers_joypad/dinput_joypad.c | 23 ++++++++++++++++++++++ input/drivers_joypad/dinput_joypad.h | 29 ++++++++++++++++++++++++++++ input/drivers_joypad/xinput_joypad.c | 28 ++++++++++++++++++++------- 3 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 input/drivers_joypad/dinput_joypad.h diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 4793d83256..403a13a56a 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -63,6 +63,29 @@ extern bool g_xinput_block_pads; extern int g_xinput_pad_indexes[MAX_USERS]; extern LPDIRECTINPUT8 g_dinput_ctx; +bool dinput_joypad_get_vidpid_from_xinput_index(int index, int *vid, int *pid) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(g_xinput_pad_indexes); i++) + { + if (index == g_xinput_pad_indexes[i]) + { + RARCH_LOG("[DINPUT]: Found XInput pad at index %d (DINPUT index %d)\n", index, i); + + if (vid) + *vid = g_pads[i].vid; + + if (pid) + *pid = g_pads[i].pid; + + return true; + } + } + + return false; +} + static void dinput_joypad_destroy(void) { unsigned i; diff --git a/input/drivers_joypad/dinput_joypad.h b/input/drivers_joypad/dinput_joypad.h new file mode 100644 index 0000000000..e7705bfa30 --- /dev/null +++ b/input/drivers_joypad/dinput_joypad.h @@ -0,0 +1,29 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2016 - Daniel De Matteis + * Copyright (C) 2016-2017 - Brad Parker + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef __DINPUT_JOYPAD_H +#define __DINPUT_JOYPAD_H + +#include + +RETRO_BEGIN_DECLS + +bool dinput_joypad_get_vidpid_from_xinput_index(int index, int *vid, int *pid, int *dinput_index); + +RETRO_END_DECLS + +#endif diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index d753a889dc..17d3a42973 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -40,6 +40,12 @@ #include "../../verbosity.h" +#ifndef HAVE_DINPUT +#error Cannot compile xinput without dinput. +#endif + +#include "dinput_joypad.h" + /* Check if the definitions do not already exist. * Official and mingw xinput headers have different include guards. */ @@ -92,10 +98,6 @@ typedef struct #define ERROR_DEVICE_NOT_CONNECTED 1167 #endif -#ifndef HAVE_DINPUT -#error Cannot compile xinput without dinput. -#endif - /* Due to 360 pads showing up under both XInput and DirectInput, * and since we are going to have to pass through unhandled * joypad numbers to DirectInput, a slightly ugly @@ -270,16 +272,28 @@ static bool xinput_joypad_init(void *data) for (j = 0; j < MAX_USERS; j++) { - RARCH_LOG("[XInput]: Attempting autoconf for, user #%u\n", j); + if (xinput_joypad_name(j)) + RARCH_LOG("[XInput]: Attempting autoconf for \"%s\", user #%u\n", xinput_joypad_name(j), j); + else + RARCH_LOG("[XInput]: Attempting autoconf for user #%u\n", j); + if (pad_index_to_xuser_index(j) > -1) { + int vid = 0; + int pid = 0; + int dinput_index = 0; + bool success = dinput_joypad_get_vidpid_from_xinput_index(j, &vid, &pid, &dinput_index); + + if (success) + RARCH_LOG("[XInput]: Found VID/PID (%04X/%04X) from DINPUT index %d for \"%s\", user #%u\n", vid, pid, dinput_index, xinput_joypad_name(j), j); + if (!input_autoconfigure_connect( xinput_joypad_name(j), NULL, xinput_joypad.ident, j, - 0, - 0)) + vid, + pid)) input_config_set_device_name(j, xinput_joypad_name(j)); } }