tools: add a helper tool to list all currently known codes
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 8 Nov 2021 23:17:16 +0000 (09:17 +1000)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 17 Nov 2023 10:53:12 +0000 (19:53 +0900)
A non-installed tool to make it easy to check if newly added codes are
indeed supported correctly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
meson.build
tools/Makefile.am
tools/libevdev-list-codes.c [new file with mode: 0644]

index 06544003be6579ae0a41641e53b5ad36eb532a0f..972b416397cae5437f1879866ca2420ba2e73c06 100644 (file)
@@ -110,6 +110,11 @@ executable('libevdev-events',
           include_directories: [includes_include],
           dependencies: dep_libevdev,
           install: false)
+executable('libevdev-list-codes',
+          sources: ['tools/libevdev-list-codes.c'],
+          include_directories: [includes_include],
+          dependencies: dep_libevdev,
+          install: false)
 executable('touchpad-edge-detector',
           sources: ['tools/touchpad-edge-detector.c'],
           include_directories: [includes_include],
index 12a4cabbb05ead11498a7eb6652bcf6777d2ff78..65cf4cdc893c59cd0c7b0c58be966638ac097e5c 100644 (file)
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = libevdev-events \
+noinst_PROGRAMS = libevdev-events libevdev-list-codes \
               touchpad-edge-detector \
               mouse-dpi-tool \
               libevdev-tweak-device
@@ -11,6 +11,9 @@ libevdev_ldadd = $(top_builddir)/libevdev/libevdev.la
 libevdev_events_SOURCES = libevdev-events.c
 libevdev_events_LDADD = $(libevdev_ldadd)
 
+libevdev_list_codes_SOURCES = libevdev-list-codes.c
+libevdev_list_codes_LDADD = $(libevdev_ldadd)
+
 touchpad_edge_detector_SOURCES = touchpad-edge-detector.c
 touchpad_edge_detector_LDADD = $(libevdev_ldadd)
 
diff --git a/tools/libevdev-list-codes.c b/tools/libevdev-list-codes.c
new file mode 100644 (file)
index 0000000..8d4f7c2
--- /dev/null
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2021 Red Hat, Inc.
+ */
+
+/* Lists all event types and codes currently known by libevdev. */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <linux/input.h>
+#include "libevdev/libevdev.h"
+
+static void
+list_event_codes(unsigned int type, unsigned int max)
+{
+       const char *typestr = libevdev_event_type_get_name(type);
+
+       if (!typestr)
+               return;
+
+       printf("- %s:\n", typestr);
+
+       for (unsigned int code = 0; code <= max; code++) {
+               const char *str = libevdev_event_code_get_name(type, code);
+
+               if (!str)
+                       continue;
+
+               printf("    %d: %s\n", code, str);
+       }
+}
+
+int
+main (int argc, char **argv)
+{
+       printf("codes:\n");
+       for (unsigned int type = 0; type <= EV_MAX; type++) {
+               int max = libevdev_event_type_get_max(type);
+               if (max == -1)
+                       continue;
+
+               list_event_codes(type, (unsigned int)max);
+       }
+
+       return 0;
+}