diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index 78f1f254fd..b794534b67 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -673,15 +673,23 @@ static INLINE void android_mouse_calculate_deltas(android_input_t *android, android->mouse_y_delta = ceil(y) * y_scale; } -static INLINE void android_input_poll_event_type_motion( +static INLINE int android_input_poll_event_type_motion( android_input_t *android, AInputEvent *event, - int port, int source, bool vibrate_on_keypress) + int port, int source) { + int getaction, action; + size_t motion_ptr; + bool keyup; int btn; - int getaction = AMotionEvent_getAction(event); - int action = getaction & AMOTION_EVENT_ACTION_MASK; - size_t motion_ptr = getaction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; - bool keyup = ( + + /* Only handle events from a touchscreen or mouse */ + if (!(source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE))) + return 1; + + getaction = AMotionEvent_getAction(event); + action = getaction & AMOTION_EVENT_ACTION_MASK; + motion_ptr = getaction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + keyup = ( action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL || action == AMOTION_EVENT_ACTION_POINTER_UP) || @@ -720,7 +728,7 @@ static INLINE void android_input_poll_event_type_motion( android_mouse_calculate_deltas(android,event,motion_ptr); - return; + return 0; } if (keyup && motion_ptr < MAX_TOUCH) @@ -744,6 +752,8 @@ static INLINE void android_input_poll_event_type_motion( { int pointer_max = MIN( AMotionEvent_getPointerCount(event), MAX_TOUCH); + settings_t *settings = config_get_ptr(); + bool vibrate_on_keypress = settings ? settings->bools.vibrate_on_keypress : false; if (vibrate_on_keypress && action != AMOTION_EVENT_ACTION_MOVE) android_app_write_cmd(g_android, APP_CMD_VIBRATE_KEYPRESS); @@ -759,8 +769,7 @@ static INLINE void android_input_poll_event_type_motion( /* If another touch happened within 200ms after a quick tap * then cancel the quick tap and register left mouse button * as being held down */ - if ((AMotionEvent_getEventTime(event) - android->quick_tap_time) - / 1000000 < 200) + if ((AMotionEvent_getEventTime(event) - android->quick_tap_time)/1000000 < 200) { android->quick_tap_time = 0; android->mouse_l = 1; @@ -801,14 +810,15 @@ static INLINE void android_input_poll_event_type_motion( * then count it as a mouse right click */ if (ENABLE_TOUCH_SCREEN_MOUSE) android->mouse_r = (android->pointer_count == 2); + + return 0; } -static bool is_keyboard_id(int id) +bool is_keyboard_id(int id) { - unsigned i; - for(i = 0; i < kbd_num; i++) - if (id == kbd_id[i]) - return true; + for(int i=0; i DEFAULT_MAX_PADS) return; @@ -1219,13 +1233,8 @@ static int android_input_get_id(AInputEvent *event) static void android_input_poll_input(android_input_t *android) { - char device_model[256]; - device_model[0] = 0; AInputEvent *event = NULL; struct android_app *android_app = (struct android_app*)g_android; - settings_t *settings = config_get_ptr(); - bool vibrate_on_keypress = settings ? settings->bools.vibrate_on_keypress : false; - frontend_android_get_name(device_model, sizeof(device_model)); /* Read all pending events. */ while (AInputQueue_hasEvents(android_app->inputQueue)) @@ -1241,16 +1250,13 @@ static void android_input_poll_input(android_input_t *android) if (port < 0 && !is_keyboard_id(id)) handle_hotplug(android, android_app, - &port, id, source, device_model); + &port, id, source); switch (type_event) { case AINPUT_EVENT_TYPE_MOTION: - /* Only handle events from a touchscreen or mouse */ - if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE)) - android_input_poll_event_type_motion(android, event, - port, source, vibrate_on_keypress); - else + if (android_input_poll_event_type_motion(android, event, + port, source)) engine_handle_dpad(android, event, port, source); break; case AINPUT_EVENT_TYPE_KEY: