diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-08-01 13:52:13 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-08-22 15:56:51 +1000 |
commit | 98fe735ea1d756711019c3d90ed6abd9c06abebf (patch) | |
tree | 8ec8b4d4d49630dc1fdf10e95d01f3877a29aa0e | |
parent | dbbe5735d1451bb32f43bce90f0bcfeff46f9743 (diff) |
dix: add KEYBOARD_OR_FLOAT and POINTER_OR_FLOAT to GetMaster()
GetMaster() currently requires an attached slave device as parameter,
resuling in many calls being IsFloating(dev) ? dev : GetMaster(...);
Add two new parameters so GetMaster can be called unconditionally to get the
right device.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r-- | dix/devices.c | 31 | ||||
-rw-r--r-- | include/inputstr.h | 5 | ||||
-rw-r--r-- | test/input.c | 13 |
3 files changed, 37 insertions, 12 deletions
diff --git a/dix/devices.c b/dix/devices.c index 0ccf25277..334f5d3f5 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2484,16 +2484,22 @@ 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. + * Returns the requested master for this device. + * The return values are: + * - MASTER_ATTACHED: the master for this device or NULL for a floating + * slave. + * - MASTER_KEYBOARD: the master keyboard for this device or NULL for a + * floating slave + * - MASTER_POINTER: the master keyboard for this device or NULL for a + * floating slave + * - POINTER_OR_FLOAT: the master pointer for this device or the device for + * a floating slave + * - KEYBOARD_OR_FLOAT: the master keyboard for this device or the device for + * a floating slave * - * @type ::MASTER_KEYBOARD or ::MASTER_POINTER or ::MASTER_ATTACHED - * @return The requested master device. In the case of MASTER_ATTACHED, this - * is the directly attached master to this device, regardless of the type. - * Otherwise, it is either the master keyboard or pointer for this device. + * @param which ::MASTER_KEYBOARD or ::MASTER_POINTER, ::MASTER_ATTACHED, + * ::POINTER_OR_FLOAT or ::KEYBOARD_OR_FLOAT. + * @return The requested master device */ DeviceIntPtr GetMaster(DeviceIntPtr dev, int which) @@ -2502,12 +2508,15 @@ GetMaster(DeviceIntPtr dev, int which) if (IsMaster(dev)) master = dev; - else + else { master = dev->master; + if (!master && (which == POINTER_OR_FLOAT || which == KEYBOARD_OR_FLOAT)) + return dev; + } if (master && which != MASTER_ATTACHED) { - if (which == MASTER_KEYBOARD) + if (which == MASTER_KEYBOARD || which == KEYBOARD_OR_FLOAT) { if (master->type != MASTER_KEYBOARD) master = GetPairedDevice(master); diff --git a/include/inputstr.h b/include/inputstr.h index 00f72c260..838f9f021 100644 --- a/include/inputstr.h +++ b/include/inputstr.h @@ -472,7 +472,10 @@ typedef struct _SpriteInfoRec { #define MASTER_POINTER 1 #define MASTER_KEYBOARD 2 #define SLAVE 3 -#define MASTER_ATTACHED 4 /* special type for GetMaster */ +/* special types for GetMaster */ +#define MASTER_ATTACHED 4 /* Master for this device */ +#define KEYBOARD_OR_FLOAT 5 /* Keyboard master for this device or this device if floating */ +#define POINTER_OR_FLOAT 6 /* Pointer master for this device or this device if floating */ typedef struct _DeviceIntRec { DeviceRec public; diff --git a/test/input.c b/test/input.c index 31597f9de..c2b0eb012 100644 --- a/test/input.c +++ b/test/input.c @@ -1292,6 +1292,19 @@ static void dix_get_master(void) assert(GetMaster(&floating, MASTER_POINTER) == NULL); assert(GetMaster(&floating, MASTER_KEYBOARD) == NULL); assert(GetMaster(&floating, MASTER_ATTACHED) == NULL); + + assert(GetMaster(&vcp, POINTER_OR_FLOAT) == &vcp); + assert(GetMaster(&vck, POINTER_OR_FLOAT) == &vcp); + assert(GetMaster(&ptr, POINTER_OR_FLOAT) == &vcp); + assert(GetMaster(&kbd, POINTER_OR_FLOAT) == &vcp); + + assert(GetMaster(&vcp, KEYBOARD_OR_FLOAT) == &vck); + assert(GetMaster(&vck, KEYBOARD_OR_FLOAT) == &vck); + assert(GetMaster(&ptr, KEYBOARD_OR_FLOAT) == &vck); + assert(GetMaster(&kbd, KEYBOARD_OR_FLOAT) == &vck); + + assert(GetMaster(&floating, KEYBOARD_OR_FLOAT) == &floating); + assert(GetMaster(&floating, POINTER_OR_FLOAT) == &floating); } |