From f778bee8567cddedbfcd25366930758185df507f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 27 Oct 2016 06:38:02 +0200 Subject: [PATCH] Add input_menu_keys_pressed to master --- input/input_driver.c | 80 ++++++++++++++++++++++++++++++++++++++++++++ input/input_driver.h | 2 ++ runloop.c | 2 +- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/input/input_driver.c b/input/input_driver.c index 327754737f..e237540727 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -663,6 +663,86 @@ uint64_t input_keys_pressed(void) return ret; } +/** + * input_menu_keys_pressed: + * + * Grab an input sample for this frame. We exclude + * keyboard input here. + * + * TODO: In case RARCH_BIND_LIST_END starts exceeding 64, + * and you need a bitmask of more than 64 entries, reimplement + * it to use something like rarch_bits_t. + * + * Returns: Input sample containg a mask of all pressed keys. + */ +uint64_t input_menu_keys_pressed(void) +{ + unsigned i; + uint64_t ret = 0; + settings_t *settings = config_get_ptr(); + + if (!current_input || !current_input_data) + return ret; + + if (current_input->key_pressed && + check_input_driver_block_hotkey( + current_input->key_pressed(current_input_data, RARCH_ENABLE_HOTKEY))) + input_driver_block_libretro_input = true; + else + input_driver_block_libretro_input = false; + + for (i = 0; i < RARCH_BIND_LIST_END; i++) + { + bool state = false; +#if 1 + if (((!input_driver_block_libretro_input && ((i < RARCH_FIRST_META_KEY))) + || !input_driver_block_hotkey) && current_input->key_pressed) + state = current_input->key_pressed(current_input_data, i); + + if (i >= RARCH_FIRST_META_KEY) + state |= current_input->meta_key_pressed(current_input_data, i); +#else + if (((((!input_driver_block_libretro_input && ((i < RARCH_FIRST_META_KEY))) + || !input_driver_block_hotkey) && current_input->key_pressed)) + && settings->input.binds[0][i].valid) + { + state = input_joypad_pressed(input_driver_get_joypad_driver(), + 0, settings->input.binds[0], i); + } + + if (i >= RARCH_FIRST_META_KEY && settings->input.binds[0][i].valid) + state |= input_joypad_pressed(input_driver_get_joypad_driver(), + 0, settings->input.binds[0], i); +#endif + +#ifdef HAVE_OVERLAY + state |= input_overlay_key_pressed(i); +#endif + +#ifdef HAVE_COMMAND + if (input_driver_command) + { + command_handle_t handle; + + handle.handle = input_driver_command; + handle.id = i; + + state |= command_get(&handle); + } +#endif + +#ifdef HAVE_NETWORKGAMEPAD + if (input_driver_remote) + state |= input_remote_key_pressed(i, 0); +#endif + + if (state) + ret |= (UINT64_C(1) << i); + } + + return ret; +} + void *input_driver_get_data(void) { return current_input_data; diff --git a/input/input_driver.h b/input/input_driver.h index 657be73c9b..e51a296181 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -224,6 +224,8 @@ int16_t input_state(unsigned port, unsigned device, uint64_t input_keys_pressed(void); +uint64_t input_menu_keys_pressed(void); + void *input_driver_get_data(void); const input_driver_t *input_get_ptr(void); diff --git a/runloop.c b/runloop.c index ebfcfe7781..491b23c66f 100644 --- a/runloop.c +++ b/runloop.c @@ -1126,7 +1126,7 @@ int runloop_iterate(unsigned *sleep_ms) static retro_time_t frame_limit_minimum_time = 0.0; static retro_time_t frame_limit_last_time = 0.0; settings_t *settings = config_get_ptr(); - uint64_t current_input = input_keys_pressed(); + uint64_t current_input = menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL) ? input_menu_keys_pressed() : input_keys_pressed(); uint64_t old_input = last_input; last_input = current_input;