[PATCH libxkbcommon 4/4] makekeys: update to match the rest of libX11 makekeys
Ran Benita
ran234 at gmail.com
Sat Feb 25 14:25:50 PST 2012
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 at fooishbar.org>
Reviewed-by: Alan Coopersmith <alan.coopersmith at 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 at fooishbar.org>
Reviewed-by: Alan Coopersmith <alan.coopersmith at 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 at gmail.com>
---
makekeys/makekeys.c | 174 +++++++++++++--------------------------------------
src/keysym.c | 14 +++++
test/xkey.sh | 2 +-
3 files changed, 60 insertions(+), 130 deletions(-)
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
--
1.7.9.2
More information about the xorg-devel
mailing list