From 6f99b4d381113bf0eca498c0ed057fb65ed5aa04 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 11 Jul 2015 03:13:38 +0200 Subject: [PATCH] (Android) Implement 'Back As Menu Toggle Enable' setting --- config.def.h | 2 ++ configuration.c | 4 ++++ configuration.h | 1 + input/drivers/android_input.c | 12 ++++++++++-- menu/intl/menu_hash_us.c | 4 ++++ menu/menu_hash.h | 3 +++ menu/menu_setting.c | 15 +++++++++++++++ 7 files changed, 39 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index 8543594c34..46c82fd4cc 100644 --- a/config.def.h +++ b/config.def.h @@ -525,6 +525,8 @@ static unsigned menu_toggle_gamepad_combo = 2; static unsigned menu_toggle_gamepad_combo = 0; #endif +static bool back_as_menu_toggle_enable = true; + /* Crop overscanned frames. */ static const bool crop_overscan = true; diff --git a/configuration.c b/configuration.c index e0dcab60ab..34452a08e1 100644 --- a/configuration.c +++ b/configuration.c @@ -585,6 +585,7 @@ static void config_set_defaults(void) settings->camera.allow = false; settings->input.autoconfig_descriptor_label_show = true; + settings->input.back_as_menu_toggle_enable = true; settings->input.input_descriptor_label_show = input_descriptor_label_show; settings->input.input_descriptor_hide_unbound = input_descriptor_hide_unbound; settings->input.remap_binds_enable = true; @@ -1392,6 +1393,7 @@ static bool config_load_file(const char *path, bool set_defaults) if (!strcmp(settings->audio.filter_dir, "default")) *settings->audio.filter_dir = '\0'; + CONFIG_GET_BOOL_BASE(conf, settings, input.back_as_menu_toggle_enable, "back_as_menu_toggle_enable"); CONFIG_GET_BOOL_BASE(conf, settings, input.remap_binds_enable, "input_remap_binds_enable"); CONFIG_GET_FLOAT_BASE(conf, settings, input.axis_threshold, "input_axis_threshold"); CONFIG_GET_BOOL_BASE(conf, settings, input.netplay_client_swap_input, "netplay_client_swap_input"); @@ -2358,6 +2360,8 @@ bool config_save_file(const char *path) config_set_bool(conf, "video_gpu_record", settings->video.gpu_record); config_set_bool(conf, "input_remap_binds_enable", settings->input.remap_binds_enable); + config_set_bool(conf, "back_as_menu_toggle_enable", + settings->input.back_as_menu_toggle_enable); config_set_bool(conf, "netplay_client_swap_input", settings->input.netplay_client_swap_input); config_set_bool(conf, "input_descriptor_label_show", diff --git a/configuration.h b/configuration.h index 832ff0c343..06ba2810e4 100644 --- a/configuration.h +++ b/configuration.h @@ -244,6 +244,7 @@ typedef struct settings char remapping_path[PATH_MAX_LENGTH]; unsigned menu_toggle_gamepad_combo; + bool back_as_menu_toggle_enable; } input; struct diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 94bbc74ddc..afccd5571e 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -565,7 +565,7 @@ static void handle_hotplug(android_input_t *android, char name_buf[256] = {0}; int vendorId = 0; int productId = 0; - bool autoconfigured = false; + bool back_mapped = false; settings_t *settings = config_get_ptr(); if (*port > MAX_PADS) @@ -662,6 +662,7 @@ static void handle_hotplug(android_input_t *android, if (settings->input.autodetect_enable) { + unsigned autoconfigured = false; autoconfig_params_t params = {{0}}; RARCH_LOG("Port %d: %s.\n", *port, name_buf); @@ -672,9 +673,16 @@ static void handle_hotplug(android_input_t *android, params.pid = productId; strlcpy(params.driver, android_joypad.ident, sizeof(params.driver)); autoconfigured = input_config_autoconfigure_joypad(¶ms); + + if (autoconfigured) + { + if (settings->input.autoconf_binds[*port][RARCH_MENU_TOGGLE].joykey != 0) + back_mapped = true; + } } - (void)autoconfigured; + if (!back_mapped && settings->input.back_as_menu_toggle_enable) + settings->input.autoconf_binds[*port][RARCH_MENU_TOGGLE].joykey = AKEYCODE_BACK; *port = android->pads_connected; android->pad_states[android->pads_connected].id = id; diff --git a/menu/intl/menu_hash_us.c b/menu/intl/menu_hash_us.c index 1a9260b4d9..da00299046 100644 --- a/menu/intl/menu_hash_us.c +++ b/menu/intl/menu_hash_us.c @@ -26,6 +26,8 @@ static const char *menu_hash_to_str_us_label(uint32_t hash) { switch (hash) { + case MENU_LABEL_INPUT_BACK_AS_MENU_TOGGLE_ENABLE: + return "back_as_menu_toggle_enable"; case MENU_LABEL_INPUT_MENU_TOGGLE_GAMEPAD_COMBO: return "input_menu_toggle_gamepad_combo"; case MENU_LABEL_INPUT_OVERLAY_HIDE_IN_MENU: @@ -618,6 +620,8 @@ const char *menu_hash_to_str_us(uint32_t hash) switch (hash) { + case MENU_LABEL_VALUE_INPUT_BACK_AS_MENU_TOGGLE_ENABLE: + return "Back As Menu Toggle Enable"; case MENU_LABEL_VALUE_INPUT_MENU_TOGGLE_GAMEPAD_COMBO: return "Menu Toggle Gamepad Combo"; case MENU_LABEL_VALUE_INPUT_OVERLAY_HIDE_IN_MENU: diff --git a/menu/menu_hash.h b/menu/menu_hash.h index f1b2f70279..6ed62b3fc1 100644 --- a/menu/menu_hash.h +++ b/menu/menu_hash.h @@ -22,6 +22,9 @@ extern "C" { #endif +#define MENU_LABEL_VALUE_INPUT_BACK_AS_MENU_TOGGLE_ENABLE 0x1cf1e6a8U +#define MENU_LABEL_INPUT_BACK_AS_MENU_TOGGLE_ENABLE 0x60bacd04U + #define MENU_LABEL_INPUT_MENU_TOGGLE_GAMEPAD_COMBO 0xc5b7aa47U #define MENU_LABEL_VALUE_INPUT_MENU_TOGGLE_GAMEPAD_COMBO 0x0dedea3bU diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 388178d09c..66f87ec091 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -4257,6 +4257,21 @@ static bool setting_append_list_input_options( general_read_handler); menu_settings_list_current_add_range(list, list_info, 1, MAX_USERS, 1, true, true); +#ifdef ANDROID + CONFIG_BOOL( + settings->input.remap_binds_enable, + menu_hash_to_str(MENU_LABEL_INPUT_BACK_AS_MENU_TOGGLE_ENABLE), + menu_hash_to_str(MENU_LABEL_VALUE_INPUT_BACK_AS_MENU_TOGGLE_ENABLE), + back_as_menu_toggle_enable, + menu_hash_to_str(MENU_VALUE_OFF), + menu_hash_to_str(MENU_VALUE_ON), + group_info.name, + subgroup_info.name, + parent_group, + general_write_handler, + general_read_handler); +#endif + CONFIG_UINT( settings->input.menu_toggle_gamepad_combo, menu_hash_to_str(MENU_LABEL_INPUT_MENU_TOGGLE_GAMEPAD_COMBO),