From 08999899cbd80e8ed22712cc2de579583d72a287 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 21 Oct 2020 09:01:32 +1000 Subject: [PATCH] Print the event name when using an invalid event type Where an invalid event type is passed to a function (e.g. a keyboard event to a touch-related function) we used to only print the event code. That makes debugging less obvious than necessary, so let's print the event name too. This requires the function to be moved below event_type_to_str() Signed-off-by: Peter Hutterer --- src/libinput.c | 64 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index f544ef9..eb65fba 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -76,37 +76,6 @@ ASSERT_INT_SIZE(enum libinput_config_middle_emulation_state); ASSERT_INT_SIZE(enum libinput_config_scroll_method); ASSERT_INT_SIZE(enum libinput_config_dwt_state); -static inline bool -check_event_type(struct libinput *libinput, - const char *function_name, - unsigned int type_in, - ...) -{ - bool rc = false; - va_list args; - unsigned int type_permitted; - - va_start(args, type_in); - type_permitted = va_arg(args, unsigned int); - - while (type_permitted != (unsigned int)-1) { - if (type_permitted == type_in) { - rc = true; - break; - } - type_permitted = va_arg(args, unsigned int); - } - - va_end(args); - - if (!rc) - log_bug_client(libinput, - "Invalid event type %d passed to %s()\n", - type_in, function_name); - - return rc; -} - static inline const char * event_type_to_str(enum libinput_event_type type) { @@ -145,6 +114,39 @@ event_type_to_str(enum libinput_event_type type) return NULL; } +static inline bool +check_event_type(struct libinput *libinput, + const char *function_name, + unsigned int type_in, + ...) +{ + bool rc = false; + va_list args; + unsigned int type_permitted; + + va_start(args, type_in); + type_permitted = va_arg(args, unsigned int); + + while (type_permitted != (unsigned int)-1) { + if (type_permitted == type_in) { + rc = true; + break; + } + type_permitted = va_arg(args, unsigned int); + } + + va_end(args); + + if (!rc) { + const char *name = event_type_to_str(type_in); + log_bug_client(libinput, + "Invalid event type %s (%d) passed to %s()\n", + name, type_in, function_name); + } + + return rc; +} + struct libinput_source { libinput_source_dispatch_t dispatch; void *user_data; -- 2.7.4