diff --git a/driver.h b/driver.h index f54deb6386..43bcc7cedf 100644 --- a/driver.h +++ b/driver.h @@ -474,6 +474,7 @@ typedef struct driver bool stdin_claimed; bool block_hotkey; bool block_input; + bool block_libretro_input; bool nonblock_state; // Opaque handles to currently running window. diff --git a/frontend/menu/menu_input_line_cb.c b/frontend/menu/menu_input_line_cb.c index 11651846b0..2217275c28 100644 --- a/frontend/menu/menu_input_line_cb.c +++ b/frontend/menu/menu_input_line_cb.c @@ -310,16 +310,19 @@ uint64_t menu_input(void) for (i = 0; i < MAX_PLAYERS; i++) input_push_analog_dpad(g_settings.input.autoconf_binds[i], g_settings.input.analog_dpad_mode[i]); - for (i = 0; i < RETRO_DEVICE_ID_JOYPAD_R2; i++) + if (!driver.block_libretro_input) { - input_state |= input_input_state_func(binds, - 0, RETRO_DEVICE_JOYPAD, 0, i) ? (1ULL << i) : 0; + for (i = 0; i < RETRO_DEVICE_ID_JOYPAD_R2; i++) + { + input_state |= input_input_state_func(binds, + 0, RETRO_DEVICE_JOYPAD, 0, i) ? (1ULL << i) : 0; #ifdef HAVE_OVERLAY - input_state |= (driver.overlay_state.buttons & (UINT64_C(1) << i)) ? (1ULL << i) : 0; + input_state |= (driver.overlay_state.buttons & (UINT64_C(1) << i)) ? (1ULL << i) : 0; #endif - } + } - input_state |= input_key_pressed_func(RARCH_MENU_TOGGLE) ? (1ULL << RARCH_MENU_TOGGLE) : 0; + input_state |= input_key_pressed_func(RARCH_MENU_TOGGLE) ? (1ULL << RARCH_MENU_TOGGLE) : 0; + } input_pop_analog_dpad((struct retro_keybind*)binds[0]); for (i = 0; i < MAX_PLAYERS; i++) diff --git a/gfx/py_state/py_state.c b/gfx/py_state/py_state.c index ad15a663c6..456b5adc41 100644 --- a/gfx/py_state/py_state.c +++ b/gfx/py_state/py_state.c @@ -103,7 +103,7 @@ static PyObject *py_read_input(PyObject *self, PyObject *args) if (player > MAX_PLAYERS || player < 1 || key >= RARCH_FIRST_META_KEY) return NULL; - int16_t res = input_input_state_func(py_binds, player - 1, RETRO_DEVICE_JOYPAD, 0, key); + int16_t res = driver.block_libretro_input ? 0 : input_input_state_func(py_binds, player - 1, RETRO_DEVICE_JOYPAD, 0, key); return PyBool_FromLong(res); } diff --git a/gfx/state_tracker.c b/gfx/state_tracker.c index 6c006ddcee..4e9250a30e 100644 --- a/gfx/state_tracker.c +++ b/gfx/state_tracker.c @@ -251,10 +251,13 @@ static void update_input(state_tracker_t *tracker) input_push_analog_dpad(g_settings.input.autoconf_binds[i], g_settings.input.analog_dpad_mode[i]); uint16_t state[2] = {0}; - for (i = 4; i < 16; i++) + if (!driver.block_libretro_input) { - state[0] |= (input_input_state_func(binds, 0, RETRO_DEVICE_JOYPAD, 0, buttons[i - 4]) ? 1 : 0) << i; - state[1] |= (input_input_state_func(binds, 1, RETRO_DEVICE_JOYPAD, 0, buttons[i - 4]) ? 1 : 0) << i; + for (i = 4; i < 16; i++) + { + state[0] |= (input_input_state_func(binds, 0, RETRO_DEVICE_JOYPAD, 0, buttons[i - 4]) ? 1 : 0) << i; + state[1] |= (input_input_state_func(binds, 1, RETRO_DEVICE_JOYPAD, 0, buttons[i - 4]) ? 1 : 0) << i; + } } for (i = 0; i < 2; i++) diff --git a/netplay.c b/netplay.c index 28a4c62107..b937227e33 100644 --- a/netplay.c +++ b/netplay.c @@ -898,7 +898,7 @@ static bool get_self_input_state(netplay_t *handle) struct delta_frame *ptr = &handle->buffer[handle->self_ptr]; uint32_t state = 0; - if (handle->frame_count > 0) // First frame we always give zero input since relying on input from first frame screws up when we use -F 0. + if (!driver.block_libretro_input && handle->frame_count > 0) // First frame we always give zero input since relying on input from first frame screws up when we use -F 0. { retro_input_state_t cb = handle->cbs.state_cb; for (i = 0; i < RARCH_FIRST_META_KEY; i++) diff --git a/retroarch.c b/retroarch.c index 1f7e7bf911..b572e70eff 100644 --- a/retroarch.c +++ b/retroarch.c @@ -647,7 +647,7 @@ static int16_t input_state(unsigned port, unsigned device, unsigned index, unsig }; int16_t res = 0; - if (id < RARCH_FIRST_META_KEY || device == RETRO_DEVICE_KEYBOARD) + if (!driver.block_libretro_input && (id < RARCH_FIRST_META_KEY || device == RETRO_DEVICE_KEYBOARD)) res = input_input_state_func(binds, port, device, index, id); #ifdef HAVE_OVERLAY @@ -2356,9 +2356,14 @@ static void check_turbo(void) g_settings.input.binds[7], }; - for (i = 0; i < MAX_PLAYERS; i++) - g_extern.turbo_frame_enable[i] = - input_input_state_func(binds, i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); + if (driver.block_libretro_input) + memset(g_extern.turbo_frame_enable, 0, sizeof(g_extern.turbo_frame_enable)); + else + { + for (i = 0; i < MAX_PLAYERS; i++) + g_extern.turbo_frame_enable[i] = + input_input_state_func(binds, i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE); + } } static void check_shader_dir(void) @@ -2679,15 +2684,18 @@ static void check_netplay_flip(void) void rarch_check_block_hotkey(void) { + // Don't block the check to RARCH_ENABLE_HOTKEY unless we're really supposed to. driver.block_hotkey = driver.block_input; - // If we haven't bound anything to this, - // always allow hotkeys. + // If we haven't bound anything to this, always allow hotkeys. static const struct retro_keybind *bind = &g_settings.input.binds[0][RARCH_ENABLE_HOTKEY]; - if (!driver.block_hotkey && bind->key == RETROK_UNKNOWN && bind->joykey == NO_BTN && bind->joyaxis == AXIS_NONE) - return; + bool use_hotkey_enable = bind->key != RETROK_UNKNOWN || bind->joykey != NO_BTN || bind->joyaxis != AXIS_NONE; + bool enable_hotkey = input_key_pressed_func(RARCH_ENABLE_HOTKEY); - driver.block_hotkey = driver.block_input || !input_key_pressed_func(RARCH_ENABLE_HOTKEY); + driver.block_hotkey = driver.block_input || (use_hotkey_enable && !enable_hotkey); + + // If we hold ENABLE_HOTKEY button, block all libretro input to allow hotkeys to be bound to same keys as RetroPad. + driver.block_libretro_input = use_hotkey_enable && enable_hotkey; } #ifdef HAVE_OVERLAY