Update: [PATCH 6/6] xserver: input device id counter fix

Magnus Vigerlöf Magnus.Vigerlof at home.se
Sat Mar 31 01:50:06 PDT 2007


Input device id counter fix

Change of the id calculaton for every new attached input device. The
first available id is now used and the device count is now decreased
when one is removed.

--
Ok, not any sorted lists as that would affect the rest of the code in
a major way. But the array of devices are recalculated at each
invocation. As Peter said 'cpu time is cheap' and this function won't
be called very often so this should be a minor problem.

 dix/devices.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
--
diff --git a/dix/devices.c b/dix/devices.c
index f622be7..bec31c7 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -86,15 +86,27 @@ DeviceIntPtr
 AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 {
     DeviceIntPtr dev, *prev; /* not a typo */
+    DeviceIntPtr devtmp;
+    int devid;
+    char devind[MAX_DEVICES];
+
+    /* Find next available id */
+    memset(devind, 0, sizeof(char)*MAX_DEVICES);
+    for (devtmp = inputInfo.devices; devtmp; devtmp = devtmp->next)
+	devind[devtmp->id]++;
+    for (devtmp = inputInfo.off_devices; devtmp; devtmp = devtmp->next)
+	devind[devtmp->id]++;
+    for (devid = 0; devid < MAX_DEVICES && devind[devid]; devid++)
+	;
 
-    if (inputInfo.numDevices >= MAX_DEVICES)
+    if (devid >= MAX_DEVICES)
 	return (DeviceIntPtr)NULL;
     dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
     if (!dev)
 	return (DeviceIntPtr)NULL;
     dev->name = (char *)NULL;
     dev->type = 0;
-    dev->id = inputInfo.numDevices;
+    dev->id = devid;
     inputInfo.numDevices++;
     dev->public.on = FALSE;
     dev->public.processInputProc = (ProcessInputProc)NoopDDA;
@@ -567,6 +579,7 @@ RemoveDevice(DeviceIntPtr dev)
     }
     
     if (ret == Success) {
+        inputInfo.numDevices--;
         ev.type = DevicePresenceNotify;
         ev.time = currentTime.milliseconds;
         ev.devchange = 0;



More information about the xorg mailing list