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>master
parent
ad4f195eb4
commit
0d8874d01c
|
@ -51,125 +51,54 @@ static char tab[KTNUM];
|
||||||
static unsigned short offsets[KTNUM];
|
static unsigned short offsets[KTNUM];
|
||||||
static unsigned short indexes[KTNUM];
|
static unsigned short indexes[KTNUM];
|
||||||
static KeySym values[KTNUM];
|
static KeySym values[KTNUM];
|
||||||
|
static int ksnum = 0;
|
||||||
/*
|
|
||||||
* 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
|
static int
|
||||||
is_xf86_special(const char *key)
|
parse_line(const char *buf, char *key, KeySym *val, char *prefix)
|
||||||
{
|
|
||||||
const char **s = 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 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)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char alias[128];
|
char alias[128];
|
||||||
|
char *tmp, *tmpa;
|
||||||
|
|
||||||
if (sscanf(buf, "#define XK_%127s XK_%127s", key, alias) != 2)
|
/* See if we can catch a straight XK_foo 0x1234-style definition first;
|
||||||
return 0;
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = ndx - 1; i >= 0; i--) {
|
/* Now try to catch alias (XK_foo XK_bar) definitions, and resolve them
|
||||||
if (strcmp(info[i].name, alias) == 0) {
|
* immediately: if the target is in the form XF86XK_foo, we need to
|
||||||
info[ndx].val = info[i].val;
|
* canonicalise this to XF86foo before we do the lookup. */
|
||||||
return 1;
|
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 */
|
return 0;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Didn't find a match */
|
|
||||||
fprintf(stderr, "can't find matching definition %s for keysym %s\n",
|
|
||||||
alias, key);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ksnum = 0;
|
|
||||||
FILE *fptr;
|
FILE *fptr;
|
||||||
int max_rehash;
|
int max_rehash;
|
||||||
Signature sig;
|
Signature sig;
|
||||||
|
@ -181,7 +110,7 @@ main(int argc, char *argv[])
|
||||||
int best_z = 0;
|
int best_z = 0;
|
||||||
int num_found;
|
int num_found;
|
||||||
KeySym val;
|
KeySym val;
|
||||||
char key[128];
|
char key[128], prefix[128];
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
for (l = 1; l < argc; l++) {
|
for (l = 1; l < argc; l++) {
|
||||||
|
@ -192,38 +121,25 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), fptr)) {
|
while (fgets(buf, sizeof(buf), fptr)) {
|
||||||
int ret;
|
if (!parse_line(buf, key, &val, prefix))
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Manage keysyms from keysymdef.h */
|
if (val == XK_VoidSymbol)
|
||||||
ret = get_keysym(buf, key, ksnum);
|
val = 0;
|
||||||
if (!ret) {
|
if (val > 0x1fffffff) {
|
||||||
ret = get_keysym_alias(buf, key, ksnum);
|
fprintf(stderr, "ignoring illegal keysym (%s, %lx)\n", key,
|
||||||
if (ret == -1)
|
val);
|
||||||
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 (info[ksnum].val > 0x1fffffff) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"ignoring illegal keysym (%s), remove it from .h file!\n",
|
|
||||||
key);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
name = malloc((unsigned)strlen(key) + 1);
|
|
||||||
|
name = malloc(strlen(prefix) + strlen(key) + 1);
|
||||||
if (!name) {
|
if (!name) {
|
||||||
fprintf(stderr, "makekeys: out of memory!\n");
|
fprintf(stderr, "makekeys: out of memory!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
(void)strcpy(name, key);
|
sprintf(name, "%s%s", prefix, key);
|
||||||
info[ksnum].name = name;
|
info[ksnum].name = name;
|
||||||
|
info[ksnum].val = val;
|
||||||
ksnum++;
|
ksnum++;
|
||||||
if (ksnum == KTNUM) {
|
if (ksnum == KTNUM) {
|
||||||
fprintf(stderr, "makekeys: too many keysyms!\n");
|
fprintf(stderr, "makekeys: too many keysyms!\n");
|
||||||
|
|
14
src/keysym.c
14
src/keysym.c
|
@ -146,5 +146,19 @@ xkb_string_to_keysym(const char *s)
|
||||||
return strtoul(&s[2], NULL, 16);
|
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;
|
return NoSymbol;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ check_key 0x1008FF56 XF86Close
|
||||||
check_string ThisKeyShouldNotExist NoSymbol
|
check_string ThisKeyShouldNotExist NoSymbol
|
||||||
check_key 0x0 NoSymbol
|
check_key 0x0 NoSymbol
|
||||||
check_string XF86_Switch_VT_5 0x1008FE05
|
check_string XF86_Switch_VT_5 0x1008FE05
|
||||||
check_key 0x1008FE20 XF86_Ungrab
|
check_key 0x1008FE20 XF86Ungrab
|
||||||
check_string VoidSymbol 0xFFFFFF
|
check_string VoidSymbol 0xFFFFFF
|
||||||
check_key 0x01001234 U1234
|
check_key 0x01001234 U1234
|
||||||
check_string U4567 0x1004567
|
check_string U4567 0x1004567
|
||||||
|
|
Loading…
Reference in New Issue