From 5deb9a31e6d1ae2411d5ab7135df43ddc5756896 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 21 Jun 2014 05:58:09 +0200 Subject: [PATCH] (Android) Create helper function android_input_get_id_port --- input/android_input.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/input/android_input.c b/input/android_input.c index aec3a7de29..3010b73b96 100644 --- a/input/android_input.c +++ b/input/android_input.c @@ -554,6 +554,19 @@ static void handle_hotplug(struct android_app *android_app, unsigned *port, unsi } } +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 | AINPUT_SOURCE_TOUCHPAD)) + return 0; // touch overlay is always player 1 + + for (i = 0; i < android->pads_connected; i++) + if (android->state_device_ids[i] == id) + return i; + + return -1; +} + // Handle all events. If our activity is in pause state, block until we're unpaused. static void android_input_poll(void *data) { @@ -585,17 +598,7 @@ static void android_input_poll(void *data) id = zeus_id; type_event = AInputEvent_getType(event); - port = -1; - - if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD)) - port = 0; // touch overlay is always player 1 - else - { - unsigned i; - for (i = 0; i < android->pads_connected; i++) - if (android->state_device_ids[i] == id) - port = i; - } + port = android_input_get_id_port(android, id, source); if (port < 0) {