Print the event name when using an invalid event type
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 20 Oct 2020 23:01:32 +0000 (09:01 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 20 Oct 2020 23:09:50 +0000 (09:09 +1000)
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 <peter.hutterer@who-t.net>
src/libinput.c

index f544ef94a12c739544b8e9c60862ed210d0d2932..eb65fba46084b1787073fc44fb29e9eaa04640b5 100644 (file)
@@ -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;