diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 8a2cdd28e0..1d5d7ae725 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -1363,6 +1363,10 @@ static void android_input_poll_memcpy(android_input_t *android) static bool android_input_key_pressed(android_input_t *android, int key) { rarch_joypad_info_t joypad_info; + const uint16_t joykey = (input_config_binds[0][key].joykey != NO_BTN) + ? input_config_binds[0][key].joykey : joypad_info.auto_binds[key].joykey; + const uint32_t joyaxis = (input_config_binds[0][key].joyaxis != AXIS_NONE) + ? input_config_binds[0][key].joyaxis : joypad_info.auto_binds[key].joyaxis; if((key < RARCH_BIND_LIST_END) && android_keyboard_port_input_pressed(input_config_binds[0], @@ -1373,10 +1377,10 @@ static bool android_input_key_pressed(android_input_t *android, int key) joypad_info.auto_binds = input_autoconf_binds[0]; joypad_info.axis_threshold = *(input_driver_get_float(INPUT_ACTION_AXIS_THRESHOLD)); - if (input_joypad_pressed(android->joypad, joypad_info, - 0, input_config_binds[0], key)) + if (joykey != NO_BTN && android->joypad->button(joypad_info.joy_idx, joykey)) + return true; + else if (((float)abs(android->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) return true; - return false; } @@ -1469,8 +1473,18 @@ static int16_t android_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - bool res = input_joypad_pressed(android->joypad, joypad_info, - port, binds[port], i); + bool res = false; + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + if (joykey != NO_BTN && android->joypad->button( + joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(android->joypad->axis( + joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; if (!res) res = android_keyboard_port_input_pressed(binds[port], i); if (res) @@ -1479,10 +1493,19 @@ static int16_t android_input_state(void *data, } else { - ret = input_joypad_pressed(android->joypad, joypad_info, - port, binds[port], id); + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (joykey != NO_BTN && android->joypad->button( + joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(android->joypad->axis( + joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; if (!ret && (id < RARCH_BIND_LIST_END)) - ret = android_keyboard_port_input_pressed(binds[port],id); + ret = android_keyboard_port_input_pressed(binds[port], id); } return ret; case RETRO_DEVICE_ANALOG: diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index a4eb4b2090..407cebeb4b 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -305,12 +305,27 @@ static int16_t cocoa_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; bool res = apple_key_state[rarch_keysym_lut[binds[port][i].key]]; if (!res) - res = input_joypad_pressed(apple->joypad, joypad_info, port, binds[port], i); + { + if (joykey != NO_BTN && apple->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(apple->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + } #ifdef HAVE_MFI if (!res) - res = input_joypad_pressed(apple->sec_joypad, joypad_info, port, binds[port], i); + { + if (joykey != NO_BTN && apple->sec_joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(apple->sec_joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + } #endif if (res) ret |= (1 << i); @@ -318,13 +333,29 @@ static int16_t cocoa_input_state(void *data, } else { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; if (id < RARCH_BIND_LIST_END) ret = apple_key_state[rarch_keysym_lut[binds[port][id].key]]; if (!ret) - ret = input_joypad_pressed(apple->joypad, joypad_info, port, binds[port], id); + { + if (joykey != NO_BTN && apple->joypad->button( + joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(apple->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } #ifdef HAVE_MFI if (!ret) - ret = input_joypad_pressed(apple->sec_joypad, joypad_info, port, binds[port], id); + { + if (joykey != NO_BTN && apple->sec_joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(apple->sec_joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } #endif } return ret; diff --git a/input/drivers/ctr_input.c b/input/drivers/ctr_input.c index 2bcdfc59bc..9187d699ca 100644 --- a/input/drivers/ctr_input.c +++ b/input/drivers/ctr_input.c @@ -66,14 +66,36 @@ static int16_t ctr_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed(ctr->joypad, - joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && + ctr->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(ctr->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else - ret = input_joypad_pressed(ctr->joypad, - joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && ctr->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(ctr->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/drivers/dinput.c b/input/drivers/dinput.c index a80ef455f9..207d2945e1 100644 --- a/input/drivers/dinput.c +++ b/input/drivers/dinput.c @@ -325,10 +325,19 @@ static bool dinput_is_pressed(struct dinput_input *di, if (binds && binds[id].valid) { - if (dinput_mouse_button_pressed(di, port, binds[id].mbutton)) - return true; - if (input_joypad_pressed(di->joypad, joypad_info, port, binds, id)) - return true; + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (dinput_mouse_button_pressed(di, port, binds[id].mbutton)) + return true; + if (joykey != NO_BTN + && di->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(di->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + return true; } return false; diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index 061893878b..c5a67a4952 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -87,8 +87,17 @@ static int16_t dos_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - bool res = input_joypad_pressed(ctr->joypad, - joypad_info, port, binds[port], i); + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && dos->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(dos->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; if (!res) res = dos_keyboard_port_input_pressed(binds[port], i); if (res) @@ -96,9 +105,21 @@ static int16_t dos_input_state(void *data, } } else - ret = input_joypad_pressed( - dos->joypad, joypad_info, port, binds[port], id) || - dos_keyboard_port_input_pressed(binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && dos->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(dos->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + + if (!ret) + ret = dos_keyboard_port_input_pressed(binds[port], id); + } return ret; case RETRO_DEVICE_KEYBOARD: return dos_keyboard_port_input_pressed(binds[port], id); diff --git a/input/drivers/gx_input.c b/input/drivers/gx_input.c index d2761c155a..e5e25a03cf 100644 --- a/input/drivers/gx_input.c +++ b/input/drivers/gx_input.c @@ -47,6 +47,7 @@ static int16_t gx_input_state(void *data, unsigned idx, unsigned id) { gx_input_t *gx = (gx_input_t*)data; + int16_t ret = 0; if (port >= MAX_PADS || !gx) return 0; @@ -57,18 +58,38 @@ static int16_t gx_input_state(void *data, if (id == RETRO_DEVICE_ID_JOYPAD_MASK) { unsigned i; - int16_t ret = 0; - for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed(gx->joypad, joypad_info, - port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && gx->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(gx->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } - return ret; } - return input_joypad_pressed(gx->joypad, - joypad_info, port, binds[port], id); + else + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && gx->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(gx->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } + return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) return input_joypad_analog(gx->joypad, diff --git a/input/drivers/linuxraw_input.c b/input/drivers/linuxraw_input.c index 0dabdce976..50e958bf8e 100644 --- a/input/drivers/linuxraw_input.c +++ b/input/drivers/linuxraw_input.c @@ -116,9 +116,21 @@ static int16_t linuxraw_input_state(void *data, linuxraw->state[rarch_keysym_lut[ (enum retro_key)binds[port][i].key]] ); + if (!res) - res = input_joypad_pressed(linuxraw->joypad, - joypad_info, port, binds[port], i); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + + if (joykey != NO_BTN && linuxraw->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(linuxraw->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + } + if (res) ret |= (1 << i); } @@ -128,9 +140,19 @@ static int16_t linuxraw_input_state(void *data, ret = ((id < RARCH_BIND_LIST_END) && binds[port]->valid && linuxraw->state[rarch_keysym_lut[(enum retro_key)binds[port][id].key]] ); + if (!ret) - ret = input_joypad_pressed(linuxraw->joypad, - joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (joykey != NO_BTN && linuxraw->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(linuxraw->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } } return ret; case RETRO_DEVICE_ANALOG: diff --git a/input/drivers/ps2_input.c b/input/drivers/ps2_input.c index b736b9a603..47df931571 100644 --- a/input/drivers/ps2_input.c +++ b/input/drivers/ps2_input.c @@ -59,13 +59,35 @@ static int16_t ps2_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - ps2->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && ps2->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(ps2->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else - ret = input_joypad_pressed(ps2->joypad, joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && ps2->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(ps2->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/drivers/ps3_input.c b/input/drivers/ps3_input.c index 0fdc7d540c..9cb6f89ba0 100644 --- a/input/drivers/ps3_input.c +++ b/input/drivers/ps3_input.c @@ -121,13 +121,35 @@ static int16_t ps3_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - ps3->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && ps3->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(ps3->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else - ret = input_joypad_pressed(ps3->joypad, joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && ps3->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(ps3->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/drivers/ps4_input.c b/input/drivers/ps4_input.c index 8d66a38880..d4e79f1b70 100644 --- a/input/drivers/ps4_input.c +++ b/input/drivers/ps4_input.c @@ -63,13 +63,35 @@ static int16_t ps4_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - ps4->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && ps4->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(ps4->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else - ret = input_joypad_pressed(ps4->joypad, joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && ps4->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(ps4->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/drivers/psp_input.c b/input/drivers/psp_input.c index eb6a2665a8..91ca51903f 100644 --- a/input/drivers/psp_input.c +++ b/input/drivers/psp_input.c @@ -318,13 +318,35 @@ static int16_t psp_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - psp->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && psp->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(psp->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else - ret = input_joypad_pressed(psp->joypad, joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && psp->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(psp->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/drivers/qnx_input.c b/input/drivers/qnx_input.c index 2bcbbf5614..aa61f13bdb 100644 --- a/input/drivers/qnx_input.c +++ b/input/drivers/qnx_input.c @@ -743,8 +743,20 @@ static bool qnx_is_pressed(qnx_input_t *qnx, if (qnx_keyboard_pressed(qnx, key)) if ((id == RARCH_GAME_FOCUS_TOGGLE) || !qnx->blocked) return true; - if (binds && binds[id].valid && input_joypad_pressed(qnx->joypad, joypad_info, port, binds, id)) - return true; + + if (binds && binds[id].valid) + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && qnx->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(qnx->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + return true; + } return false; } diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index a3472d3601..18d698c67c 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -486,11 +486,18 @@ static bool rwebinput_is_pressed(rwebinput_input_t *rwebinput, if (bind->valid) { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (port == 0 && !!rwebinput_mouse_state(&rwebinput->mouse, - bind->mbutton, false)) + bind->mbutton, false)) return true; - if (input_joypad_pressed(rwebinput->joypad, joypad_info, port, binds, - id)) + if (joykey != NO_BTN && rwebinput->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(rwebinput->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) return true; } } diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index fc6c661fca..e581e5e5e3 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -61,12 +61,12 @@ static void *sdl_input_init(const char *joypad_driver) static bool sdl_key_pressed(int key) { int num_keys; - unsigned sym = rarch_keysym_lut[(enum retro_key)key]; #ifdef HAVE_SDL2 const uint8_t *keymap = SDL_GetKeyboardState(&num_keys); - sym = SDL_GetScancodeFromKey(sym); + unsigned sym = SDL_GetScancodeFromKey(rarch_keysym_lut[(enum retro_key)key]); #else const uint8_t *keymap = SDL_GetKeyState(&num_keys); + unsigned sym = rarch_keysym_lut[(enum retro_key)key]; #endif if (sym >= (unsigned)num_keys) @@ -97,17 +97,30 @@ static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keybind *binds, unsigned port, unsigned id, enum input_device_type *device) { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if ((binds[id].key < RETROK_LAST) && sdl_key_pressed(binds[id].key)) { *device = INPUT_DEVICE_TYPE_KEYBOARD; return 1; } - if (input_joypad_pressed(sdl->joypad, joypad_info, 0, binds, id)) + if (joykey != NO_BTN && sdl->joypad->button(joypad_info.joy_idx, joykey)) { *device = INPUT_DEVICE_TYPE_JOYPAD; return 1; } + + if (((float)abs(sdl->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + { + *device = INPUT_DEVICE_TYPE_JOYPAD; + return 1; + } + return 0; } diff --git a/input/drivers/switch_input.c b/input/drivers/switch_input.c index ad3bf9411a..0bd2c9ad6b 100644 --- a/input/drivers/switch_input.c +++ b/input/drivers/switch_input.c @@ -271,15 +271,29 @@ static int16_t switch_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - sw->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + + if (joykey != NO_BTN && sw->joypad->button(joypad_info.joy_idx, joykey)) ret |= (1 << i); + else if (((float)abs(sw->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret |= (1 << 1); } } else { - ret = input_joypad_pressed(sw->joypad, - joypad_info, port, binds[port], id); + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (joykey != NO_BTN && sw->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(sw->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; } return ret; case RETRO_DEVICE_ANALOG: diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index 0250be8663..7ec4fe2fe3 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -902,9 +902,17 @@ static bool udev_is_pressed(udev_input_t *udev, if (binds && binds[id].valid) { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (udev_mouse_button_pressed(udev, port, bind->mbutton)) return true; - if (input_joypad_pressed(udev->joypad, joypad_info, port, binds, id)) + if (joykey != NO_BTN && udev->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(udev->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) return true; } diff --git a/input/drivers/uwp_input.c b/input/drivers/uwp_input.c index 5767cd292c..25e0367c83 100644 --- a/input/drivers/uwp_input.c +++ b/input/drivers/uwp_input.c @@ -138,9 +138,17 @@ static bool uwp_pressed_joypad(uwp_input_t *uwp, /* Then, process the joypad bindings */ if (binds && binds[id].valid) { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (uwp_mouse_state(port, bind->mbutton, false)) return true; - if (input_joypad_pressed(uwp->joypad, joypad_info, port, binds, id)) + if (joykey != NO_BTN && uwp->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(uwp->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) return true; } diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 8b5218e291..27033f310c 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -299,7 +299,17 @@ static int16_t input_wl_state(void *data, { bool res = BIT_GET(wl->key_state, rarch_keysym_lut[binds[port][i].key]) ; if (!res && binds[port]) - res = input_joypad_pressed(wl->joypad, joypad_info, port, binds[port], i); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + if (joykey != NO_BTN && wl->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(wl->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + } if (res) ret |= (1 << i); } @@ -309,7 +319,17 @@ static int16_t input_wl_state(void *data, if (id < RARCH_BIND_LIST_END) ret = BIT_GET(wl->key_state, rarch_keysym_lut[binds[port][id].key]); if (!ret && binds[port]) - ret = input_joypad_pressed(wl->joypad, joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (joykey != NO_BTN && wl->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(drv->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } } return ret; case RETRO_DEVICE_ANALOG: diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index 4456f22668..fae0945f99 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -147,15 +147,34 @@ static int16_t wiiu_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - wiiu->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && wiiu->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(wiiu->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else { - ret = input_joypad_pressed(wiiu->joypad, - joypad_info, port, binds[port], id); + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && wiiu->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(wiiu->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; } return ret; case RETRO_DEVICE_KEYBOARD: diff --git a/input/drivers/winraw_input.c b/input/drivers/winraw_input.c index 94db49b1d5..fab471e5fc 100644 --- a/input/drivers/winraw_input.c +++ b/input/drivers/winraw_input.c @@ -405,10 +405,18 @@ static bool winraw_is_pressed(winraw_input_t *wr, return true; if (binds && binds[id].valid) { - if (winraw_mouse_button_pressed(wr, port, bind->mbutton)) - return true; - if (input_joypad_pressed(wr->joypad, joypad_info, port, binds, id)) - return true; + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (winraw_mouse_button_pressed(wr, port, bind->mbutton)) + return true; + if (joykey != NO_BTN && + wr->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(wr->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + return true; } return false; diff --git a/input/drivers/x11_input.c b/input/drivers/x11_input.c index ff2a67d49f..33ed6fbf36 100644 --- a/input/drivers/x11_input.c +++ b/input/drivers/x11_input.c @@ -138,9 +138,18 @@ static bool x_is_pressed(x11_input_t *x11, if (binds && binds[id].valid) { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[id].joykey != NO_BTN) + ? binds[id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE) + ? binds[id].joyaxis : joypad_info.auto_binds[id].joyaxis; + if (x_mouse_button_pressed(x11, port, bind->mbutton)) return true; - if (input_joypad_pressed(x11->joypad, joypad_info, port, binds, id)) + if (joykey != NO_BTN + && x11->joypad->button(joypad_info.joy_idx, joykey)) + return true; + if (((float)abs(x11->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) return true; } diff --git a/input/drivers/xdk_xinput_input.c b/input/drivers/xdk_xinput_input.c index 8a4cc34bf6..641715e9ab 100644 --- a/input/drivers/xdk_xinput_input.c +++ b/input/drivers/xdk_xinput_input.c @@ -69,13 +69,35 @@ static int16_t xdk_input_state(void *data, unsigned i; for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) { - if (input_joypad_pressed( - xdk->joypad, joypad_info, port, binds[port], i)) + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][i].joykey != NO_BTN) + ? binds[port][i].joykey : joypad_info.auto_binds[i].joykey; + const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE) + ? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis; + bool res = false; + + if (joykey != NO_BTN && xdk->joypad->button(joypad_info.joy_idx, joykey)) + res = true; + else if (((float)abs(xdk->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + res = true; + + if (res) ret |= (1 << i); } } else - ret = input_joypad_pressed(xdk->joypad, joypad_info, port, binds[port], id); + { + /* Auto-binds are per joypad, not per user. */ + const uint16_t joykey = (binds[port][id].joykey != NO_BTN) + ? binds[port][id].joykey : joypad_info.auto_binds[id].joykey; + const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE) + ? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis; + + if (joykey != NO_BTN && xdk->joypad->button(joypad_info.joy_idx, joykey)) + ret = 1; + else if (((float)abs(xdk->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold) + ret = 1; + } return ret; case RETRO_DEVICE_ANALOG: if (binds[port]) diff --git a/input/input_driver.h b/input/input_driver.h index 70856e7868..0648eb2a01 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -446,39 +446,6 @@ const input_device_driver_t *input_joypad_init_driver( break; \ } -/** - * input_joypad_pressed: - * @drv : Input device driver handle. - * @port : User number. - * @binds : Binds of user. - * @key : Identifier of key. - * - * Checks if key (@key) was being pressed by user - * with number @port with provided keybinds (@binds). - * - * Returns: true (1) if key was pressed, otherwise - * false (0). - **/ -static INLINE bool input_joypad_pressed( - const input_device_driver_t *drv, - rarch_joypad_info_t joypad_info, - unsigned port, - const struct retro_keybind *binds, - unsigned key) -{ - /* Auto-binds are per joypad, not per user. */ - const uint64_t joykey = (binds[key].joykey != NO_BTN) - ? binds[key].joykey : joypad_info.auto_binds[key].joykey; - const uint32_t joyaxis = (binds[key].joyaxis != AXIS_NONE) - ? binds[key].joyaxis : joypad_info.auto_binds[key].joyaxis; - - if ((uint16_t)joykey != NO_BTN && drv->button(joypad_info.joy_idx, (uint16_t)joykey)) - return true; - - return ((float)abs(drv->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold; - -} - /** * input_joypad_analog: * @drv : Input device driver handle.