From fcb96967ba6473c89b862ac7826e557ea9dcdf85 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 12 Jan 2013 21:01:44 +0100 Subject: [PATCH] Replaced repeat kluge with detectable auto repeat. --- src/input.c | 4 +++- src/x11_init.c | 10 ++++++++++ src/x11_window.c | 26 -------------------------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/input.c b/src/input.c index 43653b3d..4f104eae 100644 --- a/src/input.c +++ b/src/input.c @@ -139,7 +139,9 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action) window->key[key] = GLFW_STICK; else { - repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS); + if (action == GLFW_PRESS && window->key[key] == GLFW_PRESS) + repeated = GL_TRUE; + window->key[key] = (char) action; } diff --git a/src/x11_init.c b/src/x11_init.c index 6e9761b5..4686f264 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -470,6 +470,8 @@ static void detectEWMH(void) static GLboolean initDisplay(void) { + Bool supported; + _glfw.x11.display = XOpenDisplay(NULL); if (!_glfw.x11.display) { @@ -528,6 +530,14 @@ static GLboolean initDisplay(void) return GL_FALSE; } + XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported); + if (!supported) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "X11: Detectable key repeat is not available"); + return GL_FALSE; + } + // Update the key code LUT // FIXME: We should listen to XkbMapNotify events to track changes to // the keyboard mapping. diff --git a/src/x11_window.c b/src/x11_window.c index f396b252..ee838307 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -498,32 +498,6 @@ static void processEvent(XEvent *event) if (window == NULL) return; - // Do not report key releases for key repeats. For key repeats we - // will get KeyRelease/KeyPress pairs with similar or identical - // time stamps. User selected key repeat filtering is handled in - // _glfwInputKey/_glfwInputChar. - if (XEventsQueued(_glfw.x11.display, QueuedAfterReading)) - { - XEvent nextEvent; - XPeekEvent(_glfw.x11.display, &nextEvent); - - if (nextEvent.type == KeyPress && - nextEvent.xkey.window == event->xkey.window && - nextEvent.xkey.keycode == event->xkey.keycode) - { - // This last check is a hack to work around key repeats - // leaking through due to some sort of time drift - // Toshiyuki Takahashi can press a button 16 times per - // second so it's fairly safe to assume that no human is - // pressing the key 50 times per second (value is ms) - if ((nextEvent.xkey.time - event->xkey.time) < 20) - { - // Do not report anything for this event - break; - } - } - } - _glfwInputKey(window, translateKey(event->xkey.keycode), GLFW_RELEASE); break; }