[PATCH evdev 4/7] adding to evdev the virtual subdevices that manage the multitouch part

Benjamin Tissoires tissoire at cena.fr
Sat Dec 19 03:20:50 PST 2009


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

diff --git a/src/evdev.c b/src/evdev.c
index bf0b792..fb5c5c9 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -170,6 +170,12 @@ EvdevGetMajorMinor(InputInfoPtr pInfo)
     return st.st_rdev;
 }
 
+static BOOL
+EvdevIsCoreDevice(InputInfoPtr pInfo) {
+    EvdevPtr pEvdev = pInfo->private;
+    return pEvdev->core_device == pInfo;
+}
+
 /**
  * Return TRUE if one of the devices we know about has the same min/maj
  * number.
@@ -722,6 +728,14 @@ EvdevProcessEvent(InputInfoPtr pInfo, struct input_event *ev)
 /* just a magic number to reduce the number of reads */
 #define NUM_EVENTS 16
 
+/**
+ * Empty callback for subdevice.
+ */
+static void
+EvdevSubdevReadInput(InputInfoPtr pInfo) {
+    return;
+}
+
 static void
 EvdevReadInput(InputInfoPtr pInfo)
 {
@@ -1510,6 +1524,27 @@ EvdevInit(DeviceIntPtr device)
 }
 
 /**
+ * For the subdev: Init all extras (wheel emulation, etc.) and grab the device.
+ */
+static int
+EvdevSubdevOn(DeviceIntPtr device)
+{
+    InputInfoPtr pInfo;
+    EvdevPtr pEvdev;
+
+    pInfo = device->public.devicePrivate;
+    pEvdev = pInfo->private;
+
+    xf86AddEnabledDevice(pInfo);
+    EvdevMBEmuOn(pInfo);
+    pEvdev->flags |= EVDEV_INITIALIZED;
+    device->public.on = TRUE;
+
+    return Success;
+}
+
+
+/**
  * Init all extras (wheel emulation, etc.) and grab the device.
  */
 static int
@@ -1572,19 +1607,41 @@ EvdevProc(DeviceIntPtr device, int what)
 	return EvdevInit(device);
 
     case DEVICE_ON:
-        return EvdevOn(device);
+        if (EvdevIsCoreDevice(pInfo))
+            return EvdevOn(device);
+        else
+            return EvdevSubdevOn(device);
 
     case DEVICE_OFF:
         if (pEvdev->flags & EVDEV_INITIALIZED)
             EvdevMBEmuFinalize(pInfo);
-        if (pInfo->fd != -1)
-        {
-            if (pEvdev->grabDevice && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
-                xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
-                        strerror(errno));
+        if (EvdevIsCoreDevice(pInfo)){
+            if (pInfo->fd != -1)
+            {
+                if (pEvdev->grabDevice && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
+                    xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
+                            strerror(errno));
+                xf86RemoveEnabledDevice(pInfo);
+                close(pInfo->fd);
+                pInfo->fd = -1;
+            }
+            if (pEvdev->subdevice_timer)
+            {
+                TimerFree(pEvdev->subdevice_timer);
+                pEvdev->subdevice_timer = NULL;
+            }
+        } else {
+            /* subdevice: removing it in the list of the core device */
+            EvdevPtr g_pEvdev;
+            int i;
+            g_pEvdev = pEvdev->core_device->private;
+            for (i=0; i<MAX_VALUATORS_MT; ++i) {
+                if (g_pEvdev->vals_mt[i].pInfo == pInfo) {
+                    g_pEvdev->vals_mt[i].pInfo = NULL;
+                    break;
+                }
+            }
             xf86RemoveEnabledDevice(pInfo);
-            close(pInfo->fd);
-            pInfo->fd = -1;
         }
         pEvdev->min_maj = 0;
         pEvdev->flags &= ~EVDEV_INITIALIZED;
@@ -1593,11 +1650,13 @@ EvdevProc(DeviceIntPtr device, int what)
 
     case DEVICE_CLOSE:
 	xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
+    if (EvdevIsCoreDevice(pInfo)) { // core mt only
         if (pInfo->fd != -1) {
             close(pInfo->fd);
             pInfo->fd = -1;
         }
         EvdevRemoveDevice(pInfo);
+    }
         pEvdev->min_maj = 0;
 	break;
     }
@@ -1983,16 +2042,66 @@ EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4])
 }
 
 static InputInfoPtr
+EvdevSubdevPreInit(InputInfoPtr pInfo, InputDriverPtr drv, IDevPtr dev, int flags)
+{
+    EvdevPtr pEvdev;
+
+    /* Initialise the InputInfoRec. */
+    pInfo->name = dev->identifier;
+    pInfo->flags = 0;
+    pInfo->type_name = "UNKNOWN";
+    pInfo->device_control = EvdevProc;
+    pInfo->history_size = 0;
+    pInfo->control_proc = NULL;
+    pInfo->close_proc = NULL;
+    pInfo->read_input = EvdevSubdevReadInput;
+    pInfo->switch_mode = NULL;
+    pInfo->conversion_proc = NULL;
+    pInfo->reverse_conversion_proc = NULL;
+    pInfo->dev = NULL;
+    pInfo->private_flags = 0;
+    pInfo->always_core_feedback = NULL;
+    pInfo->conf_idev = dev;
+
+    if (!(pEvdev = xcalloc(sizeof(EvdevRec), 1)))
+        return pInfo;
+
+    pInfo->private = pEvdev;
+
+    xf86CollectInputOptions(pInfo, evdevDefaults, NULL);
+    xf86ProcessCommonOptions(pInfo, pInfo->options);
+    pEvdev->id = -1;
+    
+    xf86Msg(X_INFO, "%s: Evdev subdevice found\n", dev->identifier);
+    // FIXME: need to duplicate the parent device
+
+    pInfo->flags |= XI86_CONFIGURED;
+    pEvdev->num_multitouch = 1;
+    
+    return pInfo;
+}
+
+static InputInfoPtr
 EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
 {
     InputInfoPtr pInfo;
     const char *device, *str;
     int num_calibration = 0, calibration[4] = { 0, 0, 0, 0 };
     EvdevPtr pEvdev;
+    char *type;
 
     if (!(pInfo = xf86AllocateInput(drv, 0)))
 	return NULL;
 
+    /* If Type == Object, this is a subdevice for an object to use */
+    type = xf86CheckStrOption(dev->commonOptions, "Type", NULL);
+
+    xf86Msg(X_INFO, "%s: Evdev Type %s found\n", dev->identifier,type);
+       
+    if (type != NULL && strcmp(type, "Object") == 0) {
+        return EvdevSubdevPreInit(pInfo, drv, dev, flags);
+    }
+   
     /* Initialise the InputInfoRec. */
     pInfo->name = dev->identifier;
     pInfo->flags = 0;
@@ -2017,6 +2126,10 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
 
     xf86CollectInputOptions(pInfo, evdevDefaults, NULL);
     xf86ProcessCommonOptions(pInfo, pInfo->options);
+    
+    /* mt initializations. */
+    pEvdev->id = -1;
+    pEvdev->core_device = pInfo;
 
     /*
      * We initialize pEvdev->tool to 1 so that device that doesn't use
@@ -2077,6 +2190,15 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
        Note that this needs a server that sets the console to RAW mode. */
     pEvdev->grabDevice = xf86CheckBoolOption(dev->commonOptions, "GrabDevice", 0);
 
+    /* Get setting for checking wether a touch is still alive */
+    pEvdev->timeout = xf86CheckIntOption(dev->commonOptions,
+            "SubdevTimeout", DEFAULT_MT_TIMEOUT);
+    if (pEvdev->timeout < 1) {
+        pEvdev->timeout = 1;
+    }
+    xf86Msg(X_INFO, "%s: SubdevTimeout set to %d\n",
+            dev->identifier, (int)pEvdev->timeout);
+
     EvdevInitButtonMapping(pInfo);
 
     if (EvdevCacheCompare(pInfo, FALSE) ||
-- 
1.6.5.2


--------------090208080606020807080800
Content-Type: text/x-patch;
 name="0005-Handling-the-creation-destruction-of-mt-subdevices-b.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename*0="0005-Handling-the-creation-destruction-of-mt-subdevices-b.pa";
 filename*1="tch"



More information about the xorg-devel mailing list