From d48141041d8b6b298d0fff9d275e1cdd230baf8f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Jan 2017 17:40:21 +0100 Subject: [PATCH] Pass joypad_info to input_state function callback - less settings pointer grabbing --- gfx/drivers_context/wayland_ctx.c | 10 +--- input/drivers/android_input.c | 6 +- input/drivers/cocoa_input.c | 7 +-- input/drivers/ctr_input.c | 9 +-- input/drivers/dinput.c | 8 +-- input/drivers/gx_input.c | 10 +--- input/drivers/linuxraw_input.c | 7 +-- input/drivers/nullinput.c | 1 + input/drivers/ps3_input.c | 7 +-- input/drivers/psp_input.c | 9 +-- input/drivers/qnx_input.c | 17 ++---- input/drivers/rwebinput_input.c | 4 +- input/drivers/sdl_input.c | 16 +++--- input/drivers/udev_input.c | 10 +--- input/drivers/wiiu_input.c | 9 +-- input/drivers/x11_input.c | 9 +-- input/drivers/xdk_xinput_input.c | 10 +--- input/drivers/xenon360_input.c | 12 ++-- input/input_driver.c | 83 ++++++++++++++++++++++----- input/input_driver.h | 1 + input/input_overlay.c | 14 ++++- menu/menu_event.c | 29 +++++++--- menu/menu_input.c | 13 +++-- menu/widgets/menu_input_bind_dialog.c | 9 ++- 24 files changed, 171 insertions(+), 139 deletions(-) diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 648fe0a407..f94984b0fa 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -1311,21 +1311,17 @@ static int16_t input_wl_pointer_state(gfx_ctx_wayland_data_t *wl, } -static int16_t input_wl_state(void *data, const struct retro_keybind **binds, +static int16_t input_wl_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { int16_t ret; - rarch_joypad_info_t joypad_info; - settings_t *settings = config_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; if (!wl) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 444bc2c04d..e756c80afd 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -1107,18 +1107,14 @@ bool android_run_events(void *data) } static int16_t android_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; settings_t *settings = config_get_ptr(); android_input_t *android = (android_input_t*)data; android_input_data_t *android_data = (android_input_data_t*)&android->copy; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index fef44094bb..bf8db59c9d 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -271,21 +271,16 @@ static int16_t cocoa_pointer_state(cocoa_input_data_t *apple, } static int16_t cocoa_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; int16_t ret = 0; cocoa_input_data_t *apple = (cocoa_input_data_t*)data; - settings_t *settings = config_get_ptr(); if (!apple || !apple->joypad) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index 1094159754..607aa155dc 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -45,21 +45,18 @@ static void ctr_input_poll(void *data) ctr->joypad->poll(); } -static int16_t ctr_input_state(void *data, const struct retro_keybind **binds, +static int16_t ctr_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { rarch_joypad_info_t joypad_info; ctr_input_t *ctr = (ctr_input_t*)data; - settings_t *settings = config_get_ptr(); if (port > 0) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index 238afcdbbc..f28f59e277 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -466,17 +466,12 @@ static int16_t dinput_pointer_state(struct dinput_input *di, } static int16_t dinput_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; int16_t ret; struct dinput_input *di = (struct dinput_input*)data; - settings_t *settings = config_get_ptr(); - - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; switch (device) { @@ -488,6 +483,7 @@ static int16_t dinput_input_state(void *data, case RETRO_DEVICE_ANALOG: if (binds[port]) { + settings_t *settings = config_get_ptr(); ret = dinput_pressed_analog(di, binds[port], idx, id); if (!ret) ret = input_joypad_analog(di->joypad, joypad_info, diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index 4a92cf8ba7..d40ea33df6 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -40,21 +40,17 @@ typedef struct gx_input const input_device_driver_t *joypad; } gx_input_t; -static int16_t gx_input_state(void *data, const struct retro_keybind **binds, +static int16_t gx_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; gx_input_t *gx = (gx_input_t*)data; - settings_t *settings = config_get_ptr(); if (port >= MAX_PADS || !gx) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 9b6bda88d5..efacdb6157 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -113,17 +113,12 @@ static bool linuxraw_input_meta_key_pressed(void *data, int key) } static int16_t linuxraw_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; int16_t ret = 0; linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; - settings_t *settings = config_get_ptr(); - - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; switch (device) { diff --git a/input/drivers/nullinput.c b/input/drivers/nullinput.c index c6b7f30e3f..1af48341df 100644 --- a/input/drivers/nullinput.c +++ b/input/drivers/nullinput.c @@ -29,6 +29,7 @@ static void nullinput_input_poll(void *data) } static int16_t nullinput_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned idx, unsigned id) { diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 9d61afdbaf..7a0d5009be 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -100,21 +100,16 @@ static int16_t ps3_mouse_device_state(ps3_input_t *ps3, #endif static int16_t ps3_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; ps3_input_t *ps3 = (ps3_input_t*)data; - settings_t *settings = config_get_ptr(); if (!ps3) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index 0638cff67f..0abc39fe78 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -60,23 +60,20 @@ static void psp_input_poll(void *data) psp->joypad->poll(); } -static int16_t psp_input_state(void *data, const struct retro_keybind **binds, +static int16_t psp_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { rarch_joypad_info_t joypad_info; psp_input_t *psp = (psp_input_t*)data; - settings_t *settings = config_get_ptr(); #if !defined(SN_TARGET_PSP2) && !defined(VITA) if (port > 0) return 0; #endif - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index 7a63b7e1ab..4a3b024765 100644 --- a/input/drivers/qnx_input.c +++ b/input/drivers/qnx_input.c @@ -136,8 +136,7 @@ static void qnx_process_gamepad_event( int i; screen_device_t device; qnx_input_device_t* controller = NULL; - settings_t *settings = config_get_ptr(); - uint64_t *state_cur = NULL; + uint64_t *state_cur = NULL; (void)type; @@ -720,20 +719,15 @@ bool qnx_keyboard_pressed(qnx_input_t *qnx, unsigned id) } static bool qnx_is_pressed(qnx_input_t *qnx, - const struct retro_keybind *binds, - unsigned port, unsigned id) + rarch_joypad_info_t joypad_info, + const struct retro_keybind *binds, + unsigned port, unsigned id) { - rarch_joypad_info_t joypad_info; - settings_t *settings = config_get_ptr(); const struct retro_keybind *bind = &binds[id]; if (id >= RARCH_BIND_LIST_END) return false; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - if (!qnx->blocked && qnx_keyboard_pressed(qnx, bind->key)) return true; if (binds && binds[id].valid && input_joypad_pressed(qnx->joypad, joypad_info, port, binds, id)) @@ -775,6 +769,7 @@ static int16_t qnx_pointer_input_state(qnx_input_t *qnx, } static int16_t qnx_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { @@ -783,7 +778,7 @@ static int16_t qnx_input_state(void *data, switch (device) { case RETRO_DEVICE_JOYPAD: - return qnx_is_pressed(qnx, binds[port], port, id); + return qnx_is_pressed(qnx, joypad_info, binds[port], port, id); case RETRO_DEVICE_KEYBOARD: return qnx_keyboard_pressed(qnx, id); case RETRO_DEVICE_POINTER: diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index ec21a81d90..c6df2e1ca3 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -142,7 +142,9 @@ static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, return pressed_plus + pressed_minus; } -static int16_t rwebinput_input_state(void *data, const struct retro_keybind **binds, +static int16_t rwebinput_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 801e1cee77..934ce60a46 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -110,13 +110,13 @@ static bool sdl_input_meta_key_pressed(void *data, int key) return false; } -static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keybind **binds_, +static int16_t sdl_joypad_device_state(sdl_input_t *sdl, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds_, unsigned port, unsigned id, enum input_device_type *device) { if (id < RARCH_BIND_LIST_END) { - rarch_joypad_info_t joypad_info; - settings_t *settings = config_get_ptr(); const struct retro_keybind *binds = binds_[port]; if (sdl_is_pressed(sdl, port, binds, id)) @@ -125,10 +125,6 @@ static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keyb return 1; } - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - if (input_joypad_pressed(sdl->joypad, joypad_info, 0, binds, id)) { *device = INPUT_DEVICE_TYPE_JOYPAD; @@ -240,7 +236,9 @@ static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id) return 0; } -static int16_t sdl_input_state(void *data_, const struct retro_keybind **binds, +static int16_t sdl_input_state(void *data_, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { enum input_device_type type = INPUT_DEVICE_TYPE_NONE; @@ -249,7 +247,7 @@ static int16_t sdl_input_state(void *data_, const struct retro_keybind **binds, switch (device) { case RETRO_DEVICE_JOYPAD: - return sdl_joypad_device_state(data, binds, port, id, &type); + 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); case RETRO_DEVICE_MOUSE: diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 8f69389cd8..3d341d7d04 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -492,21 +492,17 @@ static int16_t udev_pointer_state(udev_input_t *udev, return 0; } -static int16_t udev_input_state(void *data, const struct retro_keybind **binds, +static int16_t udev_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { int16_t ret; - rarch_joypad_info_t joypad_info; - settings_t *settings = config_get_ptr(); udev_input_t *udev = (udev_input_t*)data; if (!udev) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index b4c1d288ed..38207ff98e 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -47,21 +47,18 @@ static void wiiu_input_poll(void *data) wiiu->joypad->poll(); } -static int16_t wiiu_input_state(void *data, const struct retro_keybind **binds, +static int16_t wiiu_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { rarch_joypad_info_t joypad_info; - settings_t *settings = config_get_ptr(); wiiu_input_t *wiiu = (wiiu_input_t*)data; if(!wiiu || (port > 0) || !binds || !binds[port]) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index 6e737be5b9..08d33a87e1 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -220,18 +220,13 @@ static int16_t x_lightgun_state(x11_input_t *x11, unsigned id) } static int16_t x_input_state(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned idx, unsigned id) { - rarch_joypad_info_t joypad_info; int16_t ret = 0; - settings_t *settings = config_get_ptr(); x11_input_t *x11 = (x11_input_t*)data; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: @@ -242,7 +237,7 @@ static int16_t x_input_state(void *data, case RETRO_DEVICE_ANALOG: if (binds[port]) ret = x_pressed_analog(x11, binds[port], idx, id); - if (!ret && binds[port] && binds[port]) + if (!ret && binds[port]) ret = input_joypad_analog(x11->joypad, joypad_info, port, idx, id, binds[port]); diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 0d1ba26c85..35df65a880 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -47,21 +47,17 @@ static void xdk_input_poll(void *data) xdk->joypad->poll(); } -static int16_t xdk_input_state(void *data, const struct retro_keybind **binds, +static int16_t xdk_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) { - rarch_joypad_info_t joypad_info; xdk_input_t *xdk = (xdk_input_t*)data; - settings_t *settings = config_get_ptr(); if (port >= MAX_PADS) return 0; - joypad_info.joy_idx = port; - joypad_info.auto_binds = settings->input.autoconf_binds[port]; - joypad_info.axis_threshold = settings->input.axis_threshold; - switch (device) { case RETRO_DEVICE_JOYPAD: diff --git a/input/drivers/xenon360_input.c b/input/drivers/xenon360_input.c index 3d4961dee7..7d62d51585 100644 --- a/input/drivers/xenon360_input.c +++ b/input/drivers/xenon360_input.c @@ -55,15 +55,15 @@ static void xenon360_input_poll(void *data) } } -static int16_t xenon360_input_state(void *data, const struct retro_keybind **binds, +static int16_t xenon360_input_state(void *data, + rarch_joypad_info_t joypad_info, + const struct retro_keybind **binds, bool port, unsigned device, unsigned idx, unsigned id) { - (void)data; - (void)idx; - unsigned user = port; + unsigned user = port; uint64_t button = binds[user][id].joykey; - int16_t retval = 0; + int16_t retval = 0; if(user < MAX_PADS) { @@ -72,6 +72,8 @@ static int16_t xenon360_input_state(void *data, const struct retro_keybind **bin case RETRO_DEVICE_JOYPAD: retval = (state[user] & button) ? 1 : 0; break; + default: + break; } } diff --git a/input/input_driver.c b/input/input_driver.c index f4d1b9804a..e8f96e1e4e 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -265,6 +265,7 @@ static const struct retro_keybind *libretro_input_binds[MAX_USERS]; void input_poll(void) { size_t i; + rarch_joypad_info_t joypad_info; settings_t *settings = config_get_ptr(); unsigned max_users = settings->input.max_users; @@ -278,15 +279,23 @@ void input_poll(void) input_driver_turbo_btns.frame_enable[i] = 0; } + joypad_info.axis_threshold = settings->input.axis_threshold; + if (!input_driver_block_libretro_input) { for (i = 0; i < max_users; i++) { bool bind_valid = libretro_input_binds[i][RARCH_TURBO_ENABLE].valid; + if (bind_valid) + { + joypad_info.joy_idx = i; + joypad_info.auto_binds = settings->input.autoconf_binds[i]; + input_driver_turbo_btns.frame_enable[i] = current_input->input_state( - current_input_data, libretro_input_binds, + current_input_data, joypad_info, libretro_input_binds, i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); + } } } @@ -325,11 +334,14 @@ void input_poll(void) int16_t input_state(unsigned port, unsigned device, unsigned idx, unsigned id) { + rarch_joypad_info_t joypad_info; int16_t res = 0; settings_t *settings = config_get_ptr(); device &= RETRO_DEVICE_MASK; + joypad_info.axis_threshold = settings->input.axis_threshold; + if (bsv_movie_ctl(BSV_MOVIE_CTL_PLAYBACK_ON, NULL)) { int16_t ret; @@ -370,8 +382,12 @@ int16_t input_state(unsigned port, unsigned device, bind_valid = true; if (bind_valid) + { + joypad_info.joy_idx = port; + joypad_info.auto_binds = settings->input.autoconf_binds[port]; res = current_input->input_state( - current_input_data, libretro_input_binds, port, device, idx, id); + current_input_data, joypad_info, libretro_input_binds, port, device, idx, id); + } } #ifdef HAVE_OVERLAY @@ -460,6 +476,7 @@ static const unsigned buttons[] = { void state_tracker_update_input(uint16_t *input1, uint16_t *input2) { unsigned i; + rarch_joypad_info_t joypad_info; const struct retro_keybind *binds[MAX_USERS]; settings_t *settings = config_get_ptr(); unsigned max_users = settings->input.max_users; @@ -468,6 +485,8 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2) for (i = 0; i < max_users; i++) binds[i] = settings->input.binds[i]; + joypad_info.axis_threshold = settings->input.axis_threshold; + for (i = 0; i < max_users; i++) { struct retro_keybind *general_binds = settings->input.binds[i]; @@ -488,11 +507,21 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2) unsigned id = buttons[i - 4]; if (binds[0][id].valid) - *input1 |= (current_input->input_state(current_input_data, binds, + { + joypad_info.joy_idx = 0; + joypad_info.auto_binds = settings->input.autoconf_binds[0]; + *input1 |= (current_input->input_state(current_input_data, joypad_info, + binds, 0, RETRO_DEVICE_JOYPAD, 0, id) ? 1 : 0) << i; + } if (binds[1][id].valid) - *input2 |= (current_input->input_state(current_input_data, binds, + { + joypad_info.joy_idx = 1; + joypad_info.auto_binds = settings->input.autoconf_binds[1]; + *input2 |= (current_input->input_state(current_input_data, joypad_info, + binds, 1, RETRO_DEVICE_JOYPAD, 0, id) ? 1 : 0) << i; + } } } @@ -509,6 +538,8 @@ void state_tracker_update_input(uint16_t *input1, uint16_t *input2) #ifdef HAVE_MENU static INLINE bool input_menu_keys_pressed_internal( const struct retro_keybind **binds, + settings_t *settings, + rarch_joypad_info_t joypad_info, unsigned i, unsigned max_users, bool bind_valid, bool all_users_control_menu) @@ -524,7 +555,12 @@ static INLINE bool input_menu_keys_pressed_internal( for (port = 0; port < port_max; port++) { bool bind_valid = binds[port][i].valid; - if (bind_valid && current_input->input_state(current_input_data, binds, + + joypad_info.joy_idx = port; + joypad_info.auto_binds = settings->input.autoconf_binds[port]; + + if (bind_valid && current_input->input_state(current_input_data, joypad_info, + binds, port, RETRO_DEVICE_JOYPAD, 0, i)) return true; } @@ -565,14 +601,16 @@ static INLINE bool input_menu_keys_pressed_internal( return false; } -#define input_keys_pressed_checks(binds, enable_hotkey_valid) \ +#define input_keys_pressed_checks(settings, joypad_info, binds, enable_hotkey_valid) \ input_driver_block_libretro_input = false; \ input_driver_block_hotkey = false; \ if (current_input->keyboard_mapping_is_blocked && current_input->keyboard_mapping_is_blocked(current_input_data)) \ input_driver_block_hotkey = true; \ if (check_input_driver_block_hotkey(binds_norm, binds_auto)) \ { \ - if (enable_hotkey_valid && current_input->input_state(current_input_data, binds, 0, RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY)) \ + joypad_info.joy_idx = 0; \ + joypad_info.auto_binds = settings->input.autoconf_binds[0]; \ + if (enable_hotkey_valid && current_input->input_state(current_input_data, joypad_info, binds, 0, RETRO_DEVICE_JOYPAD, 0, RARCH_ENABLE_HOTKEY)) \ input_driver_block_libretro_input = true; \ else \ input_driver_block_hotkey = true; \ @@ -616,6 +654,7 @@ uint64_t input_menu_keys_pressed( if (current_input && current_input_data) { unsigned i; + rarch_joypad_info_t joypad_info; const struct retro_keybind *binds[MAX_USERS] = {NULL}; settings_t *settings = config_get_ptr(); const struct retro_keybind *binds_norm = &settings->input.binds[0][RARCH_ENABLE_HOTKEY]; @@ -634,7 +673,9 @@ uint64_t input_menu_keys_pressed( input_push_analog_dpad(auto_binds, ANALOG_DPAD_LSTICK); } - input_keys_pressed_checks(&binds[0], enable_hotkey_valid); + joypad_info.axis_threshold = settings->input.axis_threshold; + + input_keys_pressed_checks(settings, joypad_info, &binds[0], enable_hotkey_valid); for (i = 0; i < RARCH_BIND_LIST_END; i++) { @@ -644,7 +685,7 @@ uint64_t input_menu_keys_pressed( for (port = 0; port < max_users; port++) binds[port] = settings->input.binds[port]; - if (input_menu_keys_pressed_internal(binds, i, max_users, + if (input_menu_keys_pressed_internal(binds, settings, joypad_info, i, max_users, settings->input.binds[0][i].valid, settings->input.all_users_control_menu)) ret |= (UINT64_C(1) << i); @@ -695,7 +736,7 @@ uint64_t input_menu_keys_pressed( for (i = 0; i < 13; i++) { - if (current_input->input_state(current_input_data, binds, 0, + if (current_input->input_state(current_input_data, joypad_info, binds, 0, RETRO_DEVICE_KEYBOARD, 0, ids[i][0])) BIT64_SET(ret, ids[i][1]); } @@ -713,14 +754,21 @@ uint64_t input_menu_keys_pressed( } #endif -static INLINE bool input_keys_pressed_internal(unsigned i, +static INLINE bool input_keys_pressed_internal( + settings_t *settings, + rarch_joypad_info_t joypad_info, + unsigned i, const struct retro_keybind *binds) { if (((!input_driver_block_libretro_input && ((i < RARCH_FIRST_META_KEY))) || !input_driver_block_hotkey)) { bool bind_valid = binds[i].valid; - if (bind_valid && current_input->input_state(current_input_data, &binds, + + joypad_info.joy_idx = 0; + joypad_info.auto_binds = settings->input.autoconf_binds[0]; + + if (bind_valid && current_input->input_state(current_input_data, joypad_info, &binds, 0, RETRO_DEVICE_JOYPAD, 0, i)) return true; } @@ -779,6 +827,7 @@ uint64_t input_keys_pressed( bool runloop_paused) { unsigned i; + rarch_joypad_info_t joypad_info; uint64_t ret = 0; settings_t *settings = config_get_ptr(); const struct retro_keybind *binds = settings->input.binds[0]; @@ -789,22 +838,26 @@ uint64_t input_keys_pressed( const struct retro_keybind *focus_normal = &binds[RARCH_GAME_FOCUS_TOGGLE]; bool enable_hotkey_valid = binds_norm && binds_norm->valid; bool game_focus_toggle_valid = false; + + joypad_info.axis_threshold = settings->input.axis_threshold; - input_keys_pressed_checks(&binds, enable_hotkey_valid); + input_keys_pressed_checks(settings, joypad_info, &binds, enable_hotkey_valid); game_focus_toggle_valid = binds[RARCH_GAME_FOCUS_TOGGLE].valid; /* Allows rarch_focus_toggle hotkey to still work even though every hotkey is blocked */ if (check_input_driver_block_hotkey(focus_normal, focus_binds_auto) && game_focus_toggle_valid) { - if (current_input->input_state(current_input_data, &binds, 0, + joypad_info.joy_idx = 0; + joypad_info.auto_binds = settings->input.autoconf_binds[0]; + if (current_input->input_state(current_input_data, joypad_info, &binds, 0, RETRO_DEVICE_JOYPAD, 0, RARCH_GAME_FOCUS_TOGGLE)) input_driver_block_hotkey = false; } for (i = 0; i < RARCH_BIND_LIST_END; i++) { - if (input_keys_pressed_internal(i, binds)) + if (input_keys_pressed_internal(settings, joypad_info, i, binds)) ret |= (UINT64_C(1) << i); } diff --git a/input/input_driver.h b/input/input_driver.h index f7dbe8596e..94cde488c5 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -74,6 +74,7 @@ typedef struct input_driver void *(*init)(void); void (*poll)(void *data); int16_t (*input_state)(void *data, + rarch_joypad_info_t joypad_info, const struct retro_keybind **retro_keybinds, unsigned port, unsigned device, unsigned index, unsigned id); bool (*meta_key_pressed)(void *data, int key); diff --git a/input/input_overlay.c b/input/input_overlay.c index 044534567b..52dca6908f 100644 --- a/input/input_overlay.c +++ b/input/input_overlay.c @@ -569,6 +569,7 @@ bool input_overlay_key_pressed(input_overlay_t *ol, int key) void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad_mode, float axis_threshold) { + rarch_joypad_info_t joypad_info; input_overlay_state_t old_key_state; unsigned i, j, device; uint16_t key_mod = 0; @@ -578,6 +579,10 @@ void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad if (!ol_state) return; + joypad_info.joy_idx = 0; + joypad_info.auto_binds = NULL; + joypad_info.axis_threshold = 0.0f; + memcpy(old_key_state.keys, ol_state->keys, sizeof(ol_state->keys)); memset(ol_state, 0, sizeof(*ol_state)); @@ -586,14 +591,17 @@ void input_poll_overlay(input_overlay_t *ol, float opacity, unsigned analog_dpad RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER; for (i = 0; - current_input->input_state(current_input_data, NULL, + current_input->input_state(current_input_data, joypad_info, + NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_PRESSED); i++) { input_overlay_state_t polled_data; - int16_t x = current_input->input_state(current_input_data, NULL, + int16_t x = current_input->input_state(current_input_data, joypad_info, + NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_X); - int16_t y = current_input->input_state(current_input_data, NULL, + int16_t y = current_input->input_state(current_input_data, joypad_info, + NULL, 0, device, i, RETRO_DEVICE_ID_POINTER_Y); memset(&polled_data, 0, sizeof(struct input_overlay_state)); diff --git a/menu/menu_event.c b/menu/menu_event.c index da67d0247d..0f4d6dc450 100644 --- a/menu/menu_event.c +++ b/menu/menu_event.c @@ -142,6 +142,8 @@ const char** menu_event_get_osk_grid(void) static int menu_event_pointer(unsigned *action) { + rarch_joypad_info_t joypad_info; + int pointer_x, pointer_y; const struct retro_keybind *binds[MAX_USERS] = {NULL}; menu_input_t *menu_input = menu_input_get_ptr(); unsigned fb_width = menu_display_get_width(); @@ -149,19 +151,30 @@ static int menu_event_pointer(unsigned *action) int pointer_device = menu_driver_ctl(RARCH_MENU_CTL_IS_SET_TEXTURE, NULL) ? RETRO_DEVICE_POINTER : RARCH_DEVICE_POINTER_SCREEN; - int pointer_x = - current_input->input_state(current_input_data, binds, + + joypad_info.joy_idx = 0; + joypad_info.auto_binds = NULL; + joypad_info.axis_threshold = 0.0f; + + pointer_x = + current_input->input_state(current_input_data, joypad_info, binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_X); - int pointer_y = - current_input->input_state(current_input_data, binds, + pointer_y = + current_input->input_state(current_input_data, joypad_info, binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_Y); - menu_input->pointer.pressed[0] = current_input->input_state(current_input_data, binds, + menu_input->pointer.pressed[0] = current_input->input_state(current_input_data, + joypad_info, + binds, 0, pointer_device, 0, RETRO_DEVICE_ID_POINTER_PRESSED); - menu_input->pointer.pressed[1] = current_input->input_state(current_input_data, binds, + menu_input->pointer.pressed[1] = current_input->input_state(current_input_data, + joypad_info, + binds, 0, pointer_device, 1, RETRO_DEVICE_ID_POINTER_PRESSED); - menu_input->pointer.back = current_input->input_state(current_input_data, binds, - 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); + menu_input->pointer.back = current_input->input_state(current_input_data, + joypad_info, + binds, + 0, pointer_device, 0, RARCH_DEVICE_ID_POINTER_BACK); menu_input->pointer.x = ((pointer_x + 0x7fff) * (int)fb_width) / 0xFFFF; menu_input->pointer.y = ((pointer_y + 0x7fff) * (int)fb_height) / 0xFFFF; diff --git a/menu/menu_input.c b/menu/menu_input.c index 50a2c96235..3300894912 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -358,8 +358,13 @@ int16_t menu_input_pointer_state(enum menu_input_pointer_state state) int16_t menu_input_mouse_state(enum menu_input_mouse_state state) { - unsigned type = 0; - unsigned device = RETRO_DEVICE_MOUSE; + rarch_joypad_info_t joypad_info; + unsigned type = 0; + unsigned device = RETRO_DEVICE_MOUSE; + + joypad_info.joy_idx = 0; + joypad_info.auto_binds = NULL; + joypad_info.axis_threshold = 0.0f; switch (state) { @@ -391,8 +396,8 @@ int16_t menu_input_mouse_state(enum menu_input_mouse_state state) break; } - return current_input->input_state(current_input_data, NULL, - 0, device, 0, type); + return current_input->input_state(current_input_data, joypad_info, + NULL, 0, device, 0, type); } static int menu_input_pointer_post_iterate( diff --git a/menu/widgets/menu_input_bind_dialog.c b/menu/widgets/menu_input_bind_dialog.c index 094f878b94..cc782330e9 100644 --- a/menu/widgets/menu_input_bind_dialog.c +++ b/menu/widgets/menu_input_bind_dialog.c @@ -209,6 +209,7 @@ static void menu_input_key_bind_poll_bind_state( unsigned port, bool timed_out) { + rarch_joypad_info_t joypad_info; const input_device_driver_t *joypad = input_driver_get_joypad_driver(); const input_device_driver_t *sec_joypad = @@ -218,7 +219,13 @@ static void menu_input_key_bind_poll_bind_state( return; memset(state->state, 0, sizeof(state->state)); - state->skip = timed_out || current_input->input_state(current_input_data, NULL, + + joypad_info.joy_idx = 0; + joypad_info.auto_binds = NULL; + joypad_info.axis_threshold = 0.0f; + + state->skip = timed_out || current_input->input_state(current_input_data, joypad_info, + NULL, 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN); menu_input_key_bind_poll_bind_state_internal(