diff --git a/src/arch/InputHandler/InputHandler_X11.cpp b/src/arch/InputHandler/InputHandler_X11.cpp index cd285b526c..61692e7eca 100644 --- a/src/arch/InputHandler/InputHandler_X11.cpp +++ b/src/arch/InputHandler/InputHandler_X11.cpp @@ -203,9 +203,9 @@ void InputHandler_X11::Update() lastEvent.type = 0; continue; } + // This is a new event so the last release was not a repeat. - ButtonPressed( DeviceInput(DEVICE_KEYBOARD, lastDB, 0) ); - lastEvent.type = 0; + RegisterKeyEvent( event.xkey.time, false, lastDB ); } if( event.type == FocusOut ) @@ -221,7 +221,9 @@ void InputHandler_X11::Update() continue; if( bKeyPress ) - ButtonPressed( DeviceInput(DEVICE_KEYBOARD, lastDB, 1) ); + { + RegisterKeyEvent( event.xkey.time, true, lastDB ); + } /* else if( bMousePress ) ButtonPressed( DeviceInput(DEVICE_MOUSE, lastDB, 1) ); @@ -234,7 +236,9 @@ void InputHandler_X11::Update() if( lastEvent.type != 0 ) { if( lastEvent.type == (KeyPress|KeyRelease) ) - ButtonPressed( DeviceInput(DEVICE_KEYBOARD, lastDB, 0) ); + { + RegisterKeyEvent( event.xkey.time, false, lastDB ); + } /* if( lastEvent.type == (ButtonPress|ButtonRelease) ) ButtonPressed( DeviceInput(DEVICE_MOUSE, lastDB, 0) ); @@ -254,6 +258,25 @@ void InputHandler_X11::GetDevicesAndDescriptions( vector& vDevi } } +void InputHandler_X11::RegisterKeyEvent( unsigned long timestamp, bool keyDown, DeviceButton button ) +{ + // https://linux.die.net/man/3/xkeyevent + // Event timestamp is in milliseconds + + // seconds, microseconds + RageTimer timer( + timestamp / 1000, + (timestamp % 1000) * 1000 ); + + DeviceInput di( + DEVICE_KEYBOARD, + button, + keyDown ? 1.0f:0.0f, + timer); + + ButtonPressed( di ); +} + /* * (c) 2005, 2006 Sean Burke, Ben Anderson, Steve Checkoway * All rights reserved. diff --git a/src/arch/InputHandler/InputHandler_X11.h b/src/arch/InputHandler/InputHandler_X11.h index bb53c4e4d7..49905546e4 100644 --- a/src/arch/InputHandler/InputHandler_X11.h +++ b/src/arch/InputHandler/InputHandler_X11.h @@ -12,6 +12,9 @@ public: ~InputHandler_X11(); void Update(); void GetDevicesAndDescriptions( vector& vDevicesOut ); +private: + // timestamp is unsigned long to match X11 Time type + void RegisterKeyEvent( unsigned long timestamp, bool keyDown, DeviceButton button ); }; #endif