From: John Tsiombikas Date: Mon, 27 Sep 2021 18:02:09 +0000 (+0300) Subject: added glutIgnoreKeyRepeat and glutSetKeyRepeat functions X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=1f24b7f355137908b32f89b7e00fa319a112478d;p=miniglut added glutIgnoreKeyRepeat and glutSetKeyRepeat functions --- diff --git a/miniglut.c b/miniglut.c index bda9491..c362882 100644 --- a/miniglut.c +++ b/miniglut.c @@ -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 diff --git a/miniglut.h b/miniglut.h index 666e5fc..a757369 100644 --- a/miniglut.h +++ b/miniglut.h @@ -116,6 +116,12 @@ enum { #define GLUT_ACTIVE_CTRL 4 #define GLUT_ACTIVE_ALT 8 +enum { + GLUT_KEY_REPEAT_OFF, + GLUT_KEY_REPEAT_ON +}; +#define GLUT_KEY_REPEAT_DEFAULT GLUT_KEY_REPEAT_ON + typedef void (*glut_cb)(void); typedef void (*glut_cb_reshape)(int x, int y); typedef void (*glut_cb_state)(int state); @@ -149,6 +155,9 @@ void glutSetWindowTitle(const char *title); void glutSetIconTitle(const char *title); void glutSetCursor(int cursor); +void glutIgnoreKeyRepeat(int ignore); +void glutSetKeyRepeat(int repmode); + void glutIdleFunc(glut_cb func); void glutDisplayFunc(glut_cb func); void glutReshapeFunc(glut_cb_reshape func);