]> git.tdb.fi Git - libs/gui.git/commitdiff
Support ignoring keyboard autorepeat
authorMikko Rasa <tdb@tdb.fi>
Sun, 8 Mar 2009 15:45:46 +0000 (15:45 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Mar 2009 15:45:46 +0000 (15:45 +0000)
source/gbase/display.cpp
source/gbase/window.cpp
source/gbase/window.h

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);
                        }
                }
index 7d58fe40b9abfceeacf699edf2081b372c220f63..ac95b25ec1019e82812ac80a0f48cac327b528d6 100644 (file)
@@ -184,6 +184,11 @@ void Window::reconfigure(const WindowOptions &opts)
                display.restore_mode();
 }
 
+void Window::set_keyboard_autorepeat(bool r)
+{
+       kbd_autorepeat=r;
+}
+
 void Window::show_cursor(bool s)
 {
 #ifdef WIN32
@@ -245,6 +250,7 @@ void Window::hide()
 
 void Window::init()
 {
+       kbd_autorepeat=true;
        priv=new Private;
 
 #ifdef WIN32
index c48adc5fe3ff81b39ace83eb8402e0b3aa9d1e89..9dc84e4e623cd45bbf90dc08f348b7139da85c11 100644 (file)
@@ -43,6 +43,7 @@ public:
 protected:
        Display &display;
        WindowOptions options;
+       bool kbd_autorepeat;
        Private *priv;
 
 public:
@@ -52,6 +53,8 @@ public:
 
        void set_title(const std::string &);
        void reconfigure(const WindowOptions &);
+       void set_keyboard_autorepeat(bool);
+       bool get_keyboard_autorepeat() const { return kbd_autorepeat; }
        void show_cursor(bool);
        void warp_pointer(int, int);