From patchwork Wed Sep 1 11:22:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 63368 X-Patchwork-Delegate: leann.ogasawara@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id C9069B712C for ; Wed, 1 Sep 2010 21:23:15 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1OqlPK-0004KO-Ad; Wed, 01 Sep 2010 12:23:10 +0100 Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1OqlPI-0004JK-20 for kernel-team@lists.ubuntu.com; Wed, 01 Sep 2010 12:23:08 +0100 Received: from c83-248-196-134.bredband.comhem.se ([83.248.196.134]:37031 helo=alnilam) by ch-smtp02.sth.basefarm.net with smtp (Exim 4.68) (envelope-from ) id 1OqlP2-0000TK-6x; Wed, 01 Sep 2010 13:22:55 +0200 Received: by alnilam (sSMTP sendmail emulation); Wed, 01 Sep 2010 13:22:51 +0200 From: "Henrik Rydberg" To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/5] hid: 3m: Correct touchscreen emulation Date: Wed, 1 Sep 2010 13:22:23 +0200 Message-Id: <1283340144-18695-5-git-send-email-rydberg@euromail.se> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1283340144-18695-1-git-send-email-rydberg@euromail.se> References: <1283340144-18695-1-git-send-email-rydberg@euromail.se> X-Originating-IP: 83.248.196.134 X-Scan-Result: No virus found in message 1OqlP2-0000TK-6x. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1OqlP2-0000TK-6x be157d730113a6c84d3ca375721a80b4 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com The current code sometimes misses to report the last BTN_TOUCH event when multiple fingers are lifted simultaneously. With the introduction of MT slots, the tracking id is available to determine the oldest active contact. Use this information to simplify and correct the touchscreen emulation logic. Signed-off-by: Henrik Rydberg --- drivers/hid/hid-3m-pct.c | 41 +++++------------------------------------ 1 files changed, 5 insertions(+), 36 deletions(-) diff --git a/drivers/hid/hid-3m-pct.c b/drivers/hid/hid-3m-pct.c index 9a3b047..65441e0 100644 --- a/drivers/hid/hid-3m-pct.c +++ b/drivers/hid/hid-3m-pct.c @@ -33,7 +33,6 @@ MODULE_LICENSE("GPL"); struct mmm_finger { __s32 x, y, w, h; __u16 id; - __u8 rank; bool prev_touch; bool touch, valid; }; @@ -41,7 +40,7 @@ struct mmm_finger { struct mmm_data { struct mmm_finger f[MAX_SLOTS]; __u16 id; - __u8 curid, num; + __u8 curid; __u8 nexp, nreal; bool touch, valid; }; @@ -152,13 +151,7 @@ static int mmm_input_mapped(struct hid_device *hdev, struct hid_input *hi, static void mmm_filter_event(struct mmm_data *md, struct input_dev *input) { struct mmm_finger *oldest = 0; - bool pressed = false, released = false; int i; - - /* - * we need to iterate on all fingers to decide if we have a press - * or a release event in our touchscreen emulation. - */ for (i = 0; i < MAX_SLOTS; ++i) { struct mmm_finger *f = &md->f[i]; if (!f->valid) { @@ -179,34 +172,11 @@ static void mmm_filter_event(struct mmm_data *md, struct input_dev *input) wide ? f->w : f->h); input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, wide ? f->h : f->w); - /* - * touchscreen emulation: maintain the age rank - * of this finger, decide if we have a press - */ - if (f->rank == 0) { - f->rank = ++(md->num); - if (f->rank == 1) - pressed = true; - } - if (f->rank == 1) + /* touchscreen emulation: pick the oldest contact */ + if (!oldest || ((f->id - oldest->id) & (SHRT_MAX + 1))) oldest = f; } else { /* this finger took off the screen */ - /* touchscreen emulation: maintain age rank of others */ - int j; - - for (j = 0; j < 10; ++j) { - struct mmm_finger *g = &md->f[j]; - if (g->rank > f->rank) { - g->rank--; - if (g->rank == 1) - oldest = g; - } - } - f->rank = 0; - --(md->num); - if (md->num == 0) - released = true; input_event(input, EV_ABS, ABS_MT_TRACKING_ID, -1); } f->prev_touch = f->touch; @@ -215,11 +185,10 @@ static void mmm_filter_event(struct mmm_data *md, struct input_dev *input) /* touchscreen emulation */ if (oldest) { - if (pressed) - input_event(input, EV_KEY, BTN_TOUCH, 1); + input_event(input, EV_KEY, BTN_TOUCH, 1); input_event(input, EV_ABS, ABS_X, oldest->x); input_event(input, EV_ABS, ABS_Y, oldest->y); - } else if (released) { + } else { input_event(input, EV_KEY, BTN_TOUCH, 0); } input_sync(input);