Block libretro input when ENABLE_HOTKEY is held.

This commit is contained in:
Themaister 2014-07-11 00:26:50 +02:00
parent 650424c17c
commit cdc46ae512
6 changed files with 35 additions and 20 deletions

View File

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

View File

@ -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++)

View File

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

View File

@ -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++)

View File

@ -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++)

View File

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