linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ed Tomlinson <edt@aei.ca>
To: Jiri Kosina <jkosina@suse.cz>
Cc: Michael Poole <mdpoole@troilus.org>,
	linux-input@vger.kernel.org,
	Marcel Holtmann <marcel@holtmann.org>,
	linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] Enable xy scrolling for Apple Magic Mouse
Date: Sun, 14 Feb 2010 17:24:32 -0500	[thread overview]
Message-ID: <201002141724.33223.edt@aei.ca> (raw)
In-Reply-To: <alpine.LNX.2.00.1002101456490.30967@pobox.suse.cz>

Hi,

Here is a patch that enables xy scrolling with the magic mouse.  I have also
changed the accelleration logic to work better with xy scrolling.

Comments
Ed Tomlinson

---
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b20484a..3075d78 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -59,7 +59,7 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
  * @delta_time: 18-bit difference between the two most recent touch
  *     reports from the mouse.
  * @ntouches: Number of touches in most recent touch report.
- * @scroll_accel: Number of consecutive scroll motions.
+ * @scroll_accely: Number of consecutive scroll motions.
  * @scroll_jiffies: Time of last scroll motion.
  * @touches: Most recent data for a touch, indexed by tracking ID.
  * @tracking_ids: Mapping of current touch input data to @touches.
@@ -71,11 +71,13 @@ struct magicmouse_sc {
 	int last_timestamp;
 	int delta_time;
 	int ntouches;
-	int scroll_accel;
+	int scroll_accely;
+	int scroll_accelx;
 	unsigned long scroll_jiffies;
 
 	struct {
 		short x;
+		short scroll_x;
 		short y;
 		short scroll_y;
 		u8 size;
@@ -139,8 +141,10 @@ static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
 	input_report_key(msc->input, BTN_LEFT, state & 1);
 	input_report_key(msc->input, BTN_RIGHT, state & 2);
 
-	if (state != last_state)
-		msc->scroll_accel = 0;
+	if (state != last_state) {
+		msc->scroll_accely = 0;
+		msc->scroll_accelx = 0;
+	}
 }
 
 static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
@@ -159,34 +163,46 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
 	msc->touches[id].size = misc & 63;
 
 	/* If requested, emulate a scroll wheel by detecting small
-	 * vertical touch motions along the middle of the mouse.
+	 * touch motions on the mouse.
 	 */
 	if (emulate_scroll_wheel &&
-	    middle_button_start < x && x < middle_button_stop) {
+	    msc->ntouches == 1) {
 		static const int accel_profile[] = {
-			256, 228, 192, 160, 128, 96, 64, 32,
+			192, 160, 128, 96, 64, 48, 32, 24,
 		};
 		unsigned long now = jiffies;
-		int step = msc->touches[id].scroll_y - y;
+		int stepx, stepy;
 
 		/* Reset acceleration after half a second. */
-		if (time_after(now, msc->scroll_jiffies + HZ / 2))
-			msc->scroll_accel = 0;
+		if (time_after(now, msc->scroll_jiffies + HZ / 2)) {
+			msc->scroll_accely = 0;
+			msc->scroll_accelx = 0;
+		}
 
-		/* Calculate and apply the scroll motion. */
 		switch (tdata[7] & TOUCH_STATE_MASK) {
 		case TOUCH_STATE_START:
 			msc->touches[id].scroll_y = y;
-			msc->scroll_accel = min_t(int, msc->scroll_accel + 1,
-						ARRAY_SIZE(accel_profile) - 1);
+			msc->touches[id].scroll_x = x;
 			break;
 		case TOUCH_STATE_DRAG:
-			step = step / accel_profile[msc->scroll_accel];
-			if (step != 0) {
+			/* Calculate and apply the scroll motion. */
+			stepy = (msc->touches[id].scroll_y - y)/accel_profile[msc->scroll_accely];
+			stepx = (msc->touches[id].scroll_x - x)/accel_profile[msc->scroll_accelx];
+
+			/* tell input about any motions */
+			if (stepy != 0) {
 				msc->touches[id].scroll_y = y;
-				msc->scroll_jiffies = now;
-				input_report_rel(input, REL_WHEEL, step);
+				input_report_rel(input, REL_WHEEL, stepy);
+				msc->scroll_accely = min_t(int, msc->scroll_accely + 1,
+							        ARRAY_SIZE(accel_profile) - 1);
 			}
+			if (stepx != 0) {
+				msc->touches[id].scroll_x = x;
+				input_report_rel(input, REL_HWHEEL, stepx);
+				msc->scroll_accelx = min_t(int, msc->scroll_accelx + 1,
+							        ARRAY_SIZE(accel_profile) - 1);
+			}
+			msc->scroll_jiffies = now;
 			break;
 		}
 	}
@@ -300,8 +316,10 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h
 	__set_bit(EV_REL, input->evbit);
 	__set_bit(REL_X, input->relbit);
 	__set_bit(REL_Y, input->relbit);
-	if (emulate_scroll_wheel)
+	if (emulate_scroll_wheel) {
 		__set_bit(REL_WHEEL, input->relbit);
+		__set_bit(REL_HWHEEL, input->relbit);
+	}
 
 	if (report_touches) {
 		__set_bit(EV_ABS, input->evbit);

  parent reply	other threads:[~2010-02-14 22:24 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-29 14:20 [PATCH 0/3] HID: make raw output callback more flexible Jiri Kosina
2010-01-29 14:20 ` [PATCH 1/3] HID: make raw reports possible for both feature and output reports Jiri Kosina
2010-01-29 14:20 ` [PATCH 2/3] HID: Implement Wacom quirk in the kernel Jiri Kosina
2010-01-29 17:14   ` Ping Cheng
2010-02-03 14:50     ` Jiri Kosina
2010-01-29 14:21 ` [PATCH 3/3] HID: Enable Sixaxis controller over Bluetooth Jiri Kosina
2010-01-29 16:39 ` [PATCH 0/3] HID: make raw output callback more flexible Bastien Nocera
2010-01-30  0:46   ` Michael Poole
2010-01-30 14:11     ` Bastien Nocera
2010-01-31  3:27       ` Michael Poole
2010-02-03  1:25       ` Michael Poole
2010-02-03  9:47         ` Bastien Nocera
     [not found]           ` <alpine.LNX.2.00.1002031202040.15395@pobox.suse.cz>
2010-02-03 12:48             ` Jiri Kosina
2010-02-03 12:49               ` [PATCH 1/3] HID: make raw reports possible for both feature and output reports Jiri Kosina
2010-02-03 14:14                 ` Marcel Holtmann
2010-02-03 14:37                   ` Jiri Kosina
2010-02-03 12:49               ` [PATCH 2/3] HID: Implement Wacom quirk in the kernel Jiri Kosina
2010-02-03 14:19                 ` Marcel Holtmann
2010-02-03 14:40                   ` Jiri Kosina
2010-02-03 12:50               ` [PATCH 3/3] HID: Enable Sixaxis controller over Bluetooth Jiri Kosina
2010-02-03 14:17                 ` Marcel Holtmann
2010-02-03 14:42                   ` Jiri Kosina
2010-02-04 12:26       ` [PATCH] Bluetooth: Keep a copy of each HID device's report descriptor Michael Poole
2010-02-04 14:23         ` Marcel Holtmann
2010-02-05 17:23           ` Michael Poole
2010-02-05 17:51             ` Marcel Holtmann
2010-02-09  2:06               ` Ed Tomlinson
2010-02-09  7:22                 ` Justin Mattock
2010-02-09 10:14                   ` Bastien Nocera
2010-02-09 12:36                     ` Ed Tomlinson
2010-02-09 12:40                       ` Jiri Kosina
2010-02-09 13:10                         ` [PATCH 0/2] Provide a driver for the Apple Magic Mouse Michael Poole
2010-02-09 13:11                           ` [PATCH 1/2] " Michael Poole
2010-02-09 13:13                           ` [PATCH 2/2] Add a device " Michael Poole
2010-02-10 13:06                             ` Jiri Kosina
2010-02-10 13:58                               ` Jiri Kosina
2010-02-10 18:20                             ` Dmitry Torokhov
2010-02-10 20:31                               ` Michael Poole
2010-02-11  5:32                               ` [PATCH] hid-magicmouse: Coding style and probe failure fixes Michael Poole
2010-02-11  6:55                                 ` Dmitry Torokhov
2010-02-11 10:26                                 ` Jiri Kosina
2010-02-11 23:10                                   ` Michael Poole
2010-02-11  3:05                             ` [PATCH 2/2] Add a device driver for the Apple Magic Mouse Ed Tomlinson
2010-02-11  3:20                               ` Michael Poole
2010-02-11 12:51                                 ` [PATCH 2/2] Add a device driver for the Apple Magic Mouse (2.6.32.8) Ed Tomlinson
2010-02-09 21:37                           ` [PATCH 0/2] Provide a driver for the Apple Magic Mouse Justin P. Mattock
2010-02-10 13:57                           ` Jiri Kosina
2010-02-13 19:29                             ` [PATCH 0/2] Provide a driver for the Apple Magic Mouse - opps Ed Tomlinson
2010-02-14  8:03                               ` Dmitry Torokhov
2010-02-14 14:22                                 ` Ed Tomlinson
2010-02-15  7:11                                   ` Dmitry Torokhov
2010-02-15 12:42                                     ` Ed Tomlinson
2010-02-15 12:44                                     ` Ed Tomlinson
2010-02-16 12:57                                       ` Jiri Kosina
2010-02-16 12:34                                     ` Ed Tomlinson
2010-02-16 12:55                                       ` Jiri Kosina
2010-02-14 22:24                             ` Ed Tomlinson [this message]
2010-02-14 22:51                               ` [PATCH 1/1] Enable xy scrolling for Apple Magic Mouse Michael Poole
2010-02-14 23:58                                 ` Ed Tomlinson
2010-02-15  7:18                                   ` Dmitry Torokhov
2010-02-15 12:50                                     ` Ed Tomlinson
2010-02-15  0:18                                 ` Ed Tomlinson
2010-02-09 15:03                     ` [PATCH] Bluetooth: Keep a copy of each HID device's report descriptor Justin P. Mattock
2010-02-05 12:49         ` Bastien Nocera
2010-02-05 13:27           ` Marcel Holtmann
2010-01-30 14:13 ` [PATCH 0/3] HID: make raw output callback more flexible Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201002141724.33223.edt@aei.ca \
    --to=edt@aei.ca \
    --cc=jkosina@suse.cz \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=mdpoole@troilus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).