From 39580b5f89b48a587c18e79bf95901c2adceb14c Mon Sep 17 00:00:00 2001 From: "konrad.weiss13@gmail.com" Date: Tue, 28 Mar 2017 18:52:00 +0200 Subject: [PATCH 1/4] Enable scoring for single touch devices such that certain emulators do not fail. Single touch devices get outscored by multitouch devices. --- jni/minitouch/minitouch.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jni/minitouch/minitouch.c b/jni/minitouch/minitouch.c index 12f2e2c..539b06a 100644 --- a/jni/minitouch/minitouch.c +++ b/jni/minitouch/minitouch.c @@ -83,6 +83,11 @@ static int is_multitouch_device(struct libevdev* evdev) return libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X); } +static int is_singletouch_device(struct libevdev* evdev) +{ + return libevdev_has_event_code(evdev, EV_ABS, ABS_X); +} + static int consider_device(const char* devpath, internal_state_t* state) { int fd = -1; @@ -106,13 +111,16 @@ static int consider_device(const char* devpath, internal_state_t* state) goto mismatch; } + int score = 500; if (!is_multitouch_device(evdev)) + { + score += 500 + } + else if (!is_singletouch_device(evdev)) { goto mismatch; } - int score = 1000; - if (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_TOOL_TYPE)) { int tool_min = libevdev_get_abs_minimum(evdev, ABS_MT_TOOL_TYPE); From 2130eeb357576bb8b5622e474a1364d9d02719b2 Mon Sep 17 00:00:00 2001 From: "konrad.weiss13@gmail.com" Date: Tue, 28 Mar 2017 18:58:09 +0200 Subject: [PATCH 2/4] Adding event code to state of devices, a function to configure the movement event code and the screensize. --- jni/minitouch/minitouch.c | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/jni/minitouch/minitouch.c b/jni/minitouch/minitouch.c index 539b06a..d8213da 100644 --- a/jni/minitouch/minitouch.c +++ b/jni/minitouch/minitouch.c @@ -53,6 +53,8 @@ typedef struct int has_pressure; int min_pressure; int max_pressure; + int evcd_mt_x; + int evcd_mt_y; int max_x; int max_y; int max_contacts; @@ -88,6 +90,27 @@ static int is_singletouch_device(struct libevdev* evdev) return libevdev_has_event_code(evdev, EV_ABS, ABS_X); } +static void set_abs_configuration( internal_state_t* state) +{ + if (libevdev_has_event_code(state->evdev,EV_ABS, ABS_MT_POSITION_X) + && libevdev_has_event_code(state->evdev, EV_ABS, ABS_MT_POSITION_Y)) + { + state->evcd_mt_x = ABS_MT_POSITION_X; + state->evcd_mt_y = ABS_MT_POSITION_Y; + state->max_x = libevdev_get_abs_maximum(state->evdev, ABS_MT_POSITION_X); + state->max_y = libevdev_get_abs_maximum(state->evdev, ABS_MT_POSITION_Y); + return; + } + if(libevdev_has_event_code(state->evdev,EV_ABS, ABS_X) && libevdev_has_event_code(state->evdev,EV_ABS, ABS_Y)) + { + state->evcd_mt_x = ABS_X; + state->evcd_mt_y = ABS_Y; + state->max_x = libevdev_get_abs_maximum(state->evdev, ABS_X); + state->max_y = libevdev_get_abs_maximum(state->evdev, ABS_Y); + return; + } +} + static int consider_device(const char* devpath, internal_state_t* state) { int fd = -1; @@ -280,8 +303,8 @@ static int type_a_commit(internal_state_t* state) if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, state->contacts[contact].pressure); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, state->contacts[contact].x); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, state->contacts[contact].y); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, state->contacts[contact].x); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, state->contacts[contact].y); WRITE_EVENT(state, EV_SYN, SYN_MT_REPORT, 0); @@ -302,8 +325,8 @@ static int type_a_commit(internal_state_t* state) if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, state->contacts[contact].pressure); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, state->contacts[contact].x); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, state->contacts[contact].y); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, state->contacts[contact].x); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, state->contacts[contact].y); WRITE_EVENT(state, EV_SYN, SYN_MT_REPORT, 0); break; @@ -450,8 +473,8 @@ static int type_b_touch_down(internal_state_t* state, int contact, int x, int y, if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, x); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, y); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, x); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, y); return 1; } @@ -474,8 +497,8 @@ static int type_b_touch_move(internal_state_t* state, int contact, int x, int y, if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, x); - WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, y); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, x); + WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, y); return 1; } @@ -657,8 +680,7 @@ int main(int argc, char* argv[]) state.max_pressure= state.has_pressure ? libevdev_get_abs_maximum(state.evdev, ABS_MT_PRESSURE) : 0; - state.max_x = libevdev_get_abs_maximum(state.evdev, ABS_MT_POSITION_X); - state.max_y = libevdev_get_abs_maximum(state.evdev, ABS_MT_POSITION_Y); + set_abs_configuration(&state); state.max_tracking_id = state.has_tracking_id ? libevdev_get_abs_maximum(state.evdev, ABS_MT_TRACKING_ID) From 3e68b8dcaa8c3ff353afd4ea37ba926ef86cf03e Mon Sep 17 00:00:00 2001 From: "konrad.weiss13@gmail.com" Date: Tue, 28 Mar 2017 22:05:49 +0200 Subject: [PATCH 3/4] Fixes right scoring for multitouch devices --- jni/minitouch/minitouch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jni/minitouch/minitouch.c b/jni/minitouch/minitouch.c index d8213da..5c95199 100644 --- a/jni/minitouch/minitouch.c +++ b/jni/minitouch/minitouch.c @@ -135,9 +135,9 @@ static int consider_device(const char* devpath, internal_state_t* state) } int score = 500; - if (!is_multitouch_device(evdev)) + if (is_multitouch_device(evdev)) { - score += 500 + score += 500; } else if (!is_singletouch_device(evdev)) { From d3a34129609477acad32dd663a6242f453ee6ab7 Mon Sep 17 00:00:00 2001 From: Konrad Weiss Date: Mon, 8 May 2017 12:05:32 +0200 Subject: [PATCH 4/4] Differentiates already in the call of the functions that dispatch events into single and multi touch. This removes the dynamically set event codes for x and y coordinates --- jni/minitouch/minitouch.c | 185 +++++++++++++++++++++++++++++++++----- 1 file changed, 164 insertions(+), 21 deletions(-) diff --git a/jni/minitouch/minitouch.c b/jni/minitouch/minitouch.c index 5c95199..bb4149e 100644 --- a/jni/minitouch/minitouch.c +++ b/jni/minitouch/minitouch.c @@ -53,8 +53,7 @@ typedef struct int has_pressure; int min_pressure; int max_pressure; - int evcd_mt_x; - int evcd_mt_y; + int is_singletouch; int max_x; int max_y; int max_contacts; @@ -95,16 +94,14 @@ static void set_abs_configuration( internal_state_t* state) if (libevdev_has_event_code(state->evdev,EV_ABS, ABS_MT_POSITION_X) && libevdev_has_event_code(state->evdev, EV_ABS, ABS_MT_POSITION_Y)) { - state->evcd_mt_x = ABS_MT_POSITION_X; - state->evcd_mt_y = ABS_MT_POSITION_Y; + state->is_singletouch = 0; state->max_x = libevdev_get_abs_maximum(state->evdev, ABS_MT_POSITION_X); state->max_y = libevdev_get_abs_maximum(state->evdev, ABS_MT_POSITION_Y); return; } if(libevdev_has_event_code(state->evdev,EV_ABS, ABS_X) && libevdev_has_event_code(state->evdev,EV_ABS, ABS_Y)) { - state->evcd_mt_x = ABS_X; - state->evcd_mt_y = ABS_Y; + state->is_singletouch = 1; state->max_x = libevdev_get_abs_maximum(state->evdev, ABS_X); state->max_y = libevdev_get_abs_maximum(state->evdev, ABS_Y); return; @@ -276,7 +273,7 @@ static int next_tracking_id(internal_state_t* state) return state->tracking_id; } -static int type_a_commit(internal_state_t* state) +static int type_a_multi_touch_commit(internal_state_t* state) { int contact; int found_any = 0; @@ -303,8 +300,8 @@ static int type_a_commit(internal_state_t* state) if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, state->contacts[contact].pressure); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, state->contacts[contact].x); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, state->contacts[contact].y); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, state->contacts[contact].x); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, state->contacts[contact].y); WRITE_EVENT(state, EV_SYN, SYN_MT_REPORT, 0); @@ -325,8 +322,8 @@ static int type_a_commit(internal_state_t* state) if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, state->contacts[contact].pressure); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, state->contacts[contact].x); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, state->contacts[contact].y); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, state->contacts[contact].x); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, state->contacts[contact].y); WRITE_EVENT(state, EV_SYN, SYN_MT_REPORT, 0); break; @@ -352,6 +349,79 @@ static int type_a_commit(internal_state_t* state) return 1; } +static int type_a_single_touch_commit(internal_state_t* state) +{ + int contact; + int found_any = 0; + + for (contact = 0; contact < state->max_contacts; ++contact) + { + switch (state->contacts[contact].enabled) + { + case 1: // WENT_DOWN + found_any = 1; + + if (state->has_tracking_id) + WRITE_EVENT(state, EV_ABS, ABS_MT_TRACKING_ID, contact); + + if (state->has_key_btn_touch) + WRITE_EVENT(state, EV_KEY, BTN_TOUCH, 1); + + if (state->has_touch_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_TOUCH_MAJOR, 0x00000006); + + if (state->has_width_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_WIDTH_MAJOR, 0x00000004); + + if (state->has_pressure) + WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, state->contacts[contact].pressure); + + WRITE_EVENT(state, EV_ABS, ABS_X, state->contacts[contact].x); + WRITE_EVENT(state, EV_ABS, ABS_Y, state->contacts[contact].y); + + state->contacts[contact].enabled = 2; + break; + case 2: // MOVED + found_any = 1; + + if (state->has_tracking_id) + WRITE_EVENT(state, EV_ABS, ABS_MT_TRACKING_ID, contact); + + if (state->has_touch_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_TOUCH_MAJOR, 0x00000006); + + if (state->has_width_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_WIDTH_MAJOR, 0x00000004); + + if (state->has_pressure) + WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, state->contacts[contact].pressure); + + WRITE_EVENT(state, EV_ABS, ABS_X, state->contacts[contact].x); + WRITE_EVENT(state, EV_ABS, ABS_Y, state->contacts[contact].y); + + break; + case 3: // WENT_UP + found_any = 1; + + if (state->has_tracking_id) + WRITE_EVENT(state, EV_ABS, ABS_MT_TRACKING_ID, contact); + + if (state->has_key_btn_touch) + WRITE_EVENT(state, EV_KEY, BTN_TOUCH, 0); + + WRITE_EVENT(state, EV_SYN, SYN_MT_REPORT, 0); + + state->contacts[contact].enabled = 0; + break; + } + } + + if (found_any) + WRITE_EVENT(state, EV_SYN, SYN_REPORT, 0); + + return 1; +} + static int type_a_touch_panic_reset_all(internal_state_t* state) { int contact; @@ -368,7 +438,10 @@ static int type_a_touch_panic_reset_all(internal_state_t* state) } } - return type_a_commit(state); + if (state->is_singletouch) + return type_a_single_touch_commit(state); + else + return type_a_multi_touch_commit(state); } static int type_a_touch_down(internal_state_t* state, int contact, int x, int y, int pressure) @@ -442,7 +515,7 @@ static int type_b_touch_panic_reset_all(internal_state_t* state) return found_any ? type_b_commit(state) : 1; } -static int type_b_touch_down(internal_state_t* state, int contact, int x, int y, int pressure) +static int type_b_multi_touch_down(internal_state_t* state, int contact, int x, int y, int pressure) { if (contact >= state->max_contacts) { @@ -473,13 +546,50 @@ static int type_b_touch_down(internal_state_t* state, int contact, int x, int y, if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, x); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, y); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, x); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, y); return 1; } -static int type_b_touch_move(internal_state_t* state, int contact, int x, int y, int pressure) +static int type_b_single_touch_down(internal_state_t* state, int contact, int x, int y, int pressure) +{ + if (contact >= state->max_contacts) + { + return 0; + } + + if (state->contacts[contact].enabled) + { + type_b_touch_panic_reset_all(state); + } + + state->contacts[contact].enabled = 1; + state->contacts[contact].tracking_id = next_tracking_id(state); + + WRITE_EVENT(state, EV_ABS, ABS_MT_SLOT, contact); + WRITE_EVENT(state, EV_ABS, ABS_MT_TRACKING_ID, + state->contacts[contact].tracking_id); + + if (state->has_key_btn_touch) + WRITE_EVENT(state, EV_KEY, BTN_TOUCH, 1); + + if (state->has_touch_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_TOUCH_MAJOR, 0x00000006); + + if (state->has_width_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_WIDTH_MAJOR, 0x00000004); + + if (state->has_pressure) + WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure); + + WRITE_EVENT(state, EV_ABS, ABS_X, x); + WRITE_EVENT(state, EV_ABS, ABS_Y, y); + + return 1; +} + +static int type_b_multi_touch_move(internal_state_t* state, int contact, int x, int y, int pressure) { if (contact >= state->max_contacts || !state->contacts[contact].enabled) { @@ -497,8 +607,32 @@ static int type_b_touch_move(internal_state_t* state, int contact, int x, int y, if (state->has_pressure) WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_x, x); - WRITE_EVENT(state, EV_ABS, state->evcd_mt_y, y); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_X, x); + WRITE_EVENT(state, EV_ABS, ABS_MT_POSITION_Y, y); + + return 1; +} + +static int type_b_single_touch_move(internal_state_t* state, int contact, int x, int y, int pressure) +{ + if (contact >= state->max_contacts || !state->contacts[contact].enabled) + { + return 0; + } + + WRITE_EVENT(state, EV_ABS, ABS_MT_SLOT, contact); + + if (state->has_touch_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_TOUCH_MAJOR, 0x00000006); + + if (state->has_width_major) + WRITE_EVENT(state, EV_ABS, ABS_MT_WIDTH_MAJOR, 0x00000004); + + if (state->has_pressure) + WRITE_EVENT(state, EV_ABS, ABS_MT_PRESSURE, pressure); + + WRITE_EVENT(state, EV_ABS, ABS_X, x); + WRITE_EVENT(state, EV_ABS, ABS_Y, y); return 1; } @@ -525,7 +659,10 @@ static int touch_down(internal_state_t* state, int contact, int x, int y, int pr { if (state->has_mtslot) { - return type_b_touch_down(state, contact, x, y, pressure); + if (state ->is_singletouch) + return type_b_single_touch_down(state, contact, x, y, pressure); + else + return type_b_multi_touch_down(state, contact, x, y, pressure); } else { @@ -537,7 +674,10 @@ static int touch_move(internal_state_t* state, int contact, int x, int y, int pr { if (state->has_mtslot) { - return type_b_touch_move(state, contact, x, y, pressure); + if (state ->is_singletouch) + return type_b_single_touch_move(state, contact, x, y, pressure); + else + return type_b_multi_touch_move(state, contact, x, y, pressure); } else { @@ -577,7 +717,10 @@ static int commit(internal_state_t* state) } else { - return type_a_commit(state); + if (state->is_singletouch) + return type_a_single_touch_commit(state); + else + return type_a_multi_touch_commit(state); } }