Merge pull request #5863 from bparker06/xinput

xinput: copy VID/PID from dinput so autoconfig does not rely solely on HID name
This commit is contained in:
Twinaphex 2017-12-05 20:01:16 +01:00 committed by GitHub
commit 7ab7ed35b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 7 deletions

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef __DINPUT_JOYPAD_H
#define __DINPUT_JOYPAD_H
#include <retro_common_api.h>
RETRO_BEGIN_DECLS
bool dinput_joypad_get_vidpid_from_xinput_index(int index, int *vid, int *pid, int *dinput_index);
RETRO_END_DECLS
#endif

View File

@ -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));
}
}