diff --git a/caca/event.c b/caca/event.c index 636afff..e7b9d14 100644 --- a/caca/event.c +++ b/caca/event.c @@ -50,15 +50,20 @@ static int _lowlevel_event(caca_display_t *, caca_event_t *); * if no more events are pending in the queue. A negative value causes the * function to wait indefinitely until a matching event is received. * + * If not null, \c ev will be filled with information about the event + * received. If null, the function will return but no information about + * the event will be sent. + * * \param dp The libcaca graphical context. * \param event_mask Bitmask of requested events. * \param timeout A timeout value in microseconds - * \param ev A pointer to a caca_event structure. - * \return The next matching event in the queue, or 0 if no event is pending. + * \param ev A pointer to a caca_event structure, or NULL. + * \return 1 if a matching event was received, or 0 if the wait timeouted. */ int caca_get_event(caca_display_t *dp, unsigned int event_mask, caca_event_t *ev, int timeout) { + caca_event_t dummy_event; caca_timer_t timer; int usec = 0; @@ -68,6 +73,9 @@ int caca_get_event(caca_display_t *dp, unsigned int event_mask, if(timeout > 0) _caca_getticks(&timer); + if(ev == NULL) + ev = &dummy_event; + for( ; ; ) { int ret = _get_next_event(dp, ev); diff --git a/doc/migrating.dox b/doc/migrating.dox index 6d36650..50dc0af 100644 --- a/doc/migrating.dox +++ b/doc/migrating.dox @@ -47,7 +47,7 @@ int main(void) { /* Initialise libcaca */ cucul_canvas_t *cv; - caca_display_t *dp; caca_event_t ev; + caca_display_t *dp; cv = cucul_create_canvas(0, 0); dp = caca_create_display(cv); /* Set window title */ @@ -61,7 +61,7 @@ int main(void) caca_refresh_display(); /* Wait for a key press event */ caca_get_event(dp, CACA_EVENT_KEY_PRESS, - &ev, -1); + NULL, -1); /* Clean up library */ caca_free_display(dp); cucul_free_canvas(cv); diff --git a/test/colors.c b/test/colors.c index c4f1730..d3ff813 100644 --- a/test/colors.c +++ b/test/colors.c @@ -24,7 +24,6 @@ int main(int argc, char **argv) { cucul_canvas_t *cv; caca_display_t *dp; - caca_event_t ev; int i, j; cv = cucul_create_canvas(0, 0); @@ -51,7 +50,7 @@ int main(int argc, char **argv) } caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); cucul_free_canvas(cv); diff --git a/test/dithering.c b/test/dithering.c index b79f73a..7515625 100644 --- a/test/dithering.c +++ b/test/dithering.c @@ -13,6 +13,8 @@ #include "config.h" +#include + #include "cucul.h" #include "caca.h" @@ -34,7 +36,6 @@ char density[] = " ',+:;o&%w$W@#"; int main(void) { - caca_event_t ev; cucul_canvas_t *cv; caca_display_t *dp; int neara, dista, nearb, distb, dist; @@ -124,7 +125,7 @@ int main(void) caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); cucul_free_canvas(cv); diff --git a/test/font.c b/test/font.c index 191f802..bf8c2d9 100644 --- a/test/font.c +++ b/test/font.c @@ -38,7 +38,6 @@ int main(int argc, char *argv[]) caca_display_t *dp; cucul_font_t *f; cucul_dither_t *d; - caca_event_t ev; unsigned char *buf; unsigned int w, h; char const * const * fonts; @@ -97,7 +96,7 @@ int main(int argc, char *argv[]) cucul_get_canvas_height(cv), d, buf); caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); /* Free everything */ caca_free_display(dp); diff --git a/test/frames.c b/test/frames.c index bcfcc15..90459d7 100644 --- a/test/frames.c +++ b/test/frames.c @@ -21,12 +21,13 @@ typedef unsigned short uint16_t; typedef unsigned int uint32_t; #endif +#include + #include "cucul.h" #include "caca.h" int main(void) { - caca_event_t ev; cucul_canvas_t *cv; caca_display_t *dp; @@ -57,7 +58,7 @@ int main(void) } n = 0; - while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0)) + while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0)) { cucul_set_canvas_frame(cv, n % 16); caca_refresh_display(dp); diff --git a/test/hsv.c b/test/hsv.c index c4cd9b4..7292642 100644 --- a/test/hsv.c +++ b/test/hsv.c @@ -21,6 +21,8 @@ typedef unsigned short uint16_t; typedef unsigned int uint32_t; #endif +#include + #include "cucul.h" #include "caca.h" @@ -28,7 +30,6 @@ uint32_t buffer[256*256]; int main(void) { - caca_event_t ev; cucul_canvas_t *cv; caca_display_t *dp; @@ -52,7 +53,7 @@ int main(void) caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); cucul_free_canvas(cv); diff --git a/test/transform.c b/test/transform.c index d2e81a6..783e3bf 100644 --- a/test/transform.c +++ b/test/transform.c @@ -49,7 +49,6 @@ static char const *duck[] = int main(void) { - caca_event_t ev; cucul_canvas_t *cv, *normal, *flip, *flop, *rotate; caca_display_t *dp; int i; @@ -108,7 +107,7 @@ int main(void) caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); cucul_free_canvas(rotate); diff --git a/test/truecolor.c b/test/truecolor.c index d538590..bd7f747 100644 --- a/test/truecolor.c +++ b/test/truecolor.c @@ -21,12 +21,13 @@ typedef unsigned short uint16_t; typedef unsigned int uint32_t; #endif +#include + #include "cucul.h" #include "caca.h" int main(void) { - caca_event_t ev; cucul_canvas_t *cv; caca_display_t *dp; @@ -50,7 +51,7 @@ int main(void) caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); cucul_free_canvas(cv); diff --git a/test/unicode.c b/test/unicode.c index 2423b5a..ad0ad72 100644 --- a/test/unicode.c +++ b/test/unicode.c @@ -21,12 +21,13 @@ typedef unsigned short uint16_t; typedef unsigned int uint32_t; #endif +#include + #include "cucul.h" #include "caca.h" int main(void) { - caca_event_t ev; cucul_canvas_t *cv; caca_display_t *dp; @@ -87,7 +88,7 @@ int main(void) caca_refresh_display(dp); - caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); + caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); caca_free_display(dp); cucul_free_canvas(cv);