[PATCH evdev 2/7] detection of multitouch devices and adding the "Evdev Tracking ID" property

Benjamin Tissoires tissoire at cena.fr
Sat Dec 19 02:04:24 PST 2009


Signed-off-by: Benjamin Tissoires <tissoire at cena.fr>
---
 src/evdev.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index 7e65c69..470a3f7 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -92,6 +92,7 @@
 #define EVDEV_TABLET		(1 << 8) /* device looks like a tablet? */
 #define EVDEV_UNIGNORE_ABSOLUTE (1 << 9) /* explicitly unignore abs axes */
 #define EVDEV_UNIGNORE_RELATIVE (1 << 10) /* explicitly unignore rel axes */
+#define EVDEV_MULTITOUCH	(1 << 11) /* device looks like a multi-touch screen? */
 
 #define MIN_KEYCODE 8
 #define GLYPHS_PER_KEY 2
@@ -129,6 +130,7 @@ static Atom prop_calibration = 0;
 static Atom prop_swap = 0;
 static Atom prop_axis_label = 0;
 static Atom prop_btn_label = 0;
+static Atom prop_tracking_id = 0;
 #endif
 
 /* All devices the evdev driver has allocated and knows about.
@@ -328,6 +330,8 @@ EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count)
 #define ABS_X_VALUE 0x1
 #define ABS_Y_VALUE 0x2
 #define ABS_VALUE   0x4
+#define ABS_MT_X_VALUE   0x8
+#define ABS_MT_Y_VALUE   0x16
 /**
  * Take the valuators and process them accordingly.
  */
@@ -533,6 +537,10 @@ EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
         pEvdev->abs |= ABS_X_VALUE;
     else if (ev->code == ABS_Y)
         pEvdev->abs |= ABS_Y_VALUE;
+    else if (ev->code == ABS_MT_POSITION_X)
+        pEvdev->abs |= ABS_MT_X_VALUE;
+    else if (ev->code == ABS_MT_POSITION_Y)
+        pEvdev->abs |= ABS_MT_Y_VALUE;
     else
         pEvdev->abs |= ABS_VALUE;
 }
@@ -1464,7 +1472,7 @@ EvdevInit(DeviceIntPtr device)
 
     if (pEvdev->flags & (EVDEV_UNIGNORE_RELATIVE | EVDEV_UNIGNORE_ABSOLUTE))
         EvdevInitAnyClass(device, pEvdev);
-    else if (pEvdev->flags & (EVDEV_TOUCHPAD | EVDEV_TOUCHSCREEN | EVDEV_TABLET))
+    else if (pEvdev->flags & (EVDEV_TOUCHPAD | EVDEV_TOUCHSCREEN | EVDEV_TABLET | EVDEV_MULTITOUCH))
         EvdevInitTouchDevice(device, pEvdev);
     else if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
         EvdevInitRelClass(device, pEvdev);
@@ -1855,6 +1863,15 @@ EvdevProbe(InputInfoPtr pInfo)
                     pEvdev->num_buttons = 7; /* LMR + scroll wheels */
                     pEvdev->flags |= EVDEV_BUTTON_EVENTS;
                 }
+            } else if ((TestBit(ABS_MT_POSITION_X, pEvdev->abs_bitmask) &&
+                        TestBit(ABS_MT_POSITION_Y, pEvdev->abs_bitmask))) {
+                xf86Msg(X_INFO, "%s: Found absolute multitouch tablet.\n", pInfo->name);
+                pEvdev->flags |= EVDEV_MULTITOUCH;
+                if (!pEvdev->num_buttons)
+                {
+                    pEvdev->num_buttons = 7; /* LMR + scroll wheels */
+                    pEvdev->flags |= EVDEV_BUTTON_EVENTS;
+                }
             } else if (TestBit(ABS_PRESSURE, pEvdev->abs_bitmask) ||
                 TestBit(BTN_TOUCH, pEvdev->key_bitmask)) {
                 if (num_buttons || TestBit(BTN_TOOL_FINGER, pEvdev->key_bitmask)) {
@@ -1891,10 +1908,13 @@ EvdevProbe(InputInfoPtr pInfo)
         } else if (pEvdev->flags & EVDEV_TOUCHSCREEN) {
             xf86Msg(X_INFO, "%s: Configuring as touchscreen\n", pInfo->name);
             pInfo->type_name = XI_TOUCHSCREEN;
-	} else {
-	    xf86Msg(X_INFO, "%s: Configuring as mouse\n", pInfo->name);
-	    pInfo->type_name = XI_MOUSE;
-	}
+        } else if (pEvdev->flags & EVDEV_MULTITOUCH) {
+            xf86Msg(X_INFO, "%s: Configuring as multitouch screen\n", pInfo->name);
+            pInfo->type_name = "MULTITOUCHSCREEN";
+        } else {
+            xf86Msg(X_INFO, "%s: Configuring as mouse\n", pInfo->name);
+            pInfo->type_name = XI_MOUSE;
+        }
     }
 
     if (has_keys) {
@@ -2454,6 +2474,19 @@ EvdevInitProperty(DeviceIntPtr dev)
             return;
 
         XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
+        
+        if (pEvdev->flags & EVDEV_MULTITOUCH)
+        {
+            /* tracking ids for mt */
+            prop_tracking_id = MakeAtom(EVDEV_PROP_TRACKING_ID,
+                    strlen(EVDEV_PROP_TRACKING_ID), TRUE);
+            rc = XIChangeDeviceProperty(dev, prop_tracking_id, XA_INTEGER, 32,
+                    PropModeReplace, 1, &pEvdev->id, FALSE);
+            if (rc != Success)
+                return;
+
+            XISetDevicePropertyDeletable(dev, prop_tracking_id, FALSE);
+        }
 
 #ifdef HAVE_LABELS
         /* Axis labelling */
@@ -2516,6 +2549,14 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
             pEvdev->swap_axes = *((BOOL*)val->data);
     } else if (atom == prop_axis_label || atom == prop_btn_label)
         return BadAccess; /* Axis/Button labels can't be changed */
+    else if (atom == prop_tracking_id)
+    {
+        if (val->format != 32 || val->type != XA_INTEGER || val->size != 1)
+            return BadMatch;
+
+        if (!checkonly)
+            pEvdev->id = *((int*)val->data);
+    }
 
     return Success;
 }
-- 
1.6.5.2


--------------090208080606020807080800
Content-Type: text/x-patch;
 name="0003-take-the-tracking-ID-event-into-account.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="0003-take-the-tracking-ID-event-into-account.patch"



More information about the xorg-devel mailing list