Skip to content

Commit

Permalink
[X11] Fixed key repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
thefiddler committed May 8, 2014
1 parent 8195800 commit 86146f5
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions Source/OpenTK/Platform/X11/X11GLNative.cs
Expand Up @@ -865,40 +865,8 @@ public override void ProcessEvents()
{
if (pressed)
{
// Check if this is a key repeat event.
// X11 does not provide this information,
// so we rely on the XInput2 extension for that.
// Todo: hack this when XInput2 is not available
// by checking if another KeyPress event is enqueued.
bool is_repeat = false;
if (xi2_supported && e.GenericEventCookie.extension == xi2_opcode)
{
if (e.GenericEventCookie.evtype == (int)XIEventType.KeyPress)
{
unsafe
{
XIDeviceEvent* xi = (XIDeviceEvent*)e.GenericEventCookie.data;
is_repeat = (xi->flags & XIEventFlags.KeyRepeat) != 0;
}
}
}
else
{
if (API.Pending(window.Display) > 0)
{
unsafe
{
XEvent dummy = new XEvent();
KeyRepeatTestData arg = new KeyRepeatTestData();
arg.Event = e;
API.CheckIfEvent(window.Display, ref dummy, IsKeyRepeatPredicate,
new IntPtr(&arg));
is_repeat = arg.IsRepeat;
}
}
}

// Raise KeyDown event
bool is_repeat = KeyboardState[key];
OnKeyDown(key, is_repeat);
}
else
Expand Down Expand Up @@ -1060,24 +1028,6 @@ public override void ProcessEvents()
}
}

struct KeyRepeatTestData
{
public XEvent Event;
public bool IsRepeat;
}

unsafe static bool IsKeyRepeatPredicate(IntPtr display, ref XEvent e, IntPtr arg)
{
// IsRepeat is true when the event queue contains an identical
// KeyPress event at later time no greater than 2.
KeyRepeatTestData* data = (KeyRepeatTestData*)arg;
data->IsRepeat =
e.type == XEventName.KeyPress &&
e.KeyEvent.keycode == data->Event.KeyEvent.keycode &&
e.KeyEvent.time.ToInt64() - data->Event.KeyEvent.time.ToInt64() < 2;
return false; // keep the event in the queue
}

#endregion

#region Bounds
Expand Down

0 comments on commit 86146f5

Please sign in to comment.