From 86ce92eec14aa1aaf7c9ab14a520b66690488213 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 9 Dec 2009 18:46:25 +0000 Subject: [PATCH] x11: Emulate XKB's detectable key auto-repeat Old-style X11 terminals require that even modern X11 send KeyPress and KeyRelease pairs when auto-repeating. For this reason modern(-ish) API like XKB has a way to detect auto-repeat and do a single KeyRelease at the end of a KeyPress sequence. The newly added check emulates XKB's detectable auto-repeat by peeking the next event after a KeyRelease and checking if it's a KeyPress for the same key and timestamp - and then ignoring the KeyRelease if it matches. --- clutter/x11/clutter-event-x11.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clutter/x11/clutter-event-x11.c b/clutter/x11/clutter-event-x11.c index b40c5b5a4..6b3ea67ce 100644 --- a/clutter/x11/clutter-event-x11.c +++ b/clutter/x11/clutter-event-x11.c @@ -627,6 +627,32 @@ event_translate (ClutterBackend *backend, break; case KeyRelease: + /* old-style X11 terminals require that even modern X11 send + * KeyPress/KeyRelease pairs when auto-repeating. for this + * reason modern(-ish) API like XKB has a way to detect + * auto-repeat and do a single KeyRelease at the end of a + * KeyPress sequence. + * + * this check emulates XKB's detectable auto-repeat; we peek + * the next event and check if it's a KeyPress for the same key + * and timestamp - and then ignore it if it matches the + * KeyRelease + */ + if (XPending (xevent->xkey.display)) + { + XEvent next_event; + + XPeekEvent (xevent->xkey.display, &next_event); + + if (next_event.type == KeyPress && + next_event.xkey.keycode == xevent->xkey.keycode && + next_event.xkey.time == xevent->xkey.time) + { + res = FALSE; + break; + } + } + event->key.type = event->type = CLUTTER_KEY_RELEASE; translate_key_event (backend, event, xevent); break;