aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_utils.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-01 19:42:20 +0100
committerDavid Robillard <d@drobilla.net>2020-03-01 20:32:28 +0100
commit94a2d5c31e6bad7e33a03bf282dc60d08f923526 (patch)
treee89cc5bdceceadaab2f4be5b855d7c3172d7f974 /test/test_utils.h
parent2c4c565e1c92aa3a0f583e671502439abdeaf3ff (diff)
downloadpugl-94a2d5c31e6bad7e33a03bf282dc60d08f923526.tar.gz
pugl-94a2d5c31e6bad7e33a03bf282dc60d08f923526.tar.bz2
pugl-94a2d5c31e6bad7e33a03bf282dc60d08f923526.zip
Cleanup: Shorten event printing code
Diffstat (limited to 'test/test_utils.h')
-rw-r--r--test/test_utils.h105
1 files changed, 63 insertions, 42 deletions
diff --git a/test/test_utils.h b/test/test_utils.h
index 904c9a4..4207576 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -182,75 +182,96 @@ printModifiers(const uint32_t mods)
static inline int
printEvent(const PuglEvent* event, const char* prefix, const bool verbose)
{
-#define FFMT "%6.1f"
-#define PFMT FFMT " " FFMT
+#define FFMT "%6.1f"
+#define PFMT FFMT " " FFMT
+#define PRINT(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
switch (event->type) {
case PUGL_KEY_PRESS:
- return fprintf(stderr, "%sKey press code %3u key U+%04X\n",
- prefix, event->key.keycode, event->key.key);
+ return PRINT("%sKey press code %3u key U+%04X\n",
+ prefix,
+ event->key.keycode,
+ event->key.key);
case PUGL_KEY_RELEASE:
- return fprintf(stderr, "%sKey release code %3u key U+%04X\n",
- prefix, event->key.keycode, event->key.key);
+ return PRINT("%sKey release code %3u key U+%04X\n",
+ prefix,
+ event->key.keycode,
+ event->key.key);
case PUGL_TEXT:
- return fprintf(stderr, "%sText entry code %3u char U+%04X (%s)\n",
- prefix, event->text.keycode,
- event->text.character, event->text.string);
+ return PRINT("%sText entry code %3u char U+%04X (%s)\n",
+ prefix,
+ event->text.keycode,
+ event->text.character,
+ event->text.string);
case PUGL_BUTTON_PRESS:
case PUGL_BUTTON_RELEASE:
- return (fprintf(stderr, "%sMouse %d %s at " PFMT " ",
- prefix,
- event->button.button,
- (event->type == PUGL_BUTTON_PRESS) ? "down" : "up ",
- event->button.x,
- event->button.y) +
+ return (PRINT("%sMouse %d %s at " PFMT " ",
+ prefix,
+ event->button.button,
+ (event->type == PUGL_BUTTON_PRESS) ? "down" : "up ",
+ event->button.x,
+ event->button.y) +
printModifiers(event->scroll.state));
case PUGL_SCROLL:
- return (fprintf(stderr, "%sScroll %5.1f %5.1f at " PFMT " ",
- prefix,
- event->scroll.dx, event->scroll.dy,
- event->scroll.x, event->scroll.y) +
+ return (PRINT("%sScroll %5.1f %5.1f at " PFMT " ",
+ prefix,
+ event->scroll.dx,
+ event->scroll.dy,
+ event->scroll.x,
+ event->scroll.y) +
printModifiers(event->scroll.state));
case PUGL_ENTER_NOTIFY:
- return fprintf(stderr, "%sMouse enter at " PFMT "\n",
- prefix, event->crossing.x, event->crossing.y);
+ return PRINT("%sMouse enter at " PFMT "\n",
+ prefix,
+ event->crossing.x,
+ event->crossing.y);
case PUGL_LEAVE_NOTIFY:
- return fprintf(stderr, "%sMouse leave at " PFMT "\n",
- prefix, event->crossing.x, event->crossing.y);
+ return PRINT("%sMouse leave at " PFMT "\n",
+ prefix,
+ event->crossing.x,
+ event->crossing.y);
case PUGL_FOCUS_IN:
- return fprintf(stderr, "%sFocus in%s\n",
- prefix, event->focus.grab ? " (grab)" : "");
+ return PRINT("%sFocus in%s\n",
+ prefix,
+ event->focus.grab ? " (grab)" : "");
case PUGL_FOCUS_OUT:
- return fprintf(stderr, "%sFocus out%s\n",
- prefix, event->focus.grab ? " (ungrab)" : "");
- default: break;
+ return PRINT("%sFocus out%s\n",
+ prefix,
+ event->focus.grab ? " (ungrab)" : "");
+ default:
+ break;
}
if (verbose) {
switch (event->type) {
case PUGL_CONFIGURE:
- return fprintf(stderr, "%sConfigure " PFMT " " PFMT "\n", prefix,
- event->configure.x,
- event->configure.y,
- event->configure.width,
- event->configure.height);
+ return PRINT("%sConfigure " PFMT " " PFMT "\n",
+ prefix,
+ event->configure.x,
+ event->configure.y,
+ event->configure.width,
+ event->configure.height);
case PUGL_EXPOSE:
- return fprintf(stderr,
- "%sExpose " PFMT " " PFMT "\n", prefix,
- event->expose.x,
- event->expose.y,
- event->expose.width,
- event->expose.height);
+ return PRINT("%sExpose " PFMT " " PFMT "\n",
+ prefix,
+ event->expose.x,
+ event->expose.y,
+ event->expose.width,
+ event->expose.height);
case PUGL_CLOSE:
- return fprintf(stderr, "%sClose\n", prefix);
+ return PRINT("%sClose\n", prefix);
case PUGL_MOTION_NOTIFY:
- return fprintf(stderr, "%sMouse motion at " PFMT "\n",
- prefix, event->motion.x, event->motion.y);
+ return PRINT("%sMouse motion at " PFMT "\n",
+ prefix,
+ event->motion.x,
+ event->motion.y);
default:
break;
}
}
+#undef PRINT
+#undef PFMT
#undef FFMT
return 0;