]> git.tdb.fi Git - libs/gui.git/blobdiff - source/gbase/display.cpp
Support ignoring keyboard autorepeat
[libs/gui.git] / source / gbase / display.cpp
index 3a755014c1996fe29083c2fda93e7958ad259c13..5d79ca5e9246210caa05472308e092f5b17c297b 100644 (file)
@@ -187,7 +187,7 @@ void Display::tick()
                if(pending==0)
                        break;
 
-               for(int i=0; i<pending; ++i)
+               for(; pending--;)
                {
                        Window::Event event;
                        XNextEvent(priv->display, &event.xevent);
@@ -197,6 +197,26 @@ void Display::tick()
                        map<WindowHandle, Window *>::iterator j=priv->windows.find(event.xevent.xany.window);
                        if(j!=priv->windows.end())
                        {
+                               /* Filter keyboard autorepeat.  If this packet is a KeyRelease and
+                               the next one is a KeyPress with the exact same parameters, they
+                               indicate autorepeat and must be dropped. */
+                               if(event.xevent.type==KeyRelease && !j->second->get_keyboard_autorepeat() && pending>0)
+                               {
+                                       XKeyEvent &kev=event.xevent.xkey;
+                                       XEvent ev2;
+                                       XPeekEvent(priv->display, &ev2);
+                                       if(ev2.type==KeyPress)
+                                       {
+                                               XKeyEvent &kev2=ev2.xkey;
+                                               if(kev2.window==kev.window && kev2.time==kev.time && kev2.keycode==kev.keycode)
+                                               {
+                                                       XNextEvent(priv->display, &ev2);
+                                                       --pending;
+                                                       continue;
+                                               }
+                                       }
+                               }
+
                                j->second->event(event);
                        }
                }