Fixed: #1057 X11 Key auto repeat

This commit is contained in:
kervala 2010-08-05 14:21:41 +02:00
parent 719e589d0d
commit 898e36a8d8

View file

@ -393,6 +393,24 @@ TKey getKeyFromKeySym (KeySym keysym)
return KeyNOKEY; return KeyNOKEY;
} }
// check if the next pressed key is the same
static bool keyRepeat(Display *display, XEvent *event)
{
XEvent peekevent;
if (XPending(display))
{
XPeekEvent(display, &peekevent);
if ((peekevent.type == KeyPress) &&
(peekevent.xkey.keycode == event->xkey.keycode) &&
((peekevent.xkey.time-event->xkey.time) < 2))
return true;
}
return false;
}
bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
{ {
if (!server) if (!server)
@ -541,21 +559,33 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server)
} }
case KeyRelease: case KeyRelease:
{ {
TKey key = getKeyFromKeySym(XKeycodeToKeysym(_dpy, event.xkey.keycode, 0)); if (!keyRepeat(_dpy, &event))
{
KeySym k;
// only need to get correct KeySym
int c = XLookupString(&event.xkey, NULL, 0, &k, NULL);
TKey key = getKeyFromKeySym(k);
if(key == KeyNOKEY) if(key == KeyNOKEY)
key = getKeyFromKeycode(event.xkey.keycode); key = getKeyFromKeycode(event.xkey.keycode);
server->postEvent (new CEventKeyUp (key, getKeyButton(event.xbutton.state), this)); server->postEvent (new CEventKeyUp (key, getKeyButton(event.xbutton.state), this));
_PreviousKey = KeyNOKEY; _PreviousKey = KeyNOKEY;
}
break; break;
} }
case FocusIn: case FocusIn:
// keyboard focus
if (_ic) XSetICFocus(_ic); if (_ic) XSetICFocus(_ic);
break; break;
case FocusOut: case FocusOut:
// keyboard focus
if (_ic) XUnsetICFocus(_ic); if (_ic) XUnsetICFocus(_ic);
break; break;
case KeymapNotify:
break;
case MappingNotify: case MappingNotify:
// update keymap
XRefreshKeyboardMapping((XMappingEvent *)&event); XRefreshKeyboardMapping((XMappingEvent *)&event);
break; break;
case DestroyNotify: case DestroyNotify: