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>
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
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 701441c..72db22b 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -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)
diff --git a/src/keymap.c b/src/keymap.c
index 43e43dd..a36a404 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -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;
diff --git a/src/keymap.h b/src/keymap.h
index af47e4b..48f2da0 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -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];
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 05cf10e..7ef5722 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -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))