Commit c23c6bb99615658600376a5f88cd646d986638a4

Pierre Le Marre 2023-09-18T12:06:45

Interactive tools: always print keycode

diff --git a/tools/tools-common.c b/tools/tools-common.c
index a94466c..3403ea6 100644
--- a/tools/tools-common.c
+++ b/tools/tools-common.c
@@ -50,6 +50,17 @@
 
 #include "tools-common.h"
 
+static void
+print_keycode(struct xkb_keymap *keymap, const char* prefix,
+              xkb_keycode_t keycode, const char *suffix) {
+    const char *keyname = xkb_keymap_key_get_name(keymap, keycode);
+    if (keyname) {
+        printf("%s%-4s%s", prefix, keyname, suffix);
+    } else {
+        printf("%s%-4d%s", prefix, keycode, suffix);
+    }
+}
+
 void
 tools_print_keycode_state(struct xkb_state *state,
                           struct xkb_compose_state *compose_state,
@@ -89,6 +100,8 @@ tools_print_keycode_state(struct xkb_state *state,
         syms = &sym;
     }
 
+    print_keycode(keymap, "keycode [ ", keycode, " ] ");
+
     printf("keysyms [ ");
     for (int i = 0; i < nsyms; i++) {
         xkb_keysym_get_name(syms[i], s, sizeof(s));