I think this handles repeat events correctly now. It is hard for me to test it though.
This commit is contained in:
@@ -148,25 +148,44 @@ InputHandler_X11::~InputHandler_X11()
|
|||||||
|
|
||||||
void InputHandler_X11::Update()
|
void InputHandler_X11::Update()
|
||||||
{
|
{
|
||||||
XEvent event;
|
|
||||||
|
|
||||||
if( Dpy == NULL || Win == None )
|
if( Dpy == NULL || Win == None )
|
||||||
{
|
{
|
||||||
InputHandler::UpdateTimer();
|
InputHandler::UpdateTimer();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XEvent event, lastEvent;
|
||||||
|
DeviceButton lastDB = DeviceButton_Invalid;
|
||||||
|
lastEvent.type = 0;
|
||||||
|
|
||||||
while( XCheckWindowEvent(Dpy, Win, KeyPressMask | KeyReleaseMask, &event) )
|
while( XCheckWindowEvent(Dpy, Win, KeyPressMask | KeyReleaseMask, &event) )
|
||||||
{
|
{
|
||||||
|
const bool bPress = event.type == KeyPress;
|
||||||
|
if( lastEvent.type != 0 )
|
||||||
|
{
|
||||||
|
if( bPress && event.xkey.time == lastEvent.xkey.time &&
|
||||||
|
event.xkey.keycode == lastEvent.xkey.keycode )
|
||||||
|
{
|
||||||
|
// This is a repeat event so ignore it.
|
||||||
|
lastEvent.type = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// This is a new event so the last release was not a repeat.
|
||||||
|
ButtonPressed( DeviceInput(DEVICE_KEYBOARD, lastDB), false );
|
||||||
|
lastEvent.type = 0;
|
||||||
|
}
|
||||||
// Why only the zero index?
|
// Why only the zero index?
|
||||||
DeviceButton db = XSymToDeviceButton( XLookupKeysym(&event.xkey, 0) );
|
lastDB = XSymToDeviceButton( XLookupKeysym(&event.xkey, 0) );
|
||||||
if( db == DeviceButton_Invalid )
|
if( lastDB == DeviceButton_Invalid )
|
||||||
continue;
|
continue;
|
||||||
bool bPress = event.type == KeyPress;
|
if( bPress )
|
||||||
const DeviceInput di( DEVICE_KEYBOARD, db );
|
ButtonPressed( DeviceInput(DEVICE_KEYBOARD, lastDB), true );
|
||||||
if( INPUTFILTER->IsBeingPressed(di) != bPress )
|
else
|
||||||
ButtonPressed( di, bPress );
|
lastEvent = event;
|
||||||
}
|
}
|
||||||
|
// Handle any last releases.
|
||||||
|
if( lastEvent.type != 0 )
|
||||||
|
ButtonPressed( DeviceInput(DEVICE_KEYBOARD, lastDB), false );
|
||||||
InputHandler::UpdateTimer();
|
InputHandler::UpdateTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user