summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter@cs.unisa.edu.au>2007-03-05 15:31:16 +1030
committerPeter Hutterer <peter@cs.unisa.edu.au>2007-03-05 15:31:16 +1030
commit39aa79177196e21bcdbaf8e44adead9ef91e6ee5 (patch)
treecd0b106de02e7519fbc29fd035fd507cdbdec1be
parent1f0075786fedde538a95e2f39681052e25021d88 (diff)
dix: Add GuessFreePointerDevice(). Runs through device list and tries to
find a pointer that hasn't been paired yet. xfree86: Use GuessFreePointerDevice() for newly connected non-sprite devices.
-rw-r--r--dix/devices.c42
-rw-r--r--hw/xfree86/common/xf86Xinput.c6
2 files changed, 46 insertions, 2 deletions
diff --git a/dix/devices.c b/dix/devices.c
index 87b3927f9..919558658 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2026,3 +2026,45 @@ UnregisterPairingClient(ClientPtr client)
}
return True;
}
+
+/* Guess a pointer that could be a good one for pairing. Any pointer that is
+ * not yet paired with keyboard is considered a good one.
+ * If no pointer is found, the last real pointer is chosen. If that doesn't
+ * work either, we take the core pointer.
+ */
+DeviceIntPtr
+GuessFreePointerDevice()
+{
+ DeviceIntPtr it, it2;
+ DeviceIntPtr lastRealPtr = NULL;
+
+ it = inputInfo.devices;
+
+ while(it)
+ {
+ /* found device with a sprite? */
+ if (it != inputInfo.pointer && it->spriteOwner)
+ {
+ lastRealPtr = it;
+
+ it2 = inputInfo.devices;
+ while(it2)
+ {
+ /* something paired with it? */
+ if (it != it2 && it2->pSprite == it->pSprite)
+ break;
+
+ it2 = it2->next;
+ }
+
+ if (it2)
+ break;
+
+ /* woohoo! no pairing set up for 'it' yet */
+ return it;
+ }
+ it = it->next;
+ }
+
+ return (lastRealPtr) ? lastRealPtr : inputInfo.pointer;
+}
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 31be1e36a..c6d6b360e 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -189,8 +189,10 @@ xf86ActivateDevice(LocalDevicePtr local)
/* Only create a new sprite if it's a non-shared pointer */
if (IsPointerDevice(dev) && dev->isMPDev)
InitializeSprite(dev, GetCurrentRootWindow());
- else
- PairDevices(NULL, inputInfo.pointer, dev);
+ else {
+ /* pair with a free device */
+ PairDevices(NULL, GuessFreePointerDevice(), dev);
+ }
RegisterOtherDevice(dev);