Input: Always add devices with first available ID
Scan the device list when adding a new device, and make sure we can use the first available ID, instead of always incrementing.
This commit is contained in:
parent
20674dcbb2
commit
4f05f9591e
|
@ -86,15 +86,27 @@ DeviceIntPtr
|
|||
AddInputDevice(DeviceProc deviceProc, Bool autoStart)
|
||||
{
|
||||
DeviceIntPtr dev, *prev; /* not a typo */
|
||||
DeviceIntPtr devtmp;
|
||||
int devid;
|
||||
char devind[MAX_DEVICES];
|
||||
|
||||
if (inputInfo.numDevices >= 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 (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;
|
||||
|
@ -572,6 +584,7 @@ RemoveDevice(DeviceIntPtr dev)
|
|||
}
|
||||
|
||||
if (ret == Success) {
|
||||
inputInfo.numDevices--;
|
||||
ev.type = DevicePresenceNotify;
|
||||
ev.time = currentTime.milliseconds;
|
||||
ev.devchange = 0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user