[X11] Fixed key repeat
authorthefiddler <stapostol@gmail.com>
Thu, 8 May 2014 22:26:51 +0000 (00:26 +0200)
committerthefiddler <stapostol@gmail.com>
Thu, 8 May 2014 22:26:51 +0000 (00:26 +0200)
Source/OpenTK/Platform/X11/X11GLNative.cs

index 017e020..22bb851 100644 (file)
@@ -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