makekeys: update to match the rest of libX11 makekeys This integrates two commits from libX11: ebd6ef0a4db0ddef0ae17ad14571518ccdeea5ba XStringToKeysym: Special case for XF86 keysyms Some XFree86 keysyms were in XKeysymDB as XF86_foo, despite really being XF86foo. So, if we get to the bottom of XStringToKeysym and haven't found our XF86_foo, try it again as XF86foo. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com> 00175397480b76d32bf82b0c7c94c91a2a95954e makekeys: Scan vendor keysyms as well as core Since we can't really live without vendor keysyms, scan them all in to generate ks_tables.h, rather than only doing the core ones, and leaving the vendor syms to be manually synchronised with XKeysymDB. Signed-off-by: Daniel Stone <daniel@fooishbar.org> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com> Notice that the xkey.sh test is changed to match libX11 behavior, i.e. XKeysymToString(0x1008FE20) -> "XF86Ungrab" as opposed to "XF86_Ungrab". Signed-off-by: Ran Benita <ran234@gmail.com>
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
diff --git a/makekeys/makekeys.c b/makekeys/makekeys.c
index 1334e15..cf96f13 100644
--- a/makekeys/makekeys.c
+++ b/makekeys/makekeys.c
@@ -51,125 +51,54 @@ static char tab[KTNUM];
static unsigned short offsets[KTNUM];
static unsigned short indexes[KTNUM];
static KeySym values[KTNUM];
-
-/*
- * 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)
-{
- const char **s = xf86_special_keys;
- while (*s) {
- if (strcmp(key, *s) == 0)
- return 1;
- s++;
- }
- return 0;
-}
+static int ksnum = 0;
static int
-get_keysym(const char *buf, char *key, int ndx)
-{
- if (sscanf(buf, "#define XK_%127s 0x%lx", key, &info[ndx].val) != 2)
- return 0;
- return 1;
-}
-
-static int
-get_keysym_alias(const char *buf, char *key, int ndx)
+parse_line(const char *buf, char *key, KeySym *val, char *prefix)
{
int i;
char alias[128];
-
- if (sscanf(buf, "#define XK_%127s XK_%127s", key, alias) != 2)
- return 0;
-
- for (i = ndx - 1; i >= 0; i--) {
- if (strcmp(info[i].name, alias) == 0) {
- info[ndx].val = info[i].val;
- return 1;
- }
+ char *tmp, *tmpa;
+
+ /* See if we can catch a straight XK_foo 0x1234-style definition first;
+ * the trickery around tmp is to account for prefices. */
+ i = sscanf(buf, "#define %127s 0x%lx", key, val);
+ if (i == 2 && (tmp = strstr(key, "XK_"))) {
+ memcpy(prefix, key, tmp - key);
+ prefix[tmp - key] = '\0';
+ tmp += 3;
+ memmove(key, tmp, strlen(tmp) + 1);
+ return 1;
}
- /* Didn't find a match */
- fprintf(stderr, "can't find matching definition %s for keysym %s\n",
- alias, key);
- return -1;
-}
-
-static int
-get_xf86_keysym(const char *buf, char *key, size_t len, int ndx)
-{
- char tmp[128];
-
- if (sscanf(buf, "#define XF86XK_%127s 0x%lx", tmp, &info[ndx].val) != 2)
- return 0;
-
- /* Prepend XF86 or XF86_ to the key */
- snprintf(key, len, "XF86%s%s", is_xf86_special(tmp) ? "_" : "", tmp);
-
- return 1;
-}
-
-static int
-get_xf86_keysym_alias(const char *buf, char *key, size_t len, int ndx)
-{
- int i;
- char alias[128], ktmp[128], atmp[128];
-
- /* 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 */
- snprintf(key, len, "XF86%s%s", is_xf86_special(ktmp) ? "_" : "",
- ktmp);
- snprintf(alias, sizeof(alias), "XF86%s%s",
- is_xf86_special(atmp) ? "_" : "", atmp);
- } else {
- if (sscanf(buf, "#define XF86XK_%127s XK_%127s", ktmp, alias) != 2)
- return 0;
- /* Prepend XF86 to the key */
- snprintf(key, len, "XF86%s%s", is_xf86_special(ktmp) ? "_" : "",
- ktmp);
- }
-
- for (i = ndx - 1; i >= 0; i--) {
- if (strcmp(info[i].name, alias) == 0) {
- info[ndx].val = info[i].val;
- return 1;
+ /* Now try to catch alias (XK_foo XK_bar) definitions, and resolve them
+ * immediately: if the target is in the form XF86XK_foo, we need to
+ * canonicalise this to XF86foo before we do the lookup. */
+ i = sscanf(buf, "#define %127s %127s", key, alias);
+ if (i == 2 && (tmp = strstr(key, "XK_")) && (tmpa = strstr(alias, "XK_"))) {
+ memcpy(prefix, key, tmp - key);
+ prefix[tmp - key] = '\0';
+ tmp += 3;
+ memmove(key, tmp, strlen(tmp) + 1);
+ memmove(tmpa, tmpa + 3, strlen(tmpa + 3) + 1);
+
+ for (i = ksnum - 1; i >= 0; i--) {
+ if (strcmp(info[i].name, alias) == 0) {
+ *val = info[i].val;
+ return 1;
+ }
}
+
+ fprintf(stderr, "can't find matching definition %s for keysym %s%s\n",
+ alias, prefix, key);
}
- /* Didn't find a match */
- fprintf(stderr, "can't find matching definition %s for keysym %s\n",
- alias, key);
- return -1;
+ return 0;
}
int
main(int argc, char *argv[])
{
- int ksnum = 0;
FILE *fptr;
int max_rehash;
Signature sig;
@@ -181,7 +110,7 @@ main(int argc, char *argv[])
int best_z = 0;
int num_found;
KeySym val;
- char key[128];
+ char key[128], prefix[128];
char buf[1024];
for (l = 1; l < argc; l++) {
@@ -192,38 +121,25 @@ main(int argc, char *argv[])
}
while (fgets(buf, sizeof(buf), fptr)) {
- int ret;
-
- /* Manage keysyms from keysymdef.h */
- ret = get_keysym(buf, key, ksnum);
- if (!ret) {
- ret = get_keysym_alias(buf, key, ksnum);
- if (ret == -1)
- continue;
- }
-
- /* Manage keysyms from XF86keysym.h */
- if (!ret)
- ret = get_xf86_keysym(buf, key, sizeof(key), ksnum);
- if (!ret) {
- ret = get_xf86_keysym_alias(buf, key, sizeof(key), ksnum);
- if (ret < 1)
- continue;
- }
+ if (!parse_line(buf, key, &val, prefix))
+ continue;
- if (info[ksnum].val > 0x1fffffff) {
- fprintf(stderr,
- "ignoring illegal keysym (%s), remove it from .h file!\n",
- key);
+ if (val == XK_VoidSymbol)
+ val = 0;
+ if (val > 0x1fffffff) {
+ fprintf(stderr, "ignoring illegal keysym (%s, %lx)\n", key,
+ val);
continue;
}
- name = malloc((unsigned)strlen(key) + 1);
+
+ name = malloc(strlen(prefix) + strlen(key) + 1);
if (!name) {
fprintf(stderr, "makekeys: out of memory!\n");
exit(1);
}
- (void)strcpy(name, key);
+ sprintf(name, "%s%s", prefix, key);
info[ksnum].name = name;
+ info[ksnum].val = val;
ksnum++;
if (ksnum == KTNUM) {
fprintf(stderr, "makekeys: too many keysyms!\n");
diff --git a/src/keysym.c b/src/keysym.c
index bd0a67b..0eab240 100644
--- a/src/keysym.c
+++ b/src/keysym.c
@@ -146,5 +146,19 @@ xkb_string_to_keysym(const char *s)
return strtoul(&s[2], NULL, 16);
}
+ /* Stupid inconsistency between the headers and XKeysymDB: the former has
+ * no separating underscore, while some XF86* syms in the latter did.
+ * As a last ditch effort, try without. */
+ if (strncmp(s, "XF86_", 5) == 0) {
+ uint32_t ret;
+ char *tmp = strdup(s);
+ if (!tmp)
+ return NoSymbol;
+ memmove(&tmp[4], &tmp[5], strlen(s) - 5 + 1);
+ ret = xkb_string_to_keysym(tmp);
+ free(tmp);
+ return ret;
+ }
+
return NoSymbol;
}
diff --git a/test/xkey.sh b/test/xkey.sh
index eecab8c..1478a74 100755
--- a/test/xkey.sh
+++ b/test/xkey.sh
@@ -42,7 +42,7 @@ check_key 0x1008FF56 XF86Close
check_string ThisKeyShouldNotExist NoSymbol
check_key 0x0 NoSymbol
check_string XF86_Switch_VT_5 0x1008FE05
-check_key 0x1008FE20 XF86_Ungrab
+check_key 0x1008FE20 XF86Ungrab
check_string VoidSymbol 0xFFFFFF
check_key 0x01001234 U1234
check_string U4567 0x1004567