Interactive tools: always print keycode
authorPierre Le Marre <dev@wismill.eu>
Mon, 18 Sep 2023 10:06:45 +0000 (12:06 +0200)
committerWismill <dev@wismill.eu>
Mon, 18 Sep 2023 14:14:12 +0000 (16:14 +0200)
tools/tools-common.c

index a94466c..3403ea6 100644 (file)
 
 #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));