diff options
author | David Robillard <d@drobilla.net> | 2012-04-30 20:37:54 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-04-30 20:37:54 +0000 |
commit | 1365dd607f51217017f6de4c7246626a6fdd07e8 (patch) | |
tree | 6e7718c7858f5fe11cba3faae899fd388b10fb05 | |
parent | 91a4fea4672c54d84bd3e46422e32636351c8053 (diff) | |
download | pugl-1365dd607f51217017f6de4c7246626a6fdd07e8.tar.gz pugl-1365dd607f51217017f6de4c7246626a6fdd07e8.tar.bz2 pugl-1365dd607f51217017f6de4c7246626a6fdd07e8.zip |
Add puglIgnoreKeyRepeat and implement on X11.
Add proper command line options for pugl_test.
-rw-r--r-- | pugl/pugl.h | 6 | ||||
-rw-r--r-- | pugl/pugl_internal.h | 7 | ||||
-rw-r--r-- | pugl/pugl_x11.c | 13 | ||||
-rw-r--r-- | pugl_test.c | 23 |
4 files changed, 39 insertions, 10 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h index 45e1653..58b2101 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -250,6 +250,12 @@ int puglGetModifiers(PuglView* view); /** + Ignore synthetic repeated key events. +*/ +void +puglIgnoreKeyRepeat(PuglView* view, bool ignore); + +/** Set the function to call when the window is closed. */ PUGL_API void diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 21e9eb4..6ddcdf8 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -43,6 +43,7 @@ struct PuglViewImpl { int width; int height; int mods; + bool ignoreKeyRepeat; bool redisplay; }; @@ -65,6 +66,12 @@ puglGetModifiers(PuglView* view) } void +puglIgnoreKeyRepeat(PuglView* view, bool ignore) +{ + view->ignoreKeyRepeat = ignore; +} + +void puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc) { view->closeFunc = closeFunc; diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 08bfc40..35d2d42 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -156,7 +156,6 @@ puglDestroy(PuglView* view) if (!glXMakeCurrent(view->impl->display, None, NULL)) { printf("Could not release drawing context.\n"); } - /* destroy the context */ glXDestroyContext(view->impl->display, view->impl->ctx); view->impl->ctx = NULL; } @@ -259,8 +258,6 @@ PuglStatus puglProcessEvents(PuglView* view) { XEvent event; - - /* handle the events in the queue */ while (XPending(view->impl->display) > 0) { XNextEvent(view->impl->display, &event); switch (event.type) { @@ -331,20 +328,20 @@ puglProcessEvents(PuglView* view) break; case KeyRelease: { setModifiers(view, event.xkey.state); - bool retriggered = false; - if (XEventsQueued(view->impl->display, QueuedAfterReading)) { + bool repeated = false; + if (view->ignoreKeyRepeat && + XEventsQueued(view->impl->display, QueuedAfterReading)) { XEvent next; XPeekEvent(view->impl->display, &next); if (next.type == KeyPress && next.xkey.time == event.xkey.time && next.xkey.keycode == event.xkey.keycode) { - // Key repeat, ignore fake KeyPress event XNextEvent(view->impl->display, &event); - retriggered = true; + repeated = true; } } - if (!retriggered && view->keyboardFunc) { + if (!repeated && view->keyboardFunc) { KeySym sym = XKeycodeToKeysym( view->impl->display, event.xkey.keycode, 0); PuglKey special = keySymToSpecial(sym); diff --git a/pugl_test.c b/pugl_test.c index da58b78..6eeed1a 100644 --- a/pugl_test.c +++ b/pugl_test.c @@ -19,6 +19,7 @@ */ #include <stdio.h> +#include <string.h> #include "pugl/pugl.h" @@ -135,8 +136,26 @@ onClose(PuglView* view) int main(int argc, char** argv) { - bool resizable = argc > 1; - PuglView* view = puglCreate(0, "Pugl Test", 512, 512, resizable); + bool ignoreKeyRepeat = false; + bool resizable = false; + for (int i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "-h")) { + printf("USAGE: %s [OPTIONS]...\n\n" + " -h Display this help\n" + " -i Ignore key repeat\n" + " -r Resizable window\n", argv[0]); + return 0; + } else if (!strcmp(argv[i], "-i")) { + ignoreKeyRepeat = true; + } else if (!strcmp(argv[i], "-r")) { + resizable = true; + } else { + fprintf(stderr, "Unknown option: %s\n", argv[i]); + } + } + + PuglView* view = puglCreate(0, "Pugl Test", 512, 512, resizable); + puglIgnoreKeyRepeat(view, ignoreKeyRepeat); puglSetKeyboardFunc(view, onKeyboard); puglSetMotionFunc(view, onMotion); puglSetMouseFunc(view, onMouse); |