[PATCH 1/2] allow wheel emulation to work with absolute-position devices

Dima Kogan dkogan at cds.caltech.edu
Sat Dec 5 02:05:19 PST 2009


Signed-off-by: Dima Kogan <dkogan at cds.caltech.edu>
---
 src/emuWheel.c |   61 +++++++++++++++++++++++++++++++++++++++----------------
 src/evdev.c    |    3 ++
 2 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/src/emuWheel.c b/src/emuWheel.c
index e7b2f98..3105522 100644
--- a/src/emuWheel.c
+++ b/src/emuWheel.c
@@ -100,6 +100,7 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
     EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
     WheelAxisPtr pAxis = NULL, pOtherAxis = NULL;
     int value = pEv->value;
+    int oldValue;
 
     /* Has wheel emulation been configured to be enabled? */
     if (!pEvdev->emulateWheel.enabled)
@@ -118,25 +119,49 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
         }
 
 	/* We don't want to intercept real mouse wheel events */
-	switch(pEv->code) {
-	case REL_X:
-	    pAxis = &(pEvdev->emulateWheel.X);
-	    pOtherAxis = &(pEvdev->emulateWheel.Y);
-	    break;
-
-	case REL_Y:
-	    pAxis = &(pEvdev->emulateWheel.Y);
-	    pOtherAxis = &(pEvdev->emulateWheel.X);
-	    break;
-
-	default:
-	    break;
-	}
+        /* REL_X and ABS_X have the same values, so we need a switch inside
+           an if, instead of a single switch */
+        if(pEv->type == EV_REL) {
+            switch(pEv->code) {
+            case REL_X:
+                pAxis = &(pEvdev->emulateWheel.X);
+                pOtherAxis = &(pEvdev->emulateWheel.Y);
+                break;
+
+            case REL_Y:
+                pAxis = &(pEvdev->emulateWheel.Y);
+                pOtherAxis = &(pEvdev->emulateWheel.X);
+                break;
+
+            default:
+                break;
+            }
+        } else if(pEv->type == EV_ABS) {
+            oldValue = pEvdev->vals[pEvdev->axis_map[pEv->code]];
+            pEvdev->vals[pEvdev->axis_map[pEv->code]] = value;
+            value -= oldValue; // make value into a differential measurement
+
+            switch(pEv->code) {
+            case ABS_X:
+                pAxis = &(pEvdev->emulateWheel.X);
+                pOtherAxis = &(pEvdev->emulateWheel.Y);
+                break;
+
+            case ABS_Y:
+                pAxis = &(pEvdev->emulateWheel.Y);
+                pOtherAxis = &(pEvdev->emulateWheel.X);
+                break;
+
+            default:
+                break;
+            }
+
+        }
 
-	/* If we found REL_X or REL_Y, emulate a mouse wheel.
-           Reset the inertia of the other axis when a scroll event was sent
-           to avoid the buildup of erroneous scroll events if the user
-           doesn't move in a perfectly straight line.
+	/* If we found REL_X, REL_Y, ABS_X or ABS_Y then emulate a mouse
+           wheel.  Reset the inertia of the other axis when a scroll event
+           was sent to avoid the buildup of erroneous scroll events if the
+           user doesn't move in a perfectly straight line.
          */
 	if (pAxis)
 	{
diff --git a/src/evdev.c b/src/evdev.c
index 81a0bd5..1e0f9e2 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -524,6 +524,9 @@ EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
     if (ev->code > ABS_MAX)
         return;
 
+    if (EvdevWheelEmuFilterMotion(pInfo, ev))
+        return;
+
     pEvdev->vals[pEvdev->axis_map[ev->code]] = value;
     if (ev->code == ABS_X)
         pEvdev->abs |= ABS_X_VALUE;
-- 
1.6.5.2


--MP_/ZFPn_eZqKh+9G1.WysCdnQ2
Content-Type: text/x-patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename=0002-removed-unnecessary-static-declarations.patch



More information about the xorg-devel mailing list