From e9eec476bd26fb3f15d96d5bc91597770814768c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 8 Mar 2009 15:45:46 +0000 Subject: [PATCH] Support ignoring keyboard autorepeat --- source/gbase/display.cpp | 22 +++++++++++++++++++++- source/gbase/window.cpp | 6 ++++++ source/gbase/window.h | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/source/gbase/display.cpp b/source/gbase/display.cpp index 3a75501..5d79ca5 100644 --- a/source/gbase/display.cpp +++ b/source/gbase/display.cpp @@ -187,7 +187,7 @@ void Display::tick() if(pending==0) break; - for(int i=0; idisplay, &event.xevent); @@ -197,6 +197,26 @@ void Display::tick() map::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); } } diff --git a/source/gbase/window.cpp b/source/gbase/window.cpp index 7d58fe4..ac95b25 100644 --- a/source/gbase/window.cpp +++ b/source/gbase/window.cpp @@ -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 diff --git a/source/gbase/window.h b/source/gbase/window.h index c48adc5..9dc84e4 100644 --- a/source/gbase/window.h +++ b/source/gbase/window.h @@ -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); -- 2.45.2