[PATCH] dix: release all buttons and keys before reattaching a device (#34182)
Peter Hutterer
peter.hutterer at who-t.net
Thu Feb 24 17:15:12 PST 2011
Testcase:
xinput float <keyboard name>
results in the keyboard's enter key being repeated as the device is detached
while the key is still physically down. To avoid this, release all keys and
buttons before reattaching the device.
X.Org Bug 34182 <http://bugs.freedesktop.org/show_bug.cgi?id=34182>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
dix/devices.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/dix/devices.c b/dix/devices.c
index 6c0dc42..1fe9cc6 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2376,6 +2376,44 @@ RecalculateMasterButtons(DeviceIntPtr slave)
}
/**
+ * Generate release events for all keys/button currently down on this
+ * device.
+ */
+static void
+ReleaseButtonsAndKeys(DeviceIntPtr dev)
+{
+ EventListPtr eventlist = InitEventList(GetMaximumEventsNum());
+ ButtonClassPtr b = dev->button;
+ KeyClassPtr k = dev->key;
+ int i, nevents;
+
+ if (!eventlist) /* no release events for you */
+ return;
+
+ /* Release all buttons */
+ for (i = 0; b && i < b->numButtons; i++)
+ {
+ if (BitIsOn(b->down, i))
+ {
+ nevents = GetPointerEvents(eventlist, dev, ButtonRelease, i, 0, NULL);
+ for (i = 0; i < nevents; i++)
+ mieqProcessDeviceEvent(dev, (InternalEvent*)(eventlist+i)->event, NULL);
+ }
+ }
+
+ /* Release all keys */
+ for (i = 0; k && i < MAP_LENGTH; i++)
+ {
+ if (BitIsOn(k->down, i))
+ {
+ nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i);
+ for (i = 0; i < nevents; i++)
+ mieqProcessDeviceEvent(dev, (InternalEvent*)(eventlist+i)->event, NULL);
+ }
+ }
+}
+
+/**
* Attach device 'dev' to device 'master'.
* Client is set to the client that issued the request, or NULL if it comes
* from some internal automatic pairing.
@@ -2408,6 +2446,8 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master)
free(dev->spriteInfo->sprite);
}
+ ReleaseButtonsAndKeys(dev);
+
oldmaster = dev->u.master;
dev->u.master = master;
--
1.7.4
More information about the xorg-devel
mailing list