From bc63c8a4570c989f19a036965854bceb9800ce19 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 20 May 2009 12:33:49 +1000 Subject: 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 --- dix/devices.c | 35 +++++++++++++++++++++++++++++++++++ dix/getevents.c | 11 ++++++++--- 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 @@ -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 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, -- cgit v1.2.3