From 8198f65d5096dc23f4588cda6fadcc5e7afcc41e Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 14 Oct 2010 13:43:28 +0200 Subject: [PATCH] Fixed: #1057 X11 Key auto repeat --- .../3d/driver/opengl/unix_event_emitter.cpp | 20 ++++++++++++------- .../src/3d/driver/opengl/unix_event_emitter.h | 16 +++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp b/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp index abc07dba3..f5de38371 100644 --- a/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp +++ b/code/nel/src/3d/driver/opengl/unix_event_emitter.cpp @@ -29,7 +29,7 @@ typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e); namespace NLMISC { -CUnixEventEmitter::CUnixEventEmitter ():_dpy(NULL), _win(0), _PreviousKey(KeyNOKEY), _emulateRawMode(false), _driver(NULL) +CUnixEventEmitter::CUnixEventEmitter ():_dpy(NULL), _win(0), _emulateRawMode(false), _driver(NULL) { _im = 0; _ic = 0; @@ -111,7 +111,7 @@ void CUnixEventEmitter::submitEvents(CEventServer & server, bool allWindows) static Bool isMouseMoveEvent(Display *display, XEvent *event, XPointer arg) { - return (event->type == MotionNotify); + return (event->type == MotionNotify); } void CUnixEventEmitter::emulateMouseRawMode(bool enable) @@ -124,9 +124,9 @@ void CUnixEventEmitter::emulateMouseRawMode(bool enable) XGetWindowAttributes(_dpy, _win, &xwa); XWarpPointer(_dpy, None, _win, None, None, None, None, (xwa.width / 2), (xwa.height / 2)); - + // remove all outstanding mouse move events, they happened before the mouse - // was pulled back to 0.5 / 0.5, so a wrong movement delta would be + // was pulled back to 0.5 / 0.5, so a wrong movement delta would be // reported otherwise XEvent event; while(XCheckIfEvent(_dpy, &event, &isMouseMoveEvent, NULL)) { }; @@ -533,8 +533,14 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) if(key == KeyNOKEY) key = getKeyFromKeycode(keyCode); - server->postEvent (new CEventKeyDown (key, getKeyButton(event.xbutton.state), _PreviousKey != key, this)); - _PreviousKey = key; + // search for key in map + std::map::const_iterator it = _PressedKeys.find(key); + + // if key is not found or value is false, that's the first time + bool firstTime = (it == _PressedKeys.end()) || !it->second; + + server->postEvent (new CEventKeyDown (key, getKeyButton(event.xbutton.state), firstTime, this)); + _PressedKeys[key] = true; // don't send a control character when deleting if (key == KeyDELETE) @@ -568,7 +574,7 @@ bool CUnixEventEmitter::processMessage (XEvent &event, CEventServer *server) key = getKeyFromKeycode(event.xkey.keycode); server->postEvent (new CEventKeyUp (key, getKeyButton(event.xbutton.state), this)); - _PreviousKey = KeyNOKEY; + _PressedKeys[key] = false; } break; } diff --git a/code/nel/src/3d/driver/opengl/unix_event_emitter.h b/code/nel/src/3d/driver/opengl/unix_event_emitter.h index 2c5dc2de1..c6232330a 100644 --- a/code/nel/src/3d/driver/opengl/unix_event_emitter.h +++ b/code/nel/src/3d/driver/opengl/unix_event_emitter.h @@ -89,14 +89,14 @@ private: void createIM(); - Display* _dpy; - Window _win; - TKey _PreviousKey; - XIM _im; - XIC _ic; - bool _emulateRawMode; - NL3D::IDriver* _driver; - CUnixEventServer _InternalServer; + Display* _dpy; + Window _win; + std::map _PressedKeys; + XIM _im; + XIC _ic; + bool _emulateRawMode; + NL3D::IDriver* _driver; + CUnixEventServer _InternalServer; };