diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-05-20 12:33:49 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2009-05-22 15:44:57 +1000 |
commit | bc63c8a4570c989f19a036965854bceb9800ce19 (patch) | |
tree | 07205723732084c5c347ef14e84819f887036f83 | |
parent | d79318f269d959d566ec66239b4c985afd61b259 (diff) |
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>
-rw-r--r-- | dix/devices.c | 35 | ||||
-rw-r--r-- | dix/getevents.c | 11 | ||||
-rw-r--r-- | include/input.h | 1 |
3 files changed, 44 insertions, 3 deletions
diff --git a/dix/devices.c b/dix/devices.c index 3d0d30d29..c94e93518 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2346,6 +2346,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 * EnableDevice() manually. diff --git a/dix/getevents.c b/dix/getevents.c index ff249c803..40cf4cab5 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -612,7 +612,10 @@ clipValuators(DeviceIntPtr pDev, int first_valuator, int num_valuators, static EventListPtr updateFromMaster(EventListPtr events, DeviceIntPtr dev, int *num_events) { - DeviceIntPtr master = dev->u.master; + DeviceIntPtr master; + + master = GetMaster(dev, (type & DEVCHANGE_POINTER_EVENT) ? MASTER_POINTER : MASTER_KEYBOARD); + if (master && master->last.slave != dev) { CreateClassesChangedEvent(events, master, dev); @@ -793,8 +796,10 @@ updateHistory(DeviceIntPtr dev, int first, int num, CARD32 ms) { updateMotionHistory(dev, ms, first, num, &dev->last.valuators[first]); if (dev->u.master) - updateMotionHistory(dev->u.master, ms, first, num, - &dev->last.valuators[first]); + { + DeviceIntPtr master = GetMaster(dev, MASTER_POINTER); + updateMotionHistory(master, ms, first, num, &dev->last.valuators[first]); + } } /** diff --git a/include/input.h b/include/input.h index 44990a0d5..194dbebc5 100644 --- a/include/input.h +++ b/include/input.h @@ -472,6 +472,7 @@ extern int AttachDevice(ClientPtr client, DeviceIntPtr master); extern _X_EXPORT DeviceIntPtr GetPairedDevice(DeviceIntPtr kbd); +extern DeviceIntPtr GetMaster(DeviceIntPtr dev, int type); extern int AllocDevicePair(ClientPtr client, char* name, |