keymap, symbols: use darray for num_groups

Instead of using a static array of size XKB_NUM_GROUPS, because we want
to get rid of this limit.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-09-23 22:12:43 +02:00 committed by Daniel Stone
parent 79bbf6f758
commit d941bc0c03
4 changed files with 60 additions and 30 deletions

View File

@ -599,6 +599,7 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
{
struct xkb_key *key;
xkb_layout_index_t group, tmp;
xkb_atom_t *group_name;
bool showActions;
if (keymap->symbols_section_name)
@ -607,12 +608,13 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
else
write_buf(buf, "\txkb_symbols {\n\n");
for (tmp = group = 0; group < XKB_NUM_GROUPS; group++) {
if (!keymap->group_names[group])
tmp = 0;
darray_enumerate(group, group_name, keymap->group_names) {
if (!*group_name)
continue;
write_buf(buf,
"\t\tname[group%d]=\"%s\";\n", group + 1,
xkb_atom_text(keymap->ctx, keymap->group_names[group]));
xkb_atom_text(keymap->ctx, *group_name));
tmp++;
}
if (tmp > 0)

View File

@ -104,6 +104,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
darray_free(keymap->keys);
darray_free(keymap->sym_interpret);
darray_free(keymap->key_aliases);
darray_free(keymap->group_names);
free(keymap->keycodes_section_name);
free(keymap->symbols_section_name);
free(keymap->types_section_name);
@ -192,10 +193,11 @@ xkb_keymap_num_layouts(struct xkb_keymap *keymap)
XKB_EXPORT const char *
xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx)
{
if (idx >= xkb_keymap_num_layouts(keymap))
if (idx >= xkb_keymap_num_layouts(keymap) ||
idx >= darray_size(keymap->group_names))
return NULL;
return xkb_atom_text(keymap->ctx, keymap->group_names[idx]);
return xkb_atom_text(keymap->ctx, darray_item(keymap->group_names, idx));
}
/**
@ -204,15 +206,15 @@ xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx)
XKB_EXPORT xkb_layout_index_t
xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name)
{
xkb_layout_index_t num_groups = xkb_keymap_num_layouts(keymap);
xkb_atom_t atom = xkb_atom_lookup(keymap->ctx, name);
xkb_atom_t *group_name;
xkb_layout_index_t i;
if (atom == XKB_ATOM_NONE)
return XKB_LAYOUT_INVALID;
for (i = 0; i < num_groups; i++)
if (keymap->group_names[i] == atom)
darray_enumerate(i, group_name, keymap->group_names)
if (*group_name == atom)
return i;
return XKB_LAYOUT_INVALID;

View File

@ -336,6 +336,8 @@ struct xkb_key {
xkb_keysym_t *syms;
};
typedef darray(xkb_atom_t) darray_xkb_atom_t;
/* Common keyboard description structure */
struct xkb_keymap {
struct xkb_context *ctx;
@ -365,7 +367,7 @@ struct xkb_keymap {
/* Number of groups in the key with the most groups. */
xkb_layout_index_t num_groups;
xkb_atom_t group_names[XKB_NUM_GROUPS];
darray_xkb_atom_t group_names;
struct xkb_indicator_map indicators[XKB_NUM_INDICATORS];

View File

@ -167,7 +167,7 @@ typedef struct _SymbolsInfo {
KeyInfo dflt;
VModInfo vmods;
ActionsInfo *actions;
xkb_atom_t group_names[XKB_NUM_GROUPS];
darray_xkb_atom_t group_names;
darray(ModMapEntry) modMaps;
struct xkb_keymap *keymap;
@ -195,6 +195,7 @@ ClearSymbolsInfo(SymbolsInfo * info)
darray_foreach(keyi, info->keys)
ClearKeyInfo(keyi);
darray_free(info->keys);
darray_free(info->group_names);
darray_free(info->modMaps);
ClearKeyInfo(&info->dflt);
}
@ -549,22 +550,33 @@ MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
unsigned int i;
KeyInfo *keyi;
ModMapEntry *mm;
xkb_atom_t *group_name;
xkb_layout_index_t group_names_in_both;
if (from->errorCount > 0) {
into->errorCount += from->errorCount;
return;
}
if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
}
for (i = 0; i < XKB_NUM_GROUPS; i++) {
if (from->group_names[i] != XKB_ATOM_NONE) {
if ((merge != MERGE_AUGMENT) ||
(into->group_names[i] == XKB_ATOM_NONE))
into->group_names[i] = from->group_names[i];
}
group_names_in_both = MIN(darray_size(into->group_names),
darray_size(from->group_names));
for (i = 0; i < group_names_in_both; i++) {
if (!darray_item(from->group_names, i))
continue;
if (merge == MERGE_AUGMENT && darray_item(into->group_names, i))
continue;
darray_item(into->group_names, i) = darray_item(from->group_names, i);
}
/* If @from has more, get them as well. */
darray_foreach_from(group_name, from->group_names, group_names_in_both)
darray_append(into->group_names, *group_name);
darray_foreach(keyi, from->keys) {
merge = (merge == MERGE_DEFAULT ? keyi->merge : merge);
@ -768,14 +780,20 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
leveli->sym_index + j),
&darray_item(groupi->syms,
leveli->sym_index + j))) {
const char *group_name = "unnamed";
if (ndx < darray_size(info->group_names) &&
darray_item(info->group_names, ndx))
group_name = xkb_atom_text(info->keymap->ctx,
darray_item(info->group_names,
ndx));
log_warn(info->keymap->ctx,
"Could not resolve keysym %s for key %s, group %u (%s), level %u\n",
darray_item(value->value.list.syms, i),
LongKeyNameText(keyi->name),
ndx + 1,
xkb_atom_text(info->keymap->ctx,
info->group_names[ndx]),
nSyms);
ndx + 1, group_name, nSyms);
leveli->sym_index = 0;
leveli->num_syms = 0;
break;
@ -1033,7 +1051,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
static int
SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
{
xkb_layout_index_t grp;
xkb_layout_index_t grp, grp_to_use;
xkb_atom_t name;
if (!arrayNdx) {
@ -1057,18 +1075,26 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
return false;
}
if (info->explicit_group == XKB_LAYOUT_INVALID)
info->group_names[grp - 1] = name;
else if (grp - 1 == 0)
info->group_names[info->explicit_group] = name;
else
grp_to_use = XKB_LAYOUT_INVALID;
if (info->explicit_group == XKB_LAYOUT_INVALID) {
grp_to_use = grp - 1;
}
else if (grp - 1 == 0) {
grp_to_use = info->explicit_group;
}
else {
log_warn(info->keymap->ctx,
"An explicit group was specified for the '%s' map, "
"but it provides a name for a group other than Group1 (%d); "
"Ignoring group name '%s'\n",
info->name, grp,
xkb_atom_text(info->keymap->ctx, name));
return false;
}
if (grp_to_use >= darray_size(info->group_names))
darray_resize0(info->group_names, grp_to_use + 1);
darray_item(info->group_names, grp_to_use) = name;
return true;
}
@ -1672,14 +1698,12 @@ CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info)
{
KeyInfo *keyi;
ModMapEntry *mm;
xkb_layout_index_t i;
struct xkb_key *key;
keymap->symbols_section_name = strdup_safe(info->name);
for (i = 0; i < XKB_NUM_GROUPS; i++)
if (info->group_names[i] != XKB_ATOM_NONE)
keymap->group_names[i] = info->group_names[i];
keymap->group_names = info->group_names;
darray_init(info->group_names);
darray_foreach(keyi, info->keys)
if (!CopySymbolsDef(info, keyi))