Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support single touch event files #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 185 additions & 12 deletions jni/minitouch/minitouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ typedef struct
int has_pressure;
int min_pressure;
int max_pressure;
int is_singletouch;
int max_x;
int max_y;
int max_contacts;
Expand Down Expand Up @@ -83,6 +84,30 @@ 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 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->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->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;
}
}

static int consider_device(const char* devpath, internal_state_t* state)
{
int fd = -1;
Expand All @@ -106,13 +131,16 @@ static int consider_device(const char* devpath, internal_state_t* state)
goto mismatch;
}

if (!is_multitouch_device(evdev))
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);
Expand Down Expand Up @@ -245,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;
Expand Down Expand Up @@ -321,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;
Expand All @@ -337,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)
Expand Down Expand Up @@ -411,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)
{
Expand Down Expand Up @@ -448,7 +552,44 @@ static int type_b_touch_down(internal_state_t* state, int contact, int x, int 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)
{
Expand All @@ -472,6 +613,30 @@ static int type_b_touch_move(internal_state_t* state, int contact, int x, int 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;
}

static int type_b_touch_up(internal_state_t* state, int contact)
{
if (contact >= state->max_contacts || !state->contacts[contact].enabled)
Expand All @@ -494,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
{
Expand All @@ -506,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
{
Expand Down Expand Up @@ -546,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);
}
}

Expand Down Expand Up @@ -649,8 +823,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)
Expand Down