From 630608a7fc6e0b445b977207ae3ed1470cda2255 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 30 Jan 2013 18:07:04 +0100 Subject: [PATCH] (Android) Control if back button exits on a per-controller basis --- android/native/jni/input_android.c | 11 ++++++++--- android/native/jni/input_autodetect.c | 6 ++++-- android/native/jni/input_autodetect.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c index 5bc4e6f488..019fe0d8ec 100644 --- a/android/native/jni/input_android.c +++ b/android/native/jni/input_android.c @@ -32,6 +32,7 @@ static unsigned pads_connected; static int state_device_ids[MAX_PADS]; +static int back_exits[MAX_PADS]; static uint64_t state[MAX_PADS]; struct input_pointer @@ -119,14 +120,18 @@ static void android_input_poll(void *data) { state_id = pads_connected; state_device_ids[pads_connected++] = id; + bool back_exit = true; - input_autodetect_setup(android_app, msg, sizeof(msg), state_id, id, source); + input_autodetect_setup(android_app, msg, sizeof(msg), state_id, id, source, &back_exit); long_msg_enable = true; + + back_exits[state_id] = back_exit; } - if (keycode == AKEYCODE_BACK && (source & (AINPUT_SOURCE_KEYBOARD))) + if (keycode == AKEYCODE_BACK) { - *lifecycle_state |= (1ULL << RARCH_QUIT_KEY); + if (back_exits[state_id]) + *lifecycle_state |= (1ULL << RARCH_QUIT_KEY); AInputQueue_finishEvent(android_app->inputQueue, event, handled); break; } diff --git a/android/native/jni/input_autodetect.c b/android/native/jni/input_autodetect.c index 42614545ab..1c4e9d1111 100644 --- a/android/native/jni/input_autodetect.c +++ b/android/native/jni/input_autodetect.c @@ -96,7 +96,7 @@ void input_autodetect_init (void) } } -void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned port, unsigned id, int source) +void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned port, unsigned id, int source, bool *back_exits) { struct android_app *android_app = (struct android_app*)data; // Hack - we have to add '1' to the bit mask here because @@ -364,6 +364,7 @@ void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned keycode_lut[AKEYCODE_BACK] |= ((RETRO_DEVICE_ID_JOYPAD_SELECT+1) << shift); keycode_lut[AKEYCODE_BUTTON_THUMBL] |= ((RETRO_DEVICE_ID_JOYPAD_L3+1) << shift); keycode_lut[AKEYCODE_BUTTON_THUMBR] |= ((RETRO_DEVICE_ID_JOYPAD_R3+1) << shift); + *back_exits = false; } else if (strstr(name_buf, "USB,2-axis 8-button gamepad") || strstr(name_buf, "BUFFALO BGC-FC801")) @@ -496,6 +497,7 @@ void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned /* Xperia Play */ /* TODO: menu button */ /* Menu : 82 */ + *back_exits = false; keycode_lut[AKEYCODE_DPAD_CENTER] |= ((RETRO_DEVICE_ID_JOYPAD_B+1) << shift); keycode_lut[AKEYCODE_BACK] |= ((RETRO_DEVICE_ID_JOYPAD_A+1) << shift); keycode_lut[AKEYCODE_BUTTON_X] |= ((RETRO_DEVICE_ID_JOYPAD_Y+1) << shift); @@ -519,6 +521,7 @@ void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned * RStick Right: 40 */ /* Red Samurai */ + *back_exits = false; keycode_lut[AKEYCODE_W] |= ((RETRO_DEVICE_ID_JOYPAD_UP+1) << shift); keycode_lut[AKEYCODE_S] |= ((RETRO_DEVICE_ID_JOYPAD_DOWN+1) << shift); keycode_lut[AKEYCODE_A] |= ((RETRO_DEVICE_ID_JOYPAD_LEFT+1) << shift); @@ -709,7 +712,6 @@ void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned keycode_lut[AKEYCODE_F9] |= ((RARCH_MUTE+1) << shift); keycode_lut[AKEYCODE_ESCAPE] |= ((RARCH_QUIT_KEY+1) << shift); - keycode_lut[AKEYCODE_BACK] |= ((RARCH_QUIT_KEY+1) << shift); } } diff --git a/android/native/jni/input_autodetect.h b/android/native/jni/input_autodetect.h index 0cb8ae7378..9fe1260310 100644 --- a/android/native/jni/input_autodetect.h +++ b/android/native/jni/input_autodetect.h @@ -64,6 +64,6 @@ extern uint64_t keycode_lut[LAST_KEYCODE]; extern bool volume_enable; void input_autodetect_init (void); -void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned port, unsigned id, int source); +void input_autodetect_setup (void *data, char *msg, size_t sizeof_msg, unsigned port, unsigned id, int source, bool *back_exit); #endif