dix: introduce GetMaster()

For hybrid devices (keys + buttons/axes) the attached master device is
generally the wrong one. One shouldn't post a button event through a
keyboard and vice versa.

GetMaster(dev) returns the right master device for the given type needed.
This may be the MD paired with this device's MD.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2009-05-20 12:33:49 +10:00
commit bc63c8a457
3 changed files with 44 additions and 3 deletions

View file

@ -2345,6 +2345,41 @@ GetPairedDevice(DeviceIntPtr dev)
}
/**
* Returns the right master for the type of event needed. If the event is a
* keyboard event.
* This function may be called with a master device as argument. If so, the
* returned master is either the device itself or the paired master device.
* If dev is a floating slave device, NULL is returned.
*
* @type ::MASTER_KEYBOARD or ::MASTER_POINTER
*/
DeviceIntPtr
GetMaster(DeviceIntPtr dev, int which)
{
DeviceIntPtr master;
if (IsMaster(dev))
master = dev;
else
master = dev->u.master;
if (master)
{
if (which == MASTER_KEYBOARD)
{
if (master->type != MASTER_KEYBOARD)
master = GetPairedDevice(master);
} else
{
if (master->type != MASTER_POINTER)
master = GetPairedDevice(master);
}
}
return master;
}
/**
* Create a new device pair (== one pointer, one keyboard device).
* Only allocates the devices, you will need to call ActivateDevice() and