[PATCH 12/17] dix: add KEYBOARD_OR_FLOAT and POINTER_OR_FLOAT to GetMaster()
Peter Hutterer
peter.hutterer at who-t.net
Sun Aug 7 23:21:08 PDT 2011
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 at who-t.net>
---
dix/devices.c | 31 ++++++++++++++++++++-----------
include/inputstr.h | 5 ++++-
test/input.c | 13 +++++++++++++
3 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/dix/devices.c b/dix/devices.c
index 0ccf252..af1c030 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_SLAVE: the master pointer for this device or the device for
+ * a floating slave
+ * - KEYBOARD_OR_SLAVE: the master keyboard for this device or the device for
*
- * @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 00f72c2..838f9f0 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 31597f9..c2b0eb0 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);
}
--
1.7.6
More information about the xorg-devel
mailing list