From d0866995bd3b53d919acf5f302b5be4e9f5605eb Mon Sep 17 00:00:00 2001 From: Toad King Date: Thu, 2 Jul 2015 21:48:06 -0500 Subject: [PATCH 1/2] set back button to menu toggle if not set through autoconf --- input/drivers/android_input.c | 34 ++++++++++++++++----------- input/drivers_joypad/android_joypad.c | 8 +++++-- input/input_autodetect.c | 24 ++++++++++--------- input/input_autodetect.h | 2 +- tools/retroarch-joyconfig.c | 23 +++++++++--------- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 720cc9e61c..a25ba7fd36 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -3,7 +3,7 @@ * Copyright (C) 2011-2015 - Daniel De Matteis * Copyright (C) 2012-2015 - Michael Lelli * Copyright (C) 2013-2014 - Steven Crowe - * + * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- * ation, either version 3 of the License, or (at your option) any later version. @@ -85,7 +85,7 @@ typedef struct android_input state_device_t pad_states[MAX_PADS]; uint8_t pad_state[MAX_PADS][(LAST_KEYCODE + 7) / 8]; int8_t hat_state[MAX_PADS][2]; - + int16_t analog_state[MAX_PADS][MAX_AXIS]; sensor_t accelerometer_state; struct input_pointer pointer[MAX_TOUCH]; @@ -142,7 +142,7 @@ static void engine_handle_dpad_getaxisvalue(android_input_t *android, android->hat_state[port][0] = (int)hatx; android->hat_state[port][1] = (int)haty; - /* XXX: this could be a loop instead, but do we really want to + /* XXX: this could be a loop instead, but do we really want to * loop through every axis? */ android->analog_state[port][0] = (int16_t)(x * 32767.0f); @@ -327,7 +327,7 @@ static void engine_handle_cmd(void) scond_broadcast(android_app->cond); slock_unlock(android_app->mutex); - + break; case APP_CMD_INIT_WINDOW: @@ -396,7 +396,7 @@ static void engine_handle_cmd(void) runloop->is_paused = false; runloop->is_idle = false; - if ((android_app->sensor_state_mask + if ((android_app->sensor_state_mask & (1ULL << RETRO_SENSOR_ACCELEROMETER_ENABLE)) && android_app->accelerometerSensor == NULL && driver->input_data) @@ -436,7 +436,7 @@ static void *android_input_init(void) frontend_android_get_version_sdk(&sdk); RARCH_LOG("sdk version: %d\n", sdk); - + if (sdk >= 19) engine_lookup_name = android_input_lookup_name; else @@ -471,7 +471,7 @@ static INLINE int android_input_poll_event_type_motion( if (keyup && motion_pointer < MAX_TOUCH) { - memmove(android->pointer + motion_pointer, + memmove(android->pointer + motion_pointer, android->pointer + motion_pointer + 1, (MAX_TOUCH - motion_pointer - 1) * sizeof(struct input_pointer)); if (android->pointer_count > 0) @@ -528,7 +528,7 @@ static int android_input_get_id_port(android_input_t *android, int id, int source) { unsigned i; - if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | + if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD)) return 0; /* touch overlay is always user 1 */ @@ -565,6 +565,7 @@ static void handle_hotplug(android_input_t *android, name_buf[0] = device_name[0] = 0; int vendorId = 0, productId = 0; settings_t *settings = config_get_ptr(); + bool autoconfigured = false; if (!settings->input.autodetect_enable) return; @@ -620,7 +621,7 @@ static void handle_hotplug(android_input_t *android, strlcpy(name_buf, "TTT THT Arcade (User 1)", sizeof(name_buf)); else if (*port == 1) strlcpy(name_buf, "TTT THT Arcade (User 2)", sizeof(name_buf)); - } + } else if (strstr(device_name, "Sun4i-keypad")) strlcpy(name_buf, "iDroid x360", sizeof(name_buf)); else if (strstr(device_name, "mtk-kpd")) @@ -659,7 +660,7 @@ static void handle_hotplug(android_input_t *android, strstr(device_name, "Sixaxis") || strstr(device_name, "Gasia,Co") || (strstr(device_name, "Gamepad 0") || - strstr(device_name, "Gamepad 1") || + strstr(device_name, "Gamepad 1") || strstr(device_name, "Gamepad 2") || strstr(device_name, "Gamepad 3")) ) @@ -728,7 +729,7 @@ static void handle_hotplug(android_input_t *android, params.vid = vendorId; params.pid = productId; strlcpy(params.driver, android_joypad.ident, sizeof(params.driver)); - input_config_autoconfigure_joypad(¶ms); + autoconfigured = input_config_autoconfigure_joypad(¶ms); } *port = android->pads_connected; @@ -737,6 +738,11 @@ static void handle_hotplug(android_input_t *android, strlcpy(android->pad_states[*port].name, name_buf, sizeof(android->pad_states[*port].name)); + if (!autoconfigured) + { + settings->input.binds[*port][RARCH_MENU_TOGGLE].joykey = AKEYCODE_BACK; + } + android->pads_connected++; } @@ -822,7 +828,7 @@ static void android_input_poll(void *data) { int ident; - while ((ident = + while ((ident = ALooper_pollAll((input_driver_key_pressed(RARCH_PAUSE_TOGGLE)) ? -1 : 0, NULL, NULL, NULL)) >= 0) @@ -937,7 +943,7 @@ static uint64_t android_input_get_capabilities(void *data) { (void)data; - return + return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_POINTER) | (1 << RETRO_DEVICE_ANALOG); @@ -990,7 +996,7 @@ static bool android_input_set_sensor_state(void *data, unsigned port, if (android_app->accelerometerSensor) ASensorEventQueue_disableSensor(android->sensorEventQueue, android_app->accelerometerSensor); - + android_app->sensor_state_mask &= ~(1ULL << RETRO_SENSOR_ACCELEROMETER_ENABLE); android_app->sensor_state_mask |= (1ULL << RETRO_SENSOR_ACCELEROMETER_DISABLE); return true; diff --git a/input/drivers_joypad/android_joypad.c b/input/drivers_joypad/android_joypad.c index ec6aaa890d..5c2618bc2e 100644 --- a/input/drivers_joypad/android_joypad.c +++ b/input/drivers_joypad/android_joypad.c @@ -3,7 +3,7 @@ * Copyright (C) 2011-2015 - Daniel De Matteis * Copyright (C) 2012-2015 - Michael Lelli * Copyright (C) 2013-2014 - Steven Crowe - * + * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- * ation, either version 3 of the License, or (at your option) any later version. @@ -40,7 +40,11 @@ static bool android_joypad_init(void *data) params.idx = autoconf_pad; strlcpy(params.name, android_joypad_name(autoconf_pad), sizeof(params.name)); strlcpy(params.driver, android_joypad.ident, sizeof(params.driver)); - input_config_autoconfigure_joypad(¶ms); + + if (!input_config_autoconfigure_joypad(¶ms)) + { + settings->input.binds[autoconf_pad][RARCH_MENU_TOGGLE].joykey = AKEYCODE_BACK; + } } engine_handle_dpad = engine_handle_dpad_default; diff --git a/input/input_autodetect.c b/input/input_autodetect.c index 949438e01b..b0a067715c 100644 --- a/input/input_autodetect.c +++ b/input/input_autodetect.c @@ -90,7 +90,7 @@ static int input_try_autoconfigure_joypad_from_conf(config_file_t *conf, BIT32_SET(*match, AUTODETECT_MATCH_NAME); ret = 1; } - + /* Check for name match - name starts with ident */ if (ident[0] != '\0' && !strncmp(params->name, ident, strlen(ident))) { @@ -99,7 +99,7 @@ static int input_try_autoconfigure_joypad_from_conf(config_file_t *conf, if (!strcmp(params->driver, input_driver)) BIT32_SET(*match, AUTODETECT_MATCH_DRIVER); } - + /* Check for name match */ if (!strcmp(ident, params->name)) { @@ -107,7 +107,7 @@ static int input_try_autoconfigure_joypad_from_conf(config_file_t *conf, ret = 1; if (!strcmp(params->driver, input_driver)) BIT32_SET(*match, AUTODETECT_MATCH_DRIVER); - } + } return ret; } @@ -121,7 +121,7 @@ static void input_autoconfigure_joypad_add( /* This will be the case if input driver is reinitialized. * No reason to spam autoconfigure messages every time. */ - bool block_osd_spam = settings && + bool block_osd_spam = settings && settings->input.autoconfigured[params->idx] && *params->name; if (!settings) @@ -147,7 +147,7 @@ static int input_autoconfigure_joypad_from_conf( if (!conf) return false; - + ret = input_try_autoconfigure_joypad_from_conf(conf, params, &match); @@ -175,7 +175,7 @@ static bool input_autoconfigure_joypad_from_conf_dir( { config_file_t *conf = config_file_new(list->elems[i].data); ret = input_autoconfigure_joypad_from_conf(conf, params); - + if (ret == 1) break; @@ -230,15 +230,15 @@ static bool input_config_autoconfigure_joypad_init(autoconfig_params_t *params) return true; } -void input_config_autoconfigure_joypad(autoconfig_params_t *params) +bool input_config_autoconfigure_joypad(autoconfig_params_t *params) { bool ret = false; - + if (!input_config_autoconfigure_joypad_init(params)) - return; + return ret; if (!*params->name) - return; + return ret; #if defined(HAVE_BUILTIN_AUTOCONFIG) ret = input_autoconfigure_joypad_from_conf_internal(params); @@ -246,13 +246,15 @@ void input_config_autoconfigure_joypad(autoconfig_params_t *params) if (!ret) ret = input_autoconfigure_joypad_from_conf_dir(params); + + return ret; } const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id) { settings_t *settings = config_get_ptr(); unsigned joy_idx = 0; - + if (settings) joy_idx = settings->input.joypad_map[port]; diff --git a/input/input_autodetect.h b/input/input_autodetect.h index d96af1c516..d1bfca1f35 100644 --- a/input/input_autodetect.h +++ b/input/input_autodetect.h @@ -32,7 +32,7 @@ typedef struct autoconfig_params const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id); -void input_config_autoconfigure_joypad(autoconfig_params_t *params); +bool input_config_autoconfigure_joypad(autoconfig_params_t *params); void input_config_autoconfigure_disconnect(unsigned i, const char *ident); diff --git a/tools/retroarch-joyconfig.c b/tools/retroarch-joyconfig.c index 5d311a0db6..843c1563c6 100644 --- a/tools/retroarch-joyconfig.c +++ b/tools/retroarch-joyconfig.c @@ -1,6 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen - * + * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- * ation, either version 3 of the License, or (at your option) any later version. @@ -31,7 +31,7 @@ #include /* Need to be present for build to work, but it's not *really* used. - * Better than having to build special versions of lots of objects + * Better than having to build special versions of lots of objects * with special #ifdefs. */ struct settings g_config; @@ -173,7 +173,7 @@ static void get_binds(config_file_t *conf, config_file_t *auto_conf, * has a default negative axis for shoulder triggers, * which makes configuration very awkward. * - * If default negative, we can't trigger on the negative axis, + * If default negative, we can't trigger on the negative axis, * and similar with defaulted positive axes. */ @@ -269,7 +269,7 @@ static void get_binds(config_file_t *conf, config_file_t *auto_conf, require_negative = initial_axes[j] > 0; require_positive = initial_axes[j] < 0; - /* Block the axis config until we're sure + /* Block the axis config until we're sure * axes have returned to their neutral state. */ if (same_axis) { @@ -279,7 +279,7 @@ static void get_binds(config_file_t *conf, config_file_t *auto_conf, block_axis = false; } - /* If axes are in their neutral state, + /* If axes are in their neutral state, * we can't allow it. */ if (require_negative && value >= 0) continue; @@ -461,9 +461,10 @@ static void parse_input(int argc, char *argv[]) } -void input_config_autoconfigure_joypad(autoconfig_params_t *params) +bool input_config_autoconfigure_joypad(autoconfig_params_t *params) { (void)params; + return false; } /* Need SDL_main on OSX. */ @@ -476,11 +477,11 @@ int main(int argc, char *argv[]) config_file_t *conf; config_file_t *auto_conf = NULL; - const char *index_list[] = { - "input_player1_joypad_index", - "input_player2_joypad_index", - "input_player3_joypad_index", - "input_player4_joypad_index", + const char *index_list[] = { + "input_player1_joypad_index", + "input_player2_joypad_index", + "input_player3_joypad_index", + "input_player4_joypad_index", "input_player5_joypad_index", "input_player6_joypad_index", "input_player7_joypad_index", From 26b4dc79d011fa0bb1574bf51991c6345d82269d Mon Sep 17 00:00:00 2001 From: Toad King Date: Thu, 2 Jul 2015 23:06:53 -0500 Subject: [PATCH 2/2] [Android] clear bindings on context reset, they end up getting rebound anyway bump version --- android/phoenix/AndroidManifest.xml | 2 +- input/drivers/android_input.c | 6 +++--- input/drivers_joypad/android_joypad.c | 17 +---------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/android/phoenix/AndroidManifest.xml b/android/phoenix/AndroidManifest.xml index cf69b2ab99..b528d90cab 100644 --- a/android/phoenix/AndroidManifest.xml +++ b/android/phoenix/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionName="1.2" android:installLocation="preferExternal"> pad_states[*port].name, name_buf, sizeof(android->pad_states[*port].name)); - if (!autoconfigured) - { + if (autoconfigured && strcmp(name_buf, "RetroKeyboard")) + settings->input.binds[*port][RARCH_MENU_TOGGLE].joykey = 0; + else settings->input.binds[*port][RARCH_MENU_TOGGLE].joykey = AKEYCODE_BACK; - } android->pads_connected++; } diff --git a/input/drivers_joypad/android_joypad.c b/input/drivers_joypad/android_joypad.c index 5c2618bc2e..68203c9467 100644 --- a/input/drivers_joypad/android_joypad.c +++ b/input/drivers_joypad/android_joypad.c @@ -26,26 +26,11 @@ static bool android_joypad_init(void *data) { unsigned autoconf_pad; settings_t *settings = config_get_ptr(); - autoconfig_params_t params = {{0}}; (void)data; for (autoconf_pad = 0; autoconf_pad < MAX_USERS; autoconf_pad++) - { - strlcpy(settings->input.device_names[autoconf_pad], - android_joypad_name(autoconf_pad), - sizeof(settings->input.device_names[autoconf_pad])); - - /* TODO - implement VID/PID? */ - params.idx = autoconf_pad; - strlcpy(params.name, android_joypad_name(autoconf_pad), sizeof(params.name)); - strlcpy(params.driver, android_joypad.ident, sizeof(params.driver)); - - if (!input_config_autoconfigure_joypad(¶ms)) - { - settings->input.binds[autoconf_pad][RARCH_MENU_TOGGLE].joykey = AKEYCODE_BACK; - } - } + settings->input.binds[autoconf_pad][RARCH_MENU_TOGGLE].joykey = AKEYCODE_BACK; engine_handle_dpad = engine_handle_dpad_default; if ((dlopen("/system/lib/libandroid.so", RTLD_LOCAL | RTLD_LAZY)) == 0)