summaryrefslogtreecommitdiff
path: root/pugl_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-30 06:10:29 +0000
committerDavid Robillard <d@drobilla.net>2012-04-30 06:10:29 +0000
commitfb2ec4fd62e8218ac485c4ad1992c7e01951159d (patch)
tree7b4d9ebc8a7306dfd7b780b0a60131e4c5effa5b /pugl_test.c
parentc0059bd2d7673a155efca5cb86e92b8106f12ac5 (diff)
Implement special keys and keyboard modifiers on X11.
Diffstat (limited to 'pugl_test.c')
-rw-r--r--pugl_test.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/pugl_test.c b/pugl_test.c
index 4abbcda..cf8da2e 100644
--- a/pugl_test.c
+++ b/pugl_test.c
@@ -75,15 +75,34 @@ onDisplay(PuglView* view)
}
static void
+printModifiers(PuglView* view)
+{
+ int mods = puglGetModifiers(view);
+ fprintf(stderr, "Modifiers:%s%s%s%s\n",
+ (mods & PUGL_MOD_SHIFT) ? " Shift" : "",
+ (mods & PUGL_MOD_CTRL) ? " Ctrl" : "",
+ (mods & PUGL_MOD_ALT) ? " Alt" : "",
+ (mods & PUGL_MOD_SUPER) ? " Super" : "");
+}
+
+static void
onKeyboard(PuglView* view, bool press, uint32_t key)
{
- fprintf(stderr, "Key %c %s\n", (char)key, press ? "down" : "up");
+ fprintf(stderr, "Key %c %s ", (char)key, press ? "down" : "up");
+ printModifiers(view);
if (key == 'q' || key == 'Q' || key == KEY_ESCAPE) {
quit = 1;
}
}
static void
+onSpecial(PuglView* view, bool press, PuglKey key)
+{
+ fprintf(stderr, "Special key %d %s ", key, press ? "down" : "up");
+ printModifiers(view);
+}
+
+static void
onMotion(PuglView* view, int x, int y)
{
xAngle = x % 360;
@@ -94,14 +113,16 @@ onMotion(PuglView* view, int x, int y)
static void
onMouse(PuglView* view, int button, bool press, int x, int y)
{
- fprintf(stderr, "Mouse %d %s at %d,%d\n",
+ fprintf(stderr, "Mouse %d %s at %d,%d ",
button, press ? "down" : "up", x, y);
+ printModifiers(view);
}
static void
onScroll(PuglView* view, float dx, float dy)
{
- fprintf(stderr, "Scroll %f %f\n", dx, dy);
+ fprintf(stderr, "Scroll %f %f ", dx, dy);
+ printModifiers(view);
dist += dy / 4.0f;
puglPostRedisplay(view);
}
@@ -115,12 +136,13 @@ onClose(PuglView* view)
int
main(int argc, char** argv)
{
- bool resizable = argc > 1;
- PuglView* view = puglCreate(0, "Pugl Test", 512, 512, resizable);
+ bool resizable = argc > 1;
+ PuglView* view = puglCreate(0, "Pugl Test", 512, 512, resizable);
puglSetKeyboardFunc(view, onKeyboard);
puglSetMotionFunc(view, onMotion);
puglSetMouseFunc(view, onMouse);
puglSetScrollFunc(view, onScroll);
+ puglSetSpecialFunc(view, onSpecial);
puglSetDisplayFunc(view, onDisplay);
puglSetCloseFunc(view, onClose);