Get rid of xkb_key_names

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-15 01:31:34 +03:00
parent 50fef8eb8a
commit 1313af8fb5
14 changed files with 158 additions and 269 deletions

View File

@ -145,80 +145,27 @@ free_sym_maps(struct xkb_keymap *keymap)
darray_free(keymap->key_sym_map);
}
int
XkbcAllocNames(struct xkb_keymap *keymap, unsigned which,
size_t nTotalAliases)
{
if (!keymap)
return BadMatch;
if (!keymap->names) {
keymap->names = calloc(1, sizeof(*keymap->names));
if (!keymap->names)
return BadAlloc;
darray_init(keymap->names->keys);
darray_init(keymap->names->key_aliases);
}
if ((which & XkbKTLevelNamesMask) && keymap) {
struct xkb_key_type * type;
darray_foreach(type, keymap->types) {
if (!type->level_names) {
type->level_names = calloc(type->num_levels,
sizeof(*type->level_names));
if (!type->level_names)
return BadAlloc;
}
}
}
if (which & XkbKeyNamesMask)
darray_resize0(keymap->names->keys, keymap->max_key_code + 1);
if (which & XkbKeyAliasesMask)
darray_resize0(keymap->names->key_aliases, nTotalAliases);
return Success;
}
static void
XkbcFreeNames(struct xkb_keymap *keymap)
free_names(struct xkb_keymap *keymap)
{
struct xkb_names * names;
struct xkb_key_type *type;
int i;
if (!keymap || !keymap->names)
return;
names = keymap->names;
darray_foreach(type, keymap->types) {
int j;
for (j = 0; j < type->num_levels; j++)
free(type->level_names[j]);
free(type->level_names);
type->level_names = NULL;
}
free(names->keycodes);
free(names->symbols);
free(names->keytypes);
free(names->compat);
for (i = 0; i < XkbNumVirtualMods; i++)
free(names->vmods[i]);
for (i = 0; i < XkbNumIndicators; i++)
free(names->indicators[i]);
for (i = 0; i < XkbNumKbdGroups; i++)
free(names->groups[i]);
free(keymap->vmod_names[i]);
darray_free(names->keys);
darray_free(names->key_aliases);
free(names);
keymap->names = NULL;
for (i = 0; i < XkbNumIndicators; i++)
free(keymap->indicator_names[i]);
for (i = 0; i < XkbNumKbdGroups; i++)
free(keymap->group_names[i]);
darray_free(keymap->key_names);
darray_free(keymap->key_aliases);
free(keymap->keycodes_section_name);
free(keymap->symbols_section_name);
free(keymap->types_section_name);
free(keymap->compat_section_name);
}
int
@ -281,7 +228,7 @@ XkbcFreeKeyboard(struct xkb_keymap *keymap)
free(keymap->behaviors);
free(keymap->vmodmap);
darray_free(keymap->sym_interpret);
XkbcFreeNames(keymap);
free_names(keymap);
XkbcFreeControls(keymap);
xkb_context_unref(keymap->ctx);
free(keymap);

View File

@ -29,10 +29,6 @@
#include "xkb-priv.h"
extern int
XkbcAllocNames(struct xkb_keymap *keymap, unsigned which,
size_t nTotalAliases);
extern int
XkbcAllocControls(struct xkb_keymap *keymap);

View File

@ -125,13 +125,13 @@ write_vmods(struct xkb_keymap *keymap, char **buf, size_t *size,
int i;
for (i = 0; i < XkbNumVirtualMods; i++) {
if (!keymap->names->vmods[i])
if (!keymap->vmod_names[i])
continue;
if (num_vmods == 0)
write_buf(keymap, buf, size, offset, "\t\tvirtual_modifiers ");
else
write_buf(keymap, buf, size, offset, ",");
write_buf(keymap, buf, size, offset, "%s", keymap->names->vmods[i]);
write_buf(keymap, buf, size, offset, "%s", keymap->vmod_names[i]);
num_vmods++;
}
@ -209,10 +209,10 @@ get_mod_mask_text(struct xkb_keymap *keymap, uint8_t real_mods,
continue;
if (ret[0] != '\0') {
strcpy(ret2, ret);
append_get_text("%s+%s", ret2, keymap->names->vmods[i]);
append_get_text("%s+%s", ret2, keymap->vmod_names[i]);
}
else {
append_get_text("%s", keymap->names->vmods[i]);
append_get_text("%s", keymap->vmod_names[i]);
}
}
@ -313,9 +313,9 @@ write_keycodes(struct xkb_keymap *keymap, char **buf, size_t *size,
struct xkb_key_alias *alias;
int i;
if (keymap->names->keycodes)
if (keymap->keycodes_section_name)
write_buf(keymap, buf, size, offset, "\txkb_keycodes \"%s\" {\n",
keymap->names->keycodes);
keymap->keycodes_section_name);
else
write_buf(keymap, buf, size, offset, "\txkb_keycodes {\n");
@ -325,25 +325,26 @@ write_keycodes(struct xkb_keymap *keymap, char **buf, size_t *size,
keymap->max_key_code);
for (key = keymap->min_key_code; key <= keymap->max_key_code; key++) {
if (darray_item(keymap->names->keys, key).name[0] == '\0')
if (darray_item(keymap->key_names, key).name[0] == '\0')
continue;
write_buf(keymap, buf, size, offset, "\t\t%6s = %d;\n",
XkbcKeyNameText(darray_item(keymap->names->keys, key).name),
XkbcKeyNameText(darray_item(keymap->key_names, key).name),
key);
}
for (i = 0; i < XkbNumIndicators; i++) {
if (!keymap->names->indicators[i])
if (!keymap->indicator_names[i])
continue;
write_buf(keymap, buf, size, offset, "\t\tindicator %d = \"%s\";\n",
i + 1, keymap->names->indicators[i]);
i + 1, keymap->indicator_names[i]);
}
darray_foreach(alias, keymap->names->key_aliases)
write_buf(keymap, buf, size, offset, "\t\talias %6s = %6s;\n",
XkbcKeyNameText(alias->alias),
XkbcKeyNameText(alias->real));
darray_foreach(alias, keymap->key_aliases)
write_buf(keymap, buf, size, offset, "\t\talias %6s = %6s;\n",
XkbcKeyNameText(alias->alias),
XkbcKeyNameText(alias->real));
write_buf(keymap, buf, size, offset, "\t};\n\n");
return true;
@ -356,9 +357,9 @@ write_types(struct xkb_keymap *keymap, char **buf, size_t *size,
int n;
struct xkb_key_type *type;
if (keymap->names->keytypes)
if (keymap->types_section_name)
write_buf(keymap, buf, size, offset, "\txkb_types \"%s\" {\n\n",
keymap->names->keytypes);
keymap->types_section_name);
else
write_buf(keymap, buf, size, offset, "\txkb_types {\n\n");
@ -412,7 +413,7 @@ write_indicator_map(struct xkb_keymap *keymap, char **buf, size_t *size,
struct xkb_indicator_map *led = &keymap->indicators[num];
write_buf(keymap, buf, size, offset, "\t\tindicator \"%s\" {\n",
keymap->names->indicators[num]);
keymap->indicator_names[num]);
if (led->which_groups) {
if (led->which_groups != XkbIM_UseEffective) {
@ -665,10 +666,10 @@ write_compat(struct xkb_keymap *keymap, char **buf, size_t *size,
int i;
struct xkb_sym_interpret *interp;
if (keymap->names->compat)
if (keymap->compat_section_name)
write_buf(keymap, buf, size, offset,
"\txkb_compatibility \"%s\" {\n\n",
keymap->names->compat);
keymap->compat_section_name);
else
write_buf(keymap, buf, size, offset, "\txkb_compatibility {\n\n");
@ -695,7 +696,7 @@ write_compat(struct xkb_keymap *keymap, char **buf, size_t *size,
if (interp->virtual_mod != XkbNoModifier) {
write_buf(keymap, buf, size, offset,
"\t\t\tvirtualModifier= %s;\n",
keymap->names->vmods[interp->virtual_mod]);
keymap->vmod_names[interp->virtual_mod]);
}
if (interp->match & XkbSI_LevelOneOnly)
@ -783,18 +784,18 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
int group, tmp;
bool showActions;
if (keymap->names->symbols)
if (keymap->symbols_section_name)
write_buf(keymap, buf, size, offset, "\txkb_symbols \"%s\" {\n\n",
keymap->names->symbols);
keymap->symbols_section_name);
else
write_buf(keymap, buf, size, offset, "\txkb_symbols {\n\n");
for (tmp = group = 0; group < XkbNumKbdGroups; group++) {
if (!keymap->names->groups[group])
if (!keymap->group_names[group])
continue;
write_buf(keymap, buf, size, offset,
"\t\tname[group%d]=\"%s\";\n", group + 1,
keymap->names->groups[group]);
keymap->group_names[group]);
tmp++;
}
if (tmp > 0)
@ -807,7 +808,7 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
continue;
write_buf(keymap, buf, size, offset, "\t\tkey %6s {",
XkbcKeyNameText(darray_item(keymap->names->keys, key).name));
XkbcKeyNameText(darray_item(keymap->key_names, key).name));
if (keymap->explicit) {
if ((keymap->explicit[key] & XkbExplicitKeyTypesMask)) {
bool multi_type = false;
@ -934,7 +935,7 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size,
write_buf(keymap, buf, size, offset,
"\t\tmodifier_map %s { %s };\n",
get_mod_index_text(mod),
XkbcKeyNameText(darray_item(keymap->names->keys,
XkbcKeyNameText(darray_item(keymap->key_names,
key).name));
}
}

View File

@ -60,7 +60,7 @@ xkb_map_num_mods(struct xkb_keymap *keymap)
xkb_mod_index_t i;
for (i = 0; i < XkbNumVirtualMods; i++)
if (!keymap->names->vmods[i])
if (!keymap->vmod_names[i])
break;
/* We always have all the core modifiers (for now), plus any virtual
@ -100,7 +100,7 @@ xkb_map_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx)
}
/* If that fails, try to find a virtual mod name. */
return keymap->names->vmods[idx - Mod5MapIndex];
return keymap->vmod_names[idx - Mod5MapIndex];
}
/**
@ -128,8 +128,8 @@ xkb_map_mod_get_index(struct xkb_keymap *keymap, const char *name)
if (strcasecmp(name, "Mod5") == 0)
return Mod5MapIndex;
for (i = 0; i < XkbNumVirtualMods && keymap->names->vmods[i]; i++) {
if (strcasecmp(name, keymap->names->vmods[i]) == 0)
for (i = 0; i < XkbNumVirtualMods && keymap->vmod_names[i]; i++) {
if (strcasecmp(name, keymap->vmod_names[i]) == 0)
return i + Mod5MapIndex;
}
@ -161,7 +161,7 @@ xkb_map_group_get_name(struct xkb_keymap *keymap, xkb_group_index_t idx)
if (idx >= xkb_map_num_groups(keymap))
return NULL;
return keymap->names->groups[idx];
return keymap->group_names[idx];
}
/**
@ -174,7 +174,7 @@ xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name)
xkb_group_index_t i;
for (i = 0; i < num_groups; i++) {
if (strcasecmp(keymap->names->groups[i], name) == 0)
if (strcasecmp(keymap->group_names[i], name) == 0)
return i;
}
@ -217,7 +217,7 @@ xkb_map_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx)
if (idx >= xkb_map_num_leds(keymap))
return NULL;
return keymap->names->indicators[idx];
return keymap->indicator_names[idx];
}
/**
@ -230,7 +230,7 @@ xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name)
xkb_led_index_t i;
for (i = 0; i < num_leds; i++) {
if (strcasecmp(keymap->names->indicators[i], name) == 0)
if (strcasecmp(keymap->indicator_names[i], name) == 0)
return i;
}

View File

@ -56,9 +56,9 @@ XkbcVModIndexText(struct xkb_keymap *keymap, unsigned ndx)
char buf[20];
if (ndx >= XkbNumVirtualMods)
tmp = "illegal";
else if (keymap && keymap->names)
tmp = keymap->names->vmods[ndx];
tmp = "illegal";
else
tmp = keymap->vmod_names[ndx];
if (!tmp) {
snprintf(buf, sizeof(buf) - 1, "%d", ndx);

View File

@ -293,20 +293,6 @@ struct xkb_key_alias {
char alias[XkbKeyNameLength];
};
struct xkb_names {
char *keycodes;
char *symbols;
char *keytypes;
char *compat;
char *vmods[XkbNumVirtualMods];
char *indicators[XkbNumIndicators];
char *groups[XkbNumKbdGroups];
darray(struct xkb_key_name) keys;
darray(struct xkb_key_alias) key_aliases;
};
struct xkb_controls {
/* unsigned char groups_wrap; */
/* struct xkb_mods internal; */
@ -335,7 +321,11 @@ struct xkb_keymap {
xkb_keycode_t max_key_code;
struct xkb_controls * ctrls;
struct xkb_names * names;
/* key -> key name mapping */
darray(struct xkb_key_name) key_names;
/* aliases in no particular order */
darray(struct xkb_key_alias) key_aliases;
/* key -> explicit flags mapping */
unsigned char *explicit;
@ -349,12 +339,14 @@ struct xkb_keymap {
/* key -> mod mapping */
unsigned char *modmap;
/* vmod -> mod mapping */
uint32_t vmods[XkbNumVirtualMods];
/* key -> vmod mapping */
uint32_t *vmodmap;
/* vmod -> mod mapping */
uint32_t vmods[XkbNumVirtualMods];
char *vmod_names[XkbNumVirtualMods];
struct xkb_mods groups[XkbNumKbdGroups];
char *group_names[XkbNumKbdGroups];
/* key -> actions mapping: acts[key_acts[keycode]] */
darray(union xkb_action) acts;
@ -364,6 +356,12 @@ struct xkb_keymap {
struct xkb_behavior *behaviors;
struct xkb_indicator_map indicators[XkbNumIndicators];
char *indicator_names[XkbNumIndicators];
char *keycodes_section_name;
char *symbols_section_name;
char *types_section_name;
char *compat_section_name;
};
#define XkbNumGroups(g) ((g) & 0x0f)

View File

@ -145,12 +145,11 @@ ApplyAliases(struct xkb_keymap *keymap, AliasInfo ** info_in)
struct xkb_key_alias *old, *a;
AliasInfo *info;
int nNew, nOld;
int status;
if (*info_in == NULL)
return true;
nOld = (keymap->names ? darray_size(keymap->names->key_aliases) : 0);
old = (keymap->names ? &darray_item(keymap->names->key_aliases, 0) : NULL);
nOld = (keymap ? darray_size(keymap->key_aliases) : 0);
old = (keymap ? &darray_item(keymap->key_aliases, 0) : NULL);
for (nNew = 0, info = *info_in; info != NULL;
info = (AliasInfo *) info->def.next) {
unsigned long lname;
@ -200,14 +199,10 @@ ApplyAliases(struct xkb_keymap *keymap, AliasInfo ** info_in)
return true;
}
status = XkbcAllocNames(keymap, XkbKeyAliasesMask, nOld + nNew);
if (status != Success) {
WSGO("Allocation failure in ApplyAliases\n");
return false;
}
a = keymap->names ? &darray_item(keymap->names->key_aliases, nOld) : NULL;
for (info = *info_in; info != NULL; info =
(AliasInfo *) info->def.next) {
darray_resize0(keymap->key_aliases, nOld + nNew);
a = keymap ? &darray_item(keymap->key_aliases, nOld) : NULL;
for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next) {
if (info->alias[0] != '\0') {
strncpy(a->alias, info->alias, XkbKeyNameLength);
strncpy(a->real, info->real, XkbKeyNameLength);

View File

@ -739,11 +739,8 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
darray_init(keymap->sym_interpret);
darray_growalloc(keymap->sym_interpret, info.nInterps);
if (info.name) {
if (XkbcAllocNames(keymap, 0, 0) != Success)
goto err_info;
keymap->names->compat = strdup(info.name);
}
if (info.name)
keymap->compat_section_name = strdup(info.name);
if (info.nInterps > 0) {
CopyInterps(&info, keymap, true, XkbSI_Exactly);

View File

@ -338,36 +338,34 @@ BindIndicators(struct xkb_keymap *keymap, LEDInfo *unbound)
int i;
LEDInfo *led, *next, *last;
if (keymap->names != NULL) {
for (led = unbound; led != NULL; led = (LEDInfo *) led->defs.next) {
if (led->indicator == _LED_NotBound) {
for (i = 0; i < XkbNumIndicators; i++) {
if (keymap->names->indicators[i] &&
strcmp(keymap->names->indicators[i],
xkb_atom_text(keymap->ctx, led->name)) == 0) {
led->indicator = i + 1;
break;
}
for (led = unbound; led != NULL; led = (LEDInfo *) led->defs.next) {
if (led->indicator == _LED_NotBound) {
for (i = 0; i < XkbNumIndicators; i++) {
if (keymap->indicator_names[i] &&
strcmp(keymap->indicator_names[i],
xkb_atom_text(keymap->ctx, led->name)) == 0) {
led->indicator = i + 1;
break;
}
}
}
for (led = unbound; led != NULL; led = (LEDInfo *) led->defs.next) {
}
for (led = unbound; led != NULL; led = (LEDInfo *) led->defs.next) {
if (led->indicator == _LED_NotBound) {
for (i = 0; i < XkbNumIndicators; i++) {
if (keymap->indicator_names[i] == NULL) {
keymap->indicator_names[i] =
xkb_atom_strdup(keymap->ctx, led->name);
led->indicator = i + 1;
break;
}
}
if (led->indicator == _LED_NotBound) {
for (i = 0; i < XkbNumIndicators; i++) {
if (keymap->names->indicators[i] == NULL) {
keymap->names->indicators[i] =
xkb_atom_strdup(keymap->ctx, led->name);
led->indicator = i + 1;
break;
}
}
if (led->indicator == _LED_NotBound) {
ERROR("No unnamed indicators found\n");
ACTION
("Virtual indicator map \"%s\" not bound\n",
xkb_atom_text(keymap->ctx, led->name));
continue;
}
ERROR("No unnamed indicators found\n");
ACTION("Virtual indicator map \"%s\" not bound\n",
xkb_atom_text(keymap->ctx, led->name));
continue;
}
}
}
@ -378,11 +376,9 @@ BindIndicators(struct xkb_keymap *keymap, LEDInfo *unbound)
free(led);
}
else {
if ((keymap->names != NULL) &&
(strcmp(keymap->names->indicators[led->indicator - 1],
xkb_atom_text(keymap->ctx, led->name)) != 0)) {
const char *old =
keymap->names->indicators[led->indicator - 1];
if (strcmp(keymap->indicator_names[led->indicator - 1],
xkb_atom_text(keymap->ctx, led->name)) != 0) {
const char *old = keymap->indicator_names[led->indicator - 1];
ERROR("Multiple names bound to indicator %d\n",
(unsigned int) led->indicator);
ACTION("Using %s, ignoring %s\n", old,
@ -424,11 +420,6 @@ CopyIndicatorMapDefs(struct xkb_keymap *keymap, LEDInfo *leds)
LEDInfo *led, *next;
LEDInfo *unbound = NULL, *last = NULL;
if (XkbcAllocNames(keymap, XkbIndicatorNamesMask, 0) != Success) {
WSGO("Couldn't allocate names\n");
ACTION("Indicator names may be incorrect\n");
}
for (led = leds; led != NULL; led = next) {
next = (LEDInfo *) led->defs.next;
if ((led->groups != 0) && (led->which_groups == 0))
@ -454,11 +445,9 @@ CopyIndicatorMapDefs(struct xkb_keymap *keymap, LEDInfo *leds)
im->mods.real_mods = led->real_mods;
im->mods.vmods = led->vmods;
im->ctrls = led->ctrls;
if (keymap->names != NULL) {
free(keymap->names->indicators[led->indicator - 1]);
keymap->names->indicators[led->indicator - 1] =
xkb_atom_strdup(keymap->ctx, led->name);
}
free(keymap->indicator_names[led->indicator - 1]);
keymap->indicator_names[led->indicator - 1] =
xkb_atom_strdup(keymap->ctx, led->name);
free(led);
}
}

View File

@ -732,6 +732,7 @@ bool
CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge)
{
xkb_keycode_t i;
KeyNamesInfo info; /* contains all the info after parsing */
InitKeyNamesInfo(&info, file->id);
@ -753,26 +754,20 @@ CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
else
keymap->max_key_code = info.computedMax;
if (XkbcAllocNames(keymap, XkbKeyNamesMask | XkbIndicatorNamesMask, 0)
== Success) {
uint64_t i;
for (i = info.computedMin; i <= info.computedMax; i++)
LongToKeyName(darray_item(info.names, i),
darray_item(keymap->names->keys, i).name);
if (info.name)
keymap->names->keycodes = strdup(info.name);
}
else {
WSGO("Cannot create struct xkb_names in CompileKeycodes\n");
goto err_info;
}
darray_resize0(keymap->key_names, keymap->max_key_code + 1);
for (i = info.computedMin; i <= info.computedMax; i++)
LongToKeyName(darray_item(info.names, i),
darray_item(keymap->key_names, i).name);
if (info.name)
keymap->keycodes_section_name = strdup(info.name);
if (info.leds) {
IndicatorNameInfo *ii;
for (ii = info.leds; ii; ii = (IndicatorNameInfo *) ii->defs.next) {
free(keymap->names->indicators[ii->ndx - 1]);
keymap->names->indicators[ii->ndx - 1] =
free(keymap->indicator_names[ii->ndx - 1]);
keymap->indicator_names[ii->ndx - 1] =
xkb_atom_strdup(keymap->ctx, ii->name);
}
}

View File

@ -1152,11 +1152,8 @@ CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
if (info.errorCount != 0)
goto err_info;
if (info.name) {
if (XkbcAllocNames(keymap, 0, 0) != Success)
goto err_info;
keymap->names->keytypes = strdup(info.name);
}
if (info.name)
keymap->types_section_name = strdup(info.name);
i = info.nTypes;
if ((info.stdPresent & XkbOneLevelMask) == 0)

View File

@ -219,18 +219,17 @@ FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
{
unsigned n;
if (start_from < keymap->min_key_code) {
if (start_from < keymap->min_key_code)
start_from = keymap->min_key_code;
}
else if (start_from > keymap->max_key_code) {
else if (start_from > keymap->max_key_code)
return false;
}
*kc_rtrn = 0; /* some callers rely on this */
if (keymap && keymap->names && !darray_empty(keymap->names->keys)) {
if (!darray_empty(keymap->key_names)) {
for (n = start_from; n <= keymap->max_key_code; n++) {
unsigned long tmp;
tmp = KeyNameToLong(darray_item(keymap->names->keys, n).name);
tmp = KeyNameToLong(darray_item(keymap->key_names, n).name);
if (tmp == name) {
*kc_rtrn = n;
return true;
@ -243,23 +242,16 @@ FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
create, 0);
}
}
if (create) {
if ((!keymap->names) || darray_empty(keymap->names->keys)) {
if (XkbcAllocNames(keymap, XkbKeyNamesMask, 0) != Success) {
if (warningLevel > 0) {
WARN("Couldn't allocate key names in FindNamedKey\n");
ACTION("Key \"%s\" not automatically created\n",
longText(name));
}
return false;
}
}
darray_resize0(keymap->key_names, keymap->max_key_code + 1);
/* Find first unused keycode and store our key here */
for (n = keymap->min_key_code; n <= keymap->max_key_code; n++) {
if (darray_item(keymap->names->keys, n).name[0] == '\0') {
if (darray_item(keymap->key_names, n).name[0] == '\0') {
char buf[XkbKeyNameLength + 1];
LongToKeyName(name, buf);
memcpy(darray_item(keymap->names->keys, n).name, buf,
memcpy(darray_item(keymap->key_names, n).name, buf,
XkbKeyNameLength);
*kc_rtrn = n;
return true;
@ -276,15 +268,14 @@ FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
char name[XkbKeyNameLength + 1];
struct xkb_key_alias *a;
if (keymap && keymap->names) {
LongToKeyName(lname, name);
name[XkbKeyNameLength] = '\0';
darray_foreach(a, keymap->names->key_aliases) {
if (strncmp(name, a->alias, XkbKeyNameLength) == 0) {
*real_name = KeyNameToLong(a->real);
return true;
}
LongToKeyName(lname, name);
name[XkbKeyNameLength] = '\0';
darray_foreach(a, keymap->key_aliases) {
if (strncmp(name, a->alias, XkbKeyNameLength) == 0) {
*real_name = KeyNameToLong(a->real);
return true;
}
}
return false;
}

View File

@ -1917,13 +1917,6 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
if (info.errorCount != 0)
goto err_info;
/* alloc memory in the xkb struct */
if (XkbcAllocNames(keymap, XkbGroupNamesMask, 0) != Success) {
WSGO("Can not allocate names in CompileSymbols\n");
ACTION("Symbols not added\n");
goto err_info;
}
darray_resize0(keymap->key_sym_map, keymap->max_key_code + 1);
keymap->modmap = calloc(keymap->max_key_code + 1,
sizeof(*keymap->modmap));
@ -1956,16 +1949,16 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
}
if (info.name)
keymap->names->symbols = strdup(info.name);
keymap->symbols_section_name = strdup(info.name);
/* now copy info into xkb. */
ApplyAliases(keymap, &info.aliases);
for (i = 0; i < XkbNumKbdGroups; i++) {
if (info.groupNames[i] != XKB_ATOM_NONE) {
free(keymap->names->groups[i]);
keymap->names->groups[i] = xkb_atom_strdup(keymap->ctx,
info.groupNames[i]);
free(keymap->group_names[i]);
keymap->group_names[i] = xkb_atom_strdup(keymap->ctx,
info.groupNames[i]);
}
}
@ -1980,12 +1973,12 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
if (warningLevel > 3) {
for (i = keymap->min_key_code; i <= keymap->max_key_code; i++) {
if (darray_item(keymap->names->keys, i).name[0] == '\0')
if (darray_item(keymap->key_names, i).name[0] == '\0')
continue;
if (XkbKeyNumGroups(keymap, i) < 1) {
char buf[5];
memcpy(buf, darray_item(keymap->names->keys, i).name, 4);
memcpy(buf, darray_item(keymap->key_names, i).name, 4);
buf[4] = '\0';
WARN("No symbols defined for <%s> (keycode %d)\n", buf, i);
}

View File

@ -36,24 +36,17 @@ InitVModInfo(VModInfo *info, struct xkb_keymap *keymap)
void
ClearVModInfo(VModInfo *info, struct xkb_keymap *keymap)
{
int i;
int i, bit;
info->newlyDefined = info->defined = info->available = 0;
if (XkbcAllocNames(keymap, 0, 0) != Success)
return;
for (i = 0; i < XkbNumVirtualMods; i++)
keymap->vmods[i] = XkbNoModifierMask;
info->keymap = keymap;
if (keymap && keymap->names) {
int bit;
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if (keymap->names->vmods[i] != NULL)
info->defined |= bit;
}
}
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
if (keymap->vmod_names[i])
info->defined |= bit;
}
/***====================================================================***/
@ -73,13 +66,12 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
{
int i, bit, nextFree;
ExprResult mod;
struct xkb_names *names = keymap->names;
for (i = 0, bit = 1, nextFree = -1; i < XkbNumVirtualMods; i++, bit <<=
1) {
if (info->defined & bit) {
if (names->vmods[i] &&
strcmp(names->vmods[i],
if (keymap->vmod_names[i] &&
strcmp(keymap->vmod_names[i],
xkb_atom_text(keymap->ctx, stmt->name)) == 0) { /* already defined */
info->available |= bit;
if (stmt->value == NULL)
@ -121,7 +113,7 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
info->defined |= (1 << nextFree);
info->newlyDefined |= (1 << nextFree);
info->available |= (1 << nextFree);
names->vmods[nextFree] = xkb_atom_strdup(keymap->ctx, stmt->name);
keymap->vmod_names[nextFree] = xkb_atom_strdup(keymap->ctx, stmt->name);
if (stmt->value == NULL)
return true;
if (ExprResolveModMask(keymap->ctx, stmt->value, &mod)) {
@ -134,7 +126,7 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
}
/**
* Returns the index of the given modifier in the keymap->names->vmods array.
* Returns the index of the given modifier in the keymap->vmod_names array.
*
* @param keymap Pointer to the xkb data structure.
* @param field The Atom of the modifier's name (e.g. Atom for LAlt)
@ -151,21 +143,21 @@ LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
int i;
const char *name = xkb_atom_text(keymap->ctx, field);
if ((keymap == NULL) || (keymap->names == NULL) || (type != TypeInt)) {
if (type != TypeInt)
return false;
}
/* For each named modifier, get the name and compare it to the one passed
* in. If we get a match, return the index of the modifier.
* The order of modifiers is the same as in the virtual_modifiers line in
* the xkb_types section.
*/
for (i = 0; i < XkbNumVirtualMods; i++) {
if (keymap->names->vmods[i] &&
strcmp(keymap->names->vmods[i], name) == 0) {
for (i = 0; i < XkbNumVirtualMods; i++)
if (keymap->vmod_names[i] &&
strcmp(keymap->vmod_names[i], name) == 0) {
val_rtrn->uval = i;
return true;
}
}
return false;
}
@ -211,14 +203,12 @@ bool
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
ExprResult *val_rtrn, VModInfo *info)
{
struct xkb_names *names = keymap->names;
if (def->op == ExprIdent) {
int i, bit;
const char *name = xkb_atom_text(keymap->ctx, def->value.str);
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if ((info->available & bit) && names->vmods[i] &&
strcmp(names->vmods[i], name) == 0) {
if ((info->available & bit) && keymap->vmod_names[i] &&
strcmp(keymap->vmod_names[i], name) == 0) {
val_rtrn->uval = i;
return true;
}