makekeys: Handle XFree86 special action keys For some reason, there are a set of keys that have an underscore after the XF86 prefix when Xlib gets them from XKeysymDB.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/src/makekeys/makekeys.c b/src/makekeys/makekeys.c
index 3eb1027..07ba3ce 100644
--- a/src/makekeys/makekeys.c
+++ b/src/makekeys/makekeys.c
@@ -55,6 +55,42 @@ static unsigned short indexes[KTNUM];
static KeySym values[KTNUM];
static char buf[1024];
+/*
+ * XFree86 special action keys - for some reason, these have an
+ * underscore after the XF86 prefix.
+ */
+static const char *xf86_special_keys[] = {
+ "Switch_VT_1",
+ "Switch_VT_2",
+ "Switch_VT_3",
+ "Switch_VT_4",
+ "Switch_VT_5",
+ "Switch_VT_6",
+ "Switch_VT_7",
+ "Switch_VT_8",
+ "Switch_VT_9",
+ "Switch_VT_10",
+ "Switch_VT_11",
+ "Switch_VT_12",
+ "Ungrab",
+ "ClearGrab",
+ "Next_VMode",
+ "Prev_VMode",
+ NULL
+};
+
+static int
+is_xf86_special(const char *key)
+{
+ char **s = (char **)xf86_special_keys;
+ while (*s) {
+ if (strcmp(key, *s) == 0)
+ return 1;
+ s++;
+ }
+ return 0;
+}
+
static int
get_keysym(const char *buf, char *key, int index)
{
@@ -95,8 +131,8 @@ get_xf86_keysym(const char *buf, char *key, size_t len, int index)
if (sscanf(buf, "#define XF86XK_%127s 0x%lx", tmp, &info[index].val) != 2)
return 0;
- /* Prepend XF86 to the key */
- strncpy(key, "XF86", len - 1);
+ /* Prepend XF86 or XF86_ to the key */
+ snprintf(key, len, "XF86%s", is_xf86_special(tmp) ? "_" : "");
strncat(key, tmp, len - strlen(key) - 1);
return 1;
@@ -111,15 +147,16 @@ get_xf86_keysym_alias(const char *buf, char *key, size_t len, int index)
/* Try to handle both XF86XK and XK aliases */
if (sscanf(buf, "#define XF86XK_%127s XF86XK_%127s", ktmp, atmp) == 2) {
/* Prepend XF86 to the key and alias */
- strncpy(key, "XF86", len - 1);
+ snprintf(key, len, "XF86%s", is_xf86_special(ktmp) ? "_" : "");
strncat(key, ktmp, len - strlen(key) - 1);
- strncpy(alias, "XF86", sizeof(alias) - 1);
+ snprintf(alias, sizeof(alias), "XF86%s",
+ is_xf86_special(atmp) ? "_" : "");
strncat(alias, atmp, sizeof(alias) - strlen(alias) - 1);
} else {
if (sscanf(buf, "#define XF86XK_%127s XK_%127s", ktmp, alias) != 2)
return 0;
/* Prepend XF86 to the key */
- strncpy(key, "XF86", len - 1);
+ snprintf(key, len, "XF86%s", is_xf86_special(ktmp) ? "_" : "");
strncat(key, ktmp, len - strlen(key) - 1);
}