From 70f365258d73ac8cc37025777e13fdf9e016922c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 Feb 2015 21:32:37 -0500 Subject: UTF-8 keyboard input support on X11. --- pugl_test.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'pugl_test.c') diff --git a/pugl_test.c b/pugl_test.c index 9b942f4..248a49a 100644 --- a/pugl_test.c +++ b/pugl_test.c @@ -99,12 +99,16 @@ printModifiers(PuglView* view) } static void -onKeyboard(PuglView* view, bool press, uint32_t key) +onEvent(PuglView* view, const PuglEvent* event) { - fprintf(stderr, "Key %c %s ", (char)key, press ? "down" : "up"); - printModifiers(view); - if (key == 'q' || key == 'Q' || key == PUGL_CHAR_ESCAPE || - key == PUGL_CHAR_DELETE || key == PUGL_CHAR_BACKSPACE) { + const uint32_t ucode = event->key.character; + if (event->type == PUGL_KEY_PRESS) { + fprintf(stderr, "Key %u (char %u) down (%s)%s\n", + event->key.keycode, event->key.character, event->key.utf8, + event->key.filter ? " (filtered)" : ""); + } + if (ucode == 'q' || ucode == 'Q' || ucode == PUGL_CHAR_ESCAPE || + ucode == PUGL_CHAR_DELETE || ucode == PUGL_CHAR_BACKSPACE) { quit = 1; } } @@ -172,9 +176,9 @@ main(int argc, char** argv) puglInitWindowSize(view, 512, 512); puglInitWindowMinSize(view, 256, 256); puglInitResizable(view, resizable); - + puglIgnoreKeyRepeat(view, ignoreKeyRepeat); - puglSetKeyboardFunc(view, onKeyboard); + puglSetEventFunc(view, onEvent); puglSetMotionFunc(view, onMotion); puglSetMouseFunc(view, onMouse); puglSetScrollFunc(view, onScroll); -- cgit v1.2.1