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

Magnus Vigerlöf Magnus.Vigerlof at home.se
Wed Mar 28 15:12:38 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.

--
 dix/devices.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

--
diff --git a/dix/devices.c b/dix/devices.c
index f622be7..6536c4b 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -82,20 +82,32 @@ #include "exevents.h"
 int CoreDevicePrivatesIndex = 0;
 static int CoreDevicePrivatesGeneration = -1;
 
+/* Array of pointers to the current devices for simple calculation
+ * of the next free device id. */
+static DeviceIntPtr *inputDeviceArrayId = NULL;
+
 DeviceIntPtr
 AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 {
     DeviceIntPtr dev, *prev; /* not a typo */
+    int devid;
 
-    if (inputInfo.numDevices >= MAX_DEVICES)
+    if (!inputDeviceArrayId)
+	inputDeviceArrayId = xnfcalloc(sizeof(DeviceIntPtr), MAX_DEVICES);
+    /* find out the next available id */
+    for (devid = 0; devid < MAX_DEVICES; devid++)
+	if (!inputDeviceArrayId[devid])
+	    break;
+    if (devid == MAX_DEVICES)
 	return (DeviceIntPtr)NULL;
     dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
     if (!dev)
 	return (DeviceIntPtr)NULL;
+    inputInfo.numDevices++;
+    inputDeviceArrayId[devid] = dev;
     dev->name = (char *)NULL;
     dev->type = 0;
-    dev->id = inputInfo.numDevices;
-    inputInfo.numDevices++;
+    dev->id = devid;
     dev->public.on = FALSE;
     dev->public.processInputProc = (ProcessInputProc)NoopDDA;
     dev->public.realInputProc = (ProcessInputProc)NoopDDA;
@@ -565,8 +577,11 @@ RemoveDevice(DeviceIntPtr dev)
             ret = Success;
 	}
     }
-    
+
     if (ret == Success) {
+        inputInfo.numDevices--;
+        inputDeviceArrayId[dev->id] = NULL;
+
         ev.type = DevicePresenceNotify;
         ev.time = currentTime.milliseconds;
         ev.devchange = 0;



More information about the xorg mailing list