mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-03-30 09:27:01 +00:00
[X11] Fixed key repeat
This commit is contained in:
parent
8195800ee7
commit
86146f54d5
|
@ -865,40 +865,8 @@ namespace OpenTK.Platform.X11
|
|||
{
|
||||
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
|
||||
|
@ -1060,24 +1028,6 @@ namespace OpenTK.Platform.X11
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue