Patchwork HID: magicmouse: report last touch up

login
register
mail settings
Submitter Chase Douglas
Date July 12, 2010, 2:31 p.m.
Message ID <1278945096-5141-1-git-send-email-chase.douglas@canonical.com>
Download mbox | patch
Permalink /patch/58615/
State Accepted
Delegated to: Leann Ogasawara
Headers show

Comments

Chase Douglas - July 12, 2010, 2:31 p.m.
HID: magicmouse: report last touch up

The evdev multitouch protocol requires that a last MT sync event must be
sent after all touches are up. This change adds the last MT sync event
to the hid-magicmouse driver.

Also, don't send events when a touch leaves.

Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
Acked-by: Michael Poole <mdpoole@troilus.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
(cherry picked from commit e3612e8669b8c15278058f8dd52e3dc6e7d26710
from git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git)
---
Henrik Rydberg - July 12, 2010, 5:23 p.m.
Chase Douglas wrote:
> HID: magicmouse: report last touch up
> 
> The evdev multitouch protocol requires that a last MT sync event must be
> sent after all touches are up. This change adds the last MT sync event
> to the hid-magicmouse driver.
> 
> Also, don't send events when a touch leaves.

Perhaps "evdev" should read "kernel" in the log text, and "must require" looks
pleonastic to me. ;-) Otherwise, the patch look good.

Henrik

> 
> Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
> Acked-by: Michael Poole <mdpoole@troilus.org>
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> (cherry picked from commit e3612e8669b8c15278058f8dd52e3dc6e7d26710
> from git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git)
> ---
> 
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index 0b89c1c..ee78787 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -98,6 +98,7 @@ struct magicmouse_sc {
>  		short scroll_x;
>  		short scroll_y;
>  		u8 size;
> +		u8 down;
>  	} touches[16];
>  	int tracking_ids[16];
>  };
> @@ -170,6 +171,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
>  	int id = (misc >> 6) & 15;
>  	int x = x_y << 12 >> 20;
>  	int y = -(x_y >> 20);
> +	int down = (tdata[7] & TOUCH_STATE_MASK) != TOUCH_STATE_NONE;
>  
>  	/* Store tracking ID and other fields. */
>  	msc->tracking_ids[raw_id] = id;
> @@ -221,9 +223,11 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
>  	}
>  
>  	/* Generate the input events for this touch. */
> -	if (report_touches) {
> +	if (report_touches && down) {
>  		int orientation = (misc >> 10) - 32;
>  
> +		msc->touches[id].down = 1;
> +
>  		input_report_abs(input, ABS_MT_TRACKING_ID, id);
>  		input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]);
>  		input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]);
> @@ -243,7 +247,7 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>  {
>  	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
>  	struct input_dev *input = msc->input;
> -	int x, y, ts, ii, clicks;
> +	int x, y, ts, ii, clicks, last_up;
>  
>  	switch (data[0]) {
>  	case 0x10:
> @@ -263,6 +267,20 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>  		msc->ntouches = (size - 6) / 8;
>  		for (ii = 0; ii < msc->ntouches; ii++)
>  			magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
> +
> +		if (report_touches) {
> +			last_up = 1;
> +			for (ii = 0; ii < ARRAY_SIZE(msc->touches); ii++) {
> +				if (msc->touches[ii].down) {
> +					last_up = 0;
> +					msc->touches[ii].down = 0;
> +				}
> +			}
> +			if (last_up) {
> +				input_mt_sync(input);
> +			}
> +		}
> +
>  		/* When emulating three-button mode, it is important
>  		 * to have the current touch information before
>  		 * generating a click event.
>
Leann Ogasawara - July 13, 2010, 5:18 p.m.
Applied to Maverick linux master.

Thanks,
Leann

On Mon, 2010-07-12 at 10:31 -0400, Chase Douglas wrote:
> HID: magicmouse: report last touch up
> 
> The evdev multitouch protocol requires that a last MT sync event must be
> sent after all touches are up. This change adds the last MT sync event
> to the hid-magicmouse driver.
> 
> Also, don't send events when a touch leaves.
> 
> Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
> Acked-by: Michael Poole <mdpoole@troilus.org>
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> (cherry picked from commit e3612e8669b8c15278058f8dd52e3dc6e7d26710
> from git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git)
> ---
> 
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index 0b89c1c..ee78787 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -98,6 +98,7 @@ struct magicmouse_sc {
>  		short scroll_x;
>  		short scroll_y;
>  		u8 size;
> +		u8 down;
>  	} touches[16];
>  	int tracking_ids[16];
>  };
> @@ -170,6 +171,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
>  	int id = (misc >> 6) & 15;
>  	int x = x_y << 12 >> 20;
>  	int y = -(x_y >> 20);
> +	int down = (tdata[7] & TOUCH_STATE_MASK) != TOUCH_STATE_NONE;
>  
>  	/* Store tracking ID and other fields. */
>  	msc->tracking_ids[raw_id] = id;
> @@ -221,9 +223,11 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
>  	}
>  
>  	/* Generate the input events for this touch. */
> -	if (report_touches) {
> +	if (report_touches && down) {
>  		int orientation = (misc >> 10) - 32;
>  
> +		msc->touches[id].down = 1;
> +
>  		input_report_abs(input, ABS_MT_TRACKING_ID, id);
>  		input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]);
>  		input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]);
> @@ -243,7 +247,7 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>  {
>  	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
>  	struct input_dev *input = msc->input;
> -	int x, y, ts, ii, clicks;
> +	int x, y, ts, ii, clicks, last_up;
>  
>  	switch (data[0]) {
>  	case 0x10:
> @@ -263,6 +267,20 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>  		msc->ntouches = (size - 6) / 8;
>  		for (ii = 0; ii < msc->ntouches; ii++)
>  			magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
> +
> +		if (report_touches) {
> +			last_up = 1;
> +			for (ii = 0; ii < ARRAY_SIZE(msc->touches); ii++) {
> +				if (msc->touches[ii].down) {
> +					last_up = 0;
> +					msc->touches[ii].down = 0;
> +				}
> +			}
> +			if (last_up) {
> +				input_mt_sync(input);
> +			}
> +		}
> +
>  		/* When emulating three-button mode, it is important
>  		 * to have the current touch information before
>  		 * generating a click event.
>

Patch

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 0b89c1c..ee78787 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -98,6 +98,7 @@  struct magicmouse_sc {
 		short scroll_x;
 		short scroll_y;
 		u8 size;
+		u8 down;
 	} touches[16];
 	int tracking_ids[16];
 };
@@ -170,6 +171,7 @@  static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
 	int id = (misc >> 6) & 15;
 	int x = x_y << 12 >> 20;
 	int y = -(x_y >> 20);
+	int down = (tdata[7] & TOUCH_STATE_MASK) != TOUCH_STATE_NONE;
 
 	/* Store tracking ID and other fields. */
 	msc->tracking_ids[raw_id] = id;
@@ -221,9 +223,11 @@  static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
 	}
 
 	/* Generate the input events for this touch. */
-	if (report_touches) {
+	if (report_touches && down) {
 		int orientation = (misc >> 10) - 32;
 
+		msc->touches[id].down = 1;
+
 		input_report_abs(input, ABS_MT_TRACKING_ID, id);
 		input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]);
 		input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]);
@@ -243,7 +247,7 @@  static int magicmouse_raw_event(struct hid_device *hdev,
 {
 	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
 	struct input_dev *input = msc->input;
-	int x, y, ts, ii, clicks;
+	int x, y, ts, ii, clicks, last_up;
 
 	switch (data[0]) {
 	case 0x10:
@@ -263,6 +267,20 @@  static int magicmouse_raw_event(struct hid_device *hdev,
 		msc->ntouches = (size - 6) / 8;
 		for (ii = 0; ii < msc->ntouches; ii++)
 			magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
+
+		if (report_touches) {
+			last_up = 1;
+			for (ii = 0; ii < ARRAY_SIZE(msc->touches); ii++) {
+				if (msc->touches[ii].down) {
+					last_up = 0;
+					msc->touches[ii].down = 0;
+				}
+			}
+			if (last_up) {
+				input_mt_sync(input);
+			}
+		}
+
 		/* When emulating three-button mode, it is important
 		 * to have the current touch information before
 		 * generating a click event.