Clarified comments for X11 key repeat hack.

This commit is contained in:
Camilla Berglund 2014-09-03 01:44:08 +02:00
parent 3fcc2a6cb2
commit 4aa9174e76

View File

@ -624,10 +624,10 @@ static void processEvent(XEvent *event)
if (!_glfw.x11.xkb.detectable) if (!_glfw.x11.xkb.detectable)
{ {
// XKB detectable key repeat is not supported on this server // HACK: Key repeat events will arrive as KeyRelease/KeyPress
// For key repeats we will get KeyRelease/KeyPress pairs with // pairs with similar or identical time stamps
// similar or identical time stamps. User selected key repeat // The key repeat logic in _glfwInputKey expectes only key
// filtering is handled in _glfwInputKey/_glfwInputChar. // presses to repeat, so detect and discard release events
if (XEventsQueued(_glfw.x11.display, QueuedAfterReading)) if (XEventsQueued(_glfw.x11.display, QueuedAfterReading))
{ {
XEvent nextEvent; XEvent nextEvent;
@ -637,15 +637,16 @@ static void processEvent(XEvent *event)
nextEvent.xkey.window == event->xkey.window && nextEvent.xkey.window == event->xkey.window &&
nextEvent.xkey.keycode == event->xkey.keycode) nextEvent.xkey.keycode == event->xkey.keycode)
{ {
// This last check is a hack to work around key repeats // HACK: Repeat events sometimes leak through due to
// leaking through due to some sort of time drift // some sort of time drift, so add an epsilon
// Toshiyuki Takahashi can press a button 16 times per // Toshiyuki Takahashi can press a button 16 times
// second so it's fairly safe to assume that no human is // per second so it's fairly safe to assume that
// pressing the key 50 times per second (value is ms) // no human is pressing the key 50 times per
// second (value is ms)
if ((nextEvent.xkey.time - event->xkey.time) < 20) if ((nextEvent.xkey.time - event->xkey.time) < 20)
{ {
// This is a server-generated key repeat event // This is very likely a server-generated key repeat
// Do not report anything for this event // event, so ignore it
break; break;
} }
} }