- added glutIgnoreKeyRepeat in miniglut
[vrlugburz] / src / miniglut.c
index bda9491..c362882 100644 (file)
@@ -88,6 +88,7 @@ static unsigned int init_mode;
 
 static struct ctx_info ctx_info;
 static int cur_cursor = GLUT_CURSOR_INHERIT;
+static int ignore_key_repeat;
 
 static glut_cb cb_display;
 static glut_cb cb_idle;
@@ -205,6 +206,11 @@ void glutPostRedisplay(void)
        upd_pending = 1;
 }
 
+void glutIgnoreKeyRepeat(int ignore)
+{
+       ignore_key_repeat = ignore;
+}
+
 #define UPD_EVMASK(x) \
        do { \
                if(func) { \
@@ -580,7 +586,22 @@ static void handle_event(XEvent *ev)
                break;
 
        case KeyPress:
+               if(0) {
        case KeyRelease:
+                       if(ignore_key_repeat && XEventsQueued(dpy, QueuedAfterReading)) {
+                               XEvent next;
+                               XPeekEvent(dpy, &next);
+
+                               if(next.type == KeyPress && next.xkey.keycode == ev->xkey.keycode &&
+                                               next.xkey.time == ev->xkey.time) {
+                                       /* this is a key-repeat event, ignore the release and consume
+                                        * the following press
+                                        */
+                                       XNextEvent(dpy, &next);
+                                       break;
+                               }
+                       }
+               }
                modstate = ev->xkey.state & (ShiftMask | ControlMask | Mod1Mask);
                if(!(sym = XLookupKeysym(&ev->xkey, 0))) {
                        break;
@@ -798,6 +819,15 @@ void glutSetCursor(int cidx)
        cur_cursor = cidx;
 }
 
+void glutSetKeyRepeat(int repmode)
+{
+       if(repmode) {
+               XAutoRepeatOn(dpy);
+       } else {
+               XAutoRepeatOff(dpy);
+       }
+}
+
 static XVisualInfo *choose_visual(unsigned int mode)
 {
        XVisualInfo *vi;
@@ -1229,6 +1259,10 @@ void glutSetCursor(int cidx)
        }
 }
 
+void glutSetKeyRepeat(int repmode)
+{
+}
+
 #define WGL_DRAW_TO_WINDOW     0x2001
 #define WGL_SUPPORT_OPENGL     0x2010
 #define WGL_DOUBLE_BUFFER      0x2011