Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #300 from spiiroin/jb30661_touch_detect
Improve touch detection logic used in blanking policy handling
  • Loading branch information
spiiroin committed Jul 28, 2015
2 parents d4e5d62 + 1e20462 commit 7ee85ec
Showing 1 changed file with 58 additions and 43 deletions.
101 changes: 58 additions & 43 deletions tklock.c
Expand Up @@ -1845,75 +1845,90 @@ static void tklock_datapipe_lens_cover_cb(gconstpointer data)
return;
}

/** Handle user_activity_pipe notifications
/** Check if event relates to ongoing user activity on screen
*
* @param data input_event as void pointer
* Detect touch screen events that signify finger on screen
* situation.
*
* To make things work in SDK do mouse click detection too.
*/
static void tklock_datapipe_user_activity_cb(gconstpointer data)
static bool tklock_touch_activity_event_p(const struct input_event *ev)
{
static int64_t last_time = 0;

const struct input_event *ev = data;

if( !ev )
goto EXIT;

/* Deal with autorelock cancellation 1st */
if( autorelock_trigger != AUTORELOCK_NO_TRIGGERS ) {
switch( ev->type ) {
case EV_SYN:
break;
bool activity = false;

case EV_ABS:
switch( ev->code ) {
case ABS_MT_POSITION_X:
case ABS_MT_POSITION_Y:
case ABS_MT_PRESSURE:
mce_log(LL_DEBUG, "autorelock canceled: touch activity");
autorelock_trigger = AUTORELOCK_NO_TRIGGERS;
break;
default:
break;
}
switch( ev->type ) {
case EV_KEY:
switch( ev->code ) {
case BTN_MOUSE:
activity = (ev->value != 0);
break;

default:
case BTN_TOUCH:
activity = (ev->value != 0);
break;
}
}

/* Touch events relevant unly when handling notification & linger */
if( !(exception_state & (UIEXC_NOTIF | UIEXC_LINGER)) )
goto EXIT;

bool touched = false;
switch( ev->type ) {
case EV_SYN:
switch( ev->code ) {
case SYN_MT_REPORT:
touched = true;
break;
default:
break;
}
break;

case EV_ABS:
switch( ev->code ) {
case ABS_MT_PRESSURE:
case ABS_MT_POSITION_X:
case ABS_MT_POSITION_Y:
case ABS_MT_PRESSURE:
touched = true;
activity = true;
break;

case ABS_MT_TOUCH_MAJOR:
activity = (ev->value != 0);
break;

case ABS_MT_WIDTH_MAJOR:
activity = (ev->value > 0);
break;

case ABS_MT_TRACKING_ID:
activity = (ev->value != -1);
break;

default:
break;
}
break;

default:
break;
}

if( !touched )
return activity;
}

/** Handle user_activity_pipe notifications
*
* @param data input_event as void pointer
*/
static void tklock_datapipe_user_activity_cb(gconstpointer data)
{
static int64_t last_time = 0;

const struct input_event *ev = data;

if( !ev )
goto EXIT;

/* We are only interested in touch activity */
if( !tklock_touch_activity_event_p(ev) )
goto EXIT;

/* Deal with autorelock cancellation 1st */
if( autorelock_trigger != AUTORELOCK_NO_TRIGGERS ) {
mce_log(LL_DEBUG, "autorelock canceled: touch activity");
autorelock_trigger = AUTORELOCK_NO_TRIGGERS;
}

/* Touch events relevant unly when handling notification & linger */
if( !(exception_state & (UIEXC_NOTIF | UIEXC_LINGER)) )
goto EXIT;

int64_t now = tklock_monotick_get();
Expand Down

0 comments on commit 7ee85ec

Please sign in to comment.