Pass joypad_driver name to input_driver_init function and make

sure we don't need to access the settings struct from the
input driver
This commit is contained in:
twinaphex 2017-01-10 17:59:48 +01:00
parent db6fba51c3
commit 8bd12368ef
22 changed files with 82 additions and 92 deletions

View File

@ -594,7 +594,7 @@ static void *xv_init(const video_info_t *video,
if (input && input_data)
{
xinput = input_x.init();
xinput = input_x.init(settings->input.joypad_driver);
if (xinput)
{
*input = &input_x;

View File

@ -798,7 +798,8 @@ error:
static void gfx_ctx_x_input_driver(void *data,
const input_driver_t **input, void **input_data)
{
void *xinput = input_x.init();
settings_t *settings = config_get_ptr();
void *xinput = input_x.init(settings->input.joypad_driver);
(void)data;

View File

@ -441,7 +441,8 @@ error:
static void gfx_ctx_xegl_input_driver(void *data,
const input_driver_t **input, void **input_data)
{
void *xinput = input_x.init();
settings_t *settings = config_get_ptr();
void *xinput = input_x.init(settings->input.joypad_driver);
(void)data;

View File

@ -33,8 +33,10 @@
#include "../../menu/menu_display.h"
#endif
#include "../../frontend/drivers/platform_linux.h"
#include "../input_config.h"
#include "../input_driver.h"
#include "../../frontend/drivers/platform_linux.h"
#include "../../gfx/video_driver.h"
#include "../input_joypad_driver.h"
#include "../drivers_keyboard/keyboard_event_android.h"
@ -456,10 +458,9 @@ static bool android_input_init_handle(void)
return true;
}
static void *android_input_init(void)
static void *android_input_init(const char *joypad_driver)
{
int32_t sdk;
settings_t *settings = config_get_ptr();
struct android_app *android_app = (struct android_app*)g_android;
android_input_t *android = (android_input_t*)
calloc(1, sizeof(*android));
@ -469,8 +470,7 @@ static void *android_input_init(void)
android->thread.pads_connected = 0;
android->copy.pads_connected = 0;
android->joypad = input_joypad_init_driver(
settings->input.joypad_driver, android);
android->joypad = input_joypad_init_driver(joypad_driver, android);
input_keymaps_init_keyboard_lut(rarch_key_map_android);
@ -644,7 +644,6 @@ static void handle_hotplug(android_input_data_t *android_data,
char name_buf[256];
int vendorId = 0;
int productId = 0;
settings_t *settings = config_get_ptr();
device_name[0] = device_model[0] = name_buf[0] = '\0';
@ -899,6 +898,7 @@ static void handle_hotplug(android_input_data_t *android_data,
if (!string_is_empty(name_buf))
{
settings_t *settings = config_get_ptr();
strlcpy(settings->input.device_names[*port],
name_buf, sizeof(settings->input.device_names[*port]));
}

View File

@ -22,11 +22,12 @@
#endif
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../input_keymaps.h"
#include "cocoa_input.h"
#include "../../gfx/video_driver.h"
#include "../../configuration.h"
#include "../../driver.h"
#include "../drivers_keyboard/keyboard_event_apple.h"
@ -126,16 +127,15 @@ int32_t cocoa_input_find_any_axis(uint32_t port)
}
static void *cocoa_input_init(void)
static void *cocoa_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
cocoa_input_data_t *apple = (cocoa_input_data_t*)calloc(1, sizeof(*apple));
if (!apple)
return NULL;
input_keymaps_init_keyboard_lut(rarch_key_map_apple_hid);
apple->joypad = input_joypad_init_driver(settings->input.joypad_driver, apple);
apple->joypad = input_joypad_init_driver(joypad_driver, apple);
#ifdef HAVE_MFI
apple->sec_joypad = input_joypad_init_driver("mfi", apple);

View File

@ -23,8 +23,8 @@
#include "../../config.h"
#endif
#include "../../configuration.h"
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#define MAX_PADS 1
@ -80,14 +80,13 @@ static void ctr_input_free_input(void *data)
free(data);
}
static void* ctr_input_initialize(void)
static void* ctr_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
ctr_input_t *ctr = (ctr_input_t*)calloc(1, sizeof(*ctr));
if (!ctr)
return NULL;
ctr->joypad = input_joypad_init_driver(settings->input.joypad_driver, ctr);
ctr->joypad = input_joypad_init_driver(joypad_driver, ctr);
return ctr;
}
@ -149,7 +148,7 @@ static void ctr_input_keyboard_mapping_set_block(void *data, bool value)
}
input_driver_t input_ctr = {
ctr_input_initialize,
ctr_input_init,
ctr_input_poll,
ctr_input_state,
ctr_input_meta_key_pressed,

View File

@ -47,6 +47,7 @@
#include "../../tasks/tasks_internal.h"
#include "../../gfx/video_driver.h"
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../input_keymaps.h"
@ -125,10 +126,9 @@ error:
return false;
}
static void *dinput_init(void)
static void *dinput_init(const char *joypad_driver)
{
struct dinput_input *di = NULL;
settings_t *settings = config_get_ptr();
if (!dinput_init_context())
{
@ -185,7 +185,7 @@ static void *dinput_init(void)
}
input_keymaps_init_keyboard_lut(rarch_key_map_dinput);
di->joypad = input_joypad_init_driver(settings->input.joypad_driver, di);
di->joypad = input_joypad_init_driver(joypad_driver, di);
return di;
}

View File

@ -25,7 +25,7 @@
#include <libretro.h>
#include "../../configuration.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#ifndef MAX_PADS
@ -77,14 +77,13 @@ static void gx_input_free_input(void *data)
free(gx);
}
static void *gx_input_init(void)
static void *gx_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
gx_input_t *gx = (gx_input_t*)calloc(1, sizeof(*gx));
if (!gx)
return NULL;
gx->joypad = input_joypad_init_driver(settings->input.joypad_driver, gx);
gx->joypad = input_joypad_init_driver(joypad_driver, gx);
return gx;
}

View File

@ -24,11 +24,12 @@
#include <boolean.h>
#include "../../configuration.h"
#include "../../verbosity.h"
#include "../common/linux_common.h"
#include "../input_keymaps.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
typedef struct linuxraw_input
@ -38,10 +39,9 @@ typedef struct linuxraw_input
bool state[0x80];
} linuxraw_input_t;
static void *linuxraw_input_init(void)
static void *linuxraw_input_init(const char *joypad_driver)
{
linuxraw_input_t *linuxraw = NULL;
settings_t *settings = config_get_ptr();
/* Only work on terminals. */
if (!isatty(0))
@ -64,8 +64,7 @@ static void *linuxraw_input_init(void)
return NULL;
}
linuxraw->joypad = input_joypad_init_driver(
settings->input.joypad_driver, linuxraw);
linuxraw->joypad = input_joypad_init_driver(joypad_driver, linuxraw);
input_keymaps_init_keyboard_lut(rarch_key_map_linux);
linux_terminal_claim_stdin();

View File

@ -17,7 +17,7 @@
#include "../input_driver.h"
#include "../../verbosity.h"
static void *nullinput_input_init(void)
static void *nullinput_input_init(const char *joypad_driver)
{
RARCH_ERR("Using the null input driver. RetroArch will ignore you.");
return (void*)-1;

View File

@ -28,7 +28,7 @@
#include "../../defines/ps3_defines.h"
#include "../../configuration.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#ifdef HAVE_MOUSE
@ -163,14 +163,13 @@ static void ps3_input_free_input(void *data)
}
static void* ps3_input_init(void)
static void* ps3_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
ps3_input_t *ps3 = (ps3_input_t*)calloc(1, sizeof(*ps3));
if (!ps3)
return NULL;
ps3->joypad = input_joypad_init_driver(settings->input.joypad_driver, ps3);
ps3->joypad = input_joypad_init_driver(joypad_driver, ps3);
if (ps3->joypad)
ps3->joypad->init(ps3);

View File

@ -40,9 +40,9 @@
#include "../../defines/psp_defines.h"
#include "../../configuration.h"
#include "../input_joypad_driver.h"
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
typedef struct psp_input
{
@ -97,15 +97,13 @@ static void psp_input_free_input(void *data)
free(data);
}
static void* psp_input_initialize(void)
static void* psp_input_initialize(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
psp_input_t *psp = (psp_input_t*)calloc(1, sizeof(*psp));
if (!psp)
return NULL;
psp->joypad = input_joypad_init_driver(
settings->input.joypad_driver, psp);
psp->joypad = input_joypad_init_driver(joypad_driver, psp);
return psp;
}

View File

@ -27,9 +27,10 @@
#include "../../config.h"
#endif
#include "../../gfx/video_driver.h"
#include "../../configuration.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../../gfx/video_driver.h"
#include "../../tasks/tasks_internal.h"
#include "../../command.h"
@ -648,10 +649,9 @@ static void qnx_handle_navigator_event(
return;
}
static void *qnx_input_init(void)
static void *qnx_input_init(const char *joypad_driver)
{
int i;
settings_t *settings = config_get_ptr();
qnx_input_t *qnx = (qnx_input_t*)calloc(1, sizeof(*qnx));
if (!qnx)
@ -665,8 +665,7 @@ static void *qnx_input_init(void)
qnx->touch_map[i] = -1;
}
qnx->joypad = input_joypad_init_driver(
settings->input.joypad_driver, qnx);
qnx->joypad = input_joypad_init_driver(joypad_driver, qnx);
for (i = 0; i < MAX_PADS; ++i)
{

View File

@ -19,10 +19,11 @@
#include <boolean.h>
#include "../input_joypad_driver.h"
#include "../input_keyboard.h"
#include "../input_config.h"
#include "../input_keyboard.h"
#include "../input_keymaps.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../../tasks/tasks_internal.h"
#include "../../configuration.h"
@ -47,7 +48,7 @@ typedef struct rwebinput_input
int context;
} rwebinput_input_t;
static void *rwebinput_input_init(void)
static void *rwebinput_input_init(const char *joypad_driver)
{
rwebinput_input_t *rwebinput = (rwebinput_input_t*)calloc(1, sizeof(*rwebinput));
if (!rwebinput)

View File

@ -21,18 +21,18 @@
#include <string/stdstring.h>
#include <libretro.h>
#include "../../configuration.h"
#include "SDL.h"
#include "../../gfx/video_context_driver.h"
#include "../../configuration.h"
#include "../../verbosity.h"
#include "../../tasks/tasks_internal.h"
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../input_keymaps.h"
#include "../input_keyboard.h"
#include "../../gfx/video_context_driver.h"
#include "../../verbosity.h"
#include "../../tasks/tasks_internal.h"
typedef struct sdl_input
{
bool blocked;
@ -43,16 +43,15 @@ typedef struct sdl_input
int mouse_l, mouse_r, mouse_m, mouse_wu, mouse_wd, mouse_wl, mouse_wr;
} sdl_input_t;
static void *sdl_input_init(void)
static void *sdl_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
if (!sdl)
return NULL;
input_keymaps_init_keyboard_lut(rarch_key_map_sdl);
sdl->joypad = input_joypad_init_driver(settings->input.joypad_driver, sdl);
sdl->joypad = input_joypad_init_driver(joypad_driver, sdl);
RARCH_LOG("[SDL]: Input driver initialized.\n");
return sdl;
@ -134,17 +133,13 @@ static int16_t sdl_joypad_device_state(sdl_input_t *sdl,
return 0;
}
static int16_t sdl_analog_device_state(sdl_input_t *sdl, const struct retro_keybind **binds,
static int16_t sdl_analog_device_state(sdl_input_t *sdl,
rarch_joypad_info_t joypad_info,
const struct retro_keybind **binds,
unsigned port_num, unsigned idx, unsigned id)
{
rarch_joypad_info_t joypad_info;
settings_t *settings = config_get_ptr();
int16_t ret = binds[port_num] ? sdl_analog_pressed(sdl, binds[port_num], idx, id) : 0;
joypad_info.joy_idx = port_num;
joypad_info.auto_binds = settings->input.autoconf_binds[port_num];
joypad_info.axis_threshold = settings->input.axis_threshold;
if (!ret && binds[port_num])
ret = input_joypad_analog(sdl->joypad, joypad_info, port_num, idx, id, binds[port_num]);
return ret;
@ -249,7 +244,7 @@ static int16_t sdl_input_state(void *data_,
case RETRO_DEVICE_JOYPAD:
return sdl_joypad_device_state(data, joypad_info, binds, port, id, &type);
case RETRO_DEVICE_ANALOG:
return sdl_analog_device_state(data, binds, port, idx, id);
return sdl_analog_device_state(data, joypad_info, binds, port, idx, id);
case RETRO_DEVICE_MOUSE:
return sdl_mouse_device_state(data, id);
case RETRO_DEVICE_POINTER:

View File

@ -39,17 +39,17 @@
#include <compat/strl.h>
#include <string/stdstring.h>
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../input_keymaps.h"
#include "../drivers_keyboard/keyboard_event_udev.h"
#include "../../gfx/video_driver.h"
#include "../common/linux_common.h"
#include "../common/udev_common.h"
#include "../common/epoll_common.h"
#include "../input_config.h"
#include "../input_joypad_driver.h"
#include "../input_keymaps.h"
#include "../../configuration.h"
#include "../../verbosity.h"
typedef struct udev_input udev_input_t;
@ -606,9 +606,8 @@ static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb
return true;
}
static void *udev_input_init(void)
static void *udev_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
udev_input_t *udev = (udev_input_t*)calloc(1, sizeof(*udev));
if (!udev)
@ -662,7 +661,7 @@ static void *udev_input_init(void)
if (!udev->num_devices)
RARCH_WARN("[udev]: Couldn't open any keyboard, mouse or touchpad. Are permissions set correctly for /dev/input/event*?\n");
udev->joypad = input_joypad_init_driver(settings->input.joypad_driver, udev);
udev->joypad = input_joypad_init_driver(joypad_driver, udev);
input_keymaps_init_keyboard_lut(rarch_key_map_linux);
linux_terminal_disable_input();

View File

@ -23,8 +23,8 @@
#include "../../config.h"
#endif
#include "../../configuration.h"
#include "../input_config.h"
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "wiiu_dbg.h"
@ -82,15 +82,14 @@ static void wiiu_input_free_input(void *data)
free(data);
}
static void* wiiu_input_initialize(void)
static void* wiiu_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
wiiu_input_t *wiiu = (wiiu_input_t*)calloc(1, sizeof(*wiiu));
if (!wiiu)
return NULL;
DEBUG_STR(settings->input.joypad_driver);
wiiu->joypad = input_joypad_init_driver(settings->input.joypad_driver, wiiu);
DEBUG_STR(joypad_driver);
wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu);
return wiiu;
}
@ -152,7 +151,7 @@ static void wiiu_input_keyboard_mapping_set_block(void *data, bool value)
}
input_driver_t input_wiiu = {
wiiu_input_initialize,
wiiu_input_init,
wiiu_input_poll,
wiiu_input_state,
wiiu_input_meta_key_pressed,

View File

@ -29,7 +29,6 @@
#include "../../gfx/video_driver.h"
#include "../common/input_x11_common.h"
#include "../../configuration.h"
#include "../../verbosity.h"
typedef struct x11_input
@ -49,10 +48,9 @@ typedef struct x11_input
} x11_input_t;
static void *x_input_init(void)
static void *x_input_init(const char *joypad_driver)
{
x11_input_t *x11;
settings_t *settings = config_get_ptr();
if (video_driver_display_type_get() != RARCH_DISPLAY_X11)
{
@ -68,7 +66,7 @@ static void *x_input_init(void)
x11->display = (Display*)video_driver_display_get();
x11->win = (Window)video_driver_window_get();
x11->joypad = input_joypad_init_driver(settings->input.joypad_driver, x11);
x11->joypad = input_joypad_init_driver(joypad_driver, x11);
input_keymaps_init_keyboard_lut(rarch_key_map_x11);
return x11;

View File

@ -28,8 +28,8 @@
#include <boolean.h>
#include <libretro.h>
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#include "../../configuration.h"
#define MAX_PADS 4
@ -84,14 +84,13 @@ static void xdk_input_free_input(void *data)
free(xdk);
}
static void *xdk_input_init(void)
static void *xdk_input_init(const char *joypad_driver)
{
settings_t *settings = config_get_ptr();
xdk_input_t *xdk = (xdk_input_t*)calloc(1, sizeof(*xdk));
if (!xdk)
return NULL;
xdk->joypad = input_joypad_init_driver(settings->input.joypad_driver, xdk);
xdk->joypad = input_joypad_init_driver(joypad_driver, xdk);
return xdk;
}

View File

@ -23,6 +23,7 @@
#include <libretro.h>
#include "../input_driver.h"
#include "../input_joypad_driver.h"
#define MAX_PADS 4
@ -85,7 +86,7 @@ static void xenon360_input_free_input(void *data)
(void)data;
}
static void* xenon360_input_init(void)
static void* xenon360_input_init(const char *joypad_driver)
{
return (void*)-1;
}

View File

@ -892,7 +892,10 @@ void input_driver_poll(void)
bool input_driver_init(void)
{
if (current_input)
current_input_data = current_input->init();
{
settings_t *settings = config_get_ptr();
current_input_data = current_input->init(settings->input.joypad_driver);
}
if (!current_input_data)
return false;

View File

@ -71,7 +71,7 @@ struct retro_keybind
typedef struct input_driver
{
void *(*init)(void);
void *(*init)(const char *joypad_driver);
void (*poll)(void *data);
int16_t (*input_state)(void *data,
rarch_joypad_info_t joypad_info,