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)
|
AddInputDevice(DeviceProc deviceProc, Bool autoStart)
|
||||||
{
|
{
|
||||||
DeviceIntPtr dev, *prev; /* not a typo */
|
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;
|
return (DeviceIntPtr)NULL;
|
||||||
dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
|
dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return (DeviceIntPtr)NULL;
|
return (DeviceIntPtr)NULL;
|
||||||
dev->name = (char *)NULL;
|
dev->name = (char *)NULL;
|
||||||
dev->type = 0;
|
dev->type = 0;
|
||||||
dev->id = inputInfo.numDevices;
|
dev->id = devid;
|
||||||
inputInfo.numDevices++;
|
inputInfo.numDevices++;
|
||||||
dev->public.on = FALSE;
|
dev->public.on = FALSE;
|
||||||
dev->public.processInputProc = (ProcessInputProc)NoopDDA;
|
dev->public.processInputProc = (ProcessInputProc)NoopDDA;
|
||||||
|
@ -572,6 +584,7 @@ RemoveDevice(DeviceIntPtr dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == Success) {
|
if (ret == Success) {
|
||||||
|
inputInfo.numDevices--;
|
||||||
ev.type = DevicePresenceNotify;
|
ev.type = DevicePresenceNotify;
|
||||||
ev.time = currentTime.milliseconds;
|
ev.time = currentTime.milliseconds;
|
||||||
ev.devchange = 0;
|
ev.devchange = 0;
|
||||||
|
|
Loading…
Reference in New Issue