From 33612fb37c8f7f21ad2d3b457a98c5d659c00511 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 9 Sep 2024 15:25:52 +1000 Subject: [PATCH] tools/debug-events: move the event type str to a helper function This isn't really necessary for the code as-is it makes debugging things easier. Part-of: --- tools/libinput-debug-events.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c index 218f5d72..9a6e68c9 100644 --- a/tools/libinput-debug-events.c +++ b/tools/libinput-debug-events.c @@ -55,16 +55,12 @@ static bool is_tty = false; #define printq(...) ({ if (!be_quiet) printf(__VA_ARGS__); }) -static void -print_event_header(struct libinput_event *ev, size_t event_count) +static const char * +event_type_to_str(enum libinput_event_type evtype) { - /* use for pointer value only, do not dereference */ - static void *last_device = NULL; - struct libinput_device *dev = libinput_event_get_device(ev); - const char *type = NULL; - char prefix; + const char *type; - switch(libinput_event_get_type(ev)) { + switch(evtype) { case LIBINPUT_EVENT_NONE: abort(); case LIBINPUT_EVENT_DEVICE_ADDED: @@ -168,6 +164,19 @@ print_event_header(struct libinput_event *ev, size_t event_count) break; } + return type; +} + +static void +print_event_header(struct libinput_event *ev, size_t event_count) +{ + /* use for pointer value only, do not dereference */ + static void *last_device = NULL; + struct libinput_device *dev = libinput_event_get_device(ev); + char prefix; + + const char *type = event_type_to_str(libinput_event_get_type(ev)); + prefix = (last_device != dev) ? '-' : ' '; printq("%c%-7s %-23s ",