dix: add AttachDevice, needed to attach a slave device to a master device.

For now, we don't allow attaching slaves to other slaves, and we don't allow
pairing slaves with other slaves.
Pairing is for master keyboard->master pointer only.
Attaching is for slave device->master device only.
This commit is contained in:
Peter Hutterer 2007-10-16 11:18:31 +09:30
parent be1565f6b8
commit bd7d5255ce
2 changed files with 41 additions and 9 deletions

View File

@ -540,11 +540,11 @@ InitAndStartDevices(WindowPtr root)
ActivateDevice(dev); ActivateDevice(dev);
} }
if (!inputInfo.keyboard) { if (!inputInfo.keyboard) { /* In theory, this cannot happen */
ErrorF("[dix] No core keyboard\n"); ErrorF("[dix] No core keyboard\n");
return BadImplementation; return BadImplementation;
} }
if (!inputInfo.pointer) { if (!inputInfo.pointer) { /* In theory, this cannot happen */
ErrorF("[dix] No core pointer\n"); ErrorF("[dix] No core pointer\n");
return BadImplementation; return BadImplementation;
} }
@ -555,10 +555,6 @@ InitAndStartDevices(WindowPtr root)
if (inputInfo.pointer->inited && inputInfo.pointer->startup) if (inputInfo.pointer->inited && inputInfo.pointer->startup)
EnableDevice(inputInfo.pointer); EnableDevice(inputInfo.pointer);
/* Remove VCP and VCK from device list */
inputInfo.devices = NULL;
inputInfo.keyboard->next = inputInfo.pointer->next = NULL;
/* enable real devices */ /* enable real devices */
for (dev = inputInfo.off_devices; dev; dev = next) for (dev = inputInfo.off_devices; dev; dev = next)
{ {
@ -569,18 +565,21 @@ InitAndStartDevices(WindowPtr root)
} }
/* All of the devices are started up now. Pair VCK with VCP, then /* All of the devices are started up now. Pair VCK with VCP, then
* pair each real keyboard with a real pointer. * attach each device to the initial master.
*/ */
PairDevices(NULL, inputInfo.pointer, inputInfo.keyboard); PairDevices(NULL, inputInfo.pointer, inputInfo.keyboard);
for (dev = inputInfo.devices; dev; dev = dev->next) for (dev = inputInfo.devices; dev; dev = dev->next)
{ {
if (!DevHasCursor(dev)) if (!DevHasCursor(dev))
PairDevices(NULL, GuessFreePointerDevice(), dev); AttachDevice(NULL, dev, inputInfo.keyboard);
else else
{
AttachDevice(NULL, dev, inputInfo.pointer);
/* enter/leave counter on root window */ /* enter/leave counter on root window */
((FocusSemaphoresPtr)root->devPrivates[FocusPrivatesIndex].ptr)->enterleave++; ((FocusSemaphoresPtr)root->devPrivates[FocusPrivatesIndex].ptr)->enterleave++;
} }
}
return Success; return Success;
} }
@ -2195,7 +2194,7 @@ ProcQueryKeymap(ClientPtr client)
} }
/* Pair the keyboard to the pointer device. Keyboard events will follow the /* Pair the keyboard to the pointer device. Keyboard events will follow the
* pointer sprite. * pointer sprite. Only applicable for master devices.
* If the client is set, the request to pair comes from some client. In this * If the client is set, the request to pair comes from some client. In this
* case, we need to check for access. If the client is NULL, it's from an * case, we need to check for access. If the client is NULL, it's from an
* internal automatic pairing, we must always permit this. * internal automatic pairing, we must always permit this.
@ -2206,6 +2205,10 @@ PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd)
if (!ptr) if (!ptr)
return BadDevice; return BadDevice;
/* Don't allow pairing for slave devices */
if (ptr->master || kbd->master)
return BadDevice;
if (!pairingClient) if (!pairingClient)
RegisterPairingClient(client); RegisterPairingClient(client);
else if (client && pairingClient != client) else if (client && pairingClient != client)
@ -2223,6 +2226,32 @@ PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd)
return Success; return Success;
} }
/**
* Attach device 'dev' to device 'master'.
* Client is set to the client that issued the request, or NULL if it comes
* from some internal automatic pairing.
*
* We don't allow multi-layer hierarchies right now. You can't attach a slave
* to another slave.
*/
int
AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master)
{
if (!dev || !master)
return BadDevice;
if (master->master) /* can't attach to slave device */
return BadDevice;
if (!pairingClient)
RegisterPairingClient(client);
else if (client && pairingClient != client)
return BadAccess;
dev->master = master;
return Success;
}
/* Return the pointer that is paired with the given keyboard. If no pointer is /* Return the pointer that is paired with the given keyboard. If no pointer is
* paired, return the virtual core pointer * paired, return the virtual core pointer
*/ */

View File

@ -465,6 +465,9 @@ extern DeviceIntPtr LookupDeviceIntRec(
extern int PairDevices(ClientPtr client, extern int PairDevices(ClientPtr client,
DeviceIntPtr pointer, DeviceIntPtr pointer,
DeviceIntPtr keyboard); DeviceIntPtr keyboard);
extern int AttachDevice(ClientPtr client,
DeviceIntPtr slave,
DeviceIntPtr master);
extern DeviceIntPtr GetPairedPointer(DeviceIntPtr kbd); extern DeviceIntPtr GetPairedPointer(DeviceIntPtr kbd);
extern DeviceIntPtr GetPairedKeyboard(DeviceIntPtr ptr); extern DeviceIntPtr GetPairedKeyboard(DeviceIntPtr ptr);