Full support for multiple keysyms per level

Which also involved moving the global symbol map to be per-key instead;
this should probably be split out into a separate commit.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
master
Daniel Stone 2012-03-29 16:31:09 +01:00
parent 9cdc1990fa
commit 93ce9c7d4f
10 changed files with 519 additions and 249 deletions

View File

@ -89,6 +89,8 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define False 0 #define False 0
#endif #endif
typedef int Bool;
/* From XKM.h */ /* From XKM.h */
#define XkmFileVersion 15 #define XkmFileVersion 15
@ -289,7 +291,10 @@ struct xkb_sym_map {
unsigned char kt_index[XkbNumKbdGroups]; unsigned char kt_index[XkbNumKbdGroups];
unsigned char group_info; unsigned char group_info;
unsigned char width; unsigned char width;
unsigned short offset; int *sym_index; /* per level/group index into 'syms' */
unsigned int *num_syms; /* per level/group */
xkb_keysym_t *syms;
unsigned int size_syms; /* size of 'syms' */
}; };
#define XkbNumGroups(g) ((g)&0x0f) #define XkbNumGroups(g) ((g)&0x0f)
@ -303,12 +308,7 @@ struct xkb_client_map {
unsigned char size_types; unsigned char size_types;
unsigned char num_types; unsigned char num_types;
struct xkb_key_type * types; struct xkb_key_type * types;
uint32_t size_syms;
uint32_t num_syms;
xkb_keysym_t *syms;
struct xkb_sym_map * key_sym_map; struct xkb_sym_map * key_sym_map;
unsigned char *modmap; unsigned char *modmap;
}; };
@ -415,14 +415,16 @@ struct xkb_desc {
#define XkbKeyGroupsWidth(d,k) ((d)->map->key_sym_map[k].width) #define XkbKeyGroupsWidth(d,k) ((d)->map->key_sym_map[k].width)
#define XkbKeyTypeIndex(d,k,g) ((d)->map->key_sym_map[k].kt_index[g&0x3]) #define XkbKeyTypeIndex(d,k,g) ((d)->map->key_sym_map[k].kt_index[g&0x3])
#define XkbKeyType(d,k,g) (&(d)->map->types[XkbKeyTypeIndex(d,k,g)]) #define XkbKeyType(d,k,g) (&(d)->map->types[XkbKeyTypeIndex(d,k,g)])
#define XkbKeyNumSyms(d,k) (XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k)) #define XkbKeyNumSyms(d,k,g,sl) \
#define XkbKeySymsOffset(d,k) ((d)->map->key_sym_map[k].offset) ((d)->map->key_sym_map[k].num_syms[(g*XkbKeyGroupsWidth(d,k))+sl])
#define XkbKeySymsPtr(d,k) (&(d)->map->syms[XkbKeySymsOffset(d,k)]) #define XkbKeySym(d,k,n) (&(d)->map->key_sym_map[k].syms[n])
#define XkbKeySym(d,k,n) (XkbKeySymsPtr(d,k)[n]) #define XkbKeySymOffset(d,k,g,sl) \
#define XkbKeySymEntry(d,k,sl,g) \ ((d)->map->key_sym_map[k].sym_index[(g*XkbKeyGroupsWidth(d,k))+sl])
(XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl)))) #define XkbKeySymEntry(d,k,g,sl) \
(XkbKeySym(d,k,XkbKeySymOffset(d,k,g,sl)))
#define XkbKeyHasActions(d,k) ((d)->server->key_acts[k]!=0) #define XkbKeyHasActions(d,k) ((d)->server->key_acts[k]!=0)
#define XkbKeyNumActions(d,k) (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1) #define XkbKeyNumActions(d,k) \
(XkbKeyHasActions(d,k)?(XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k)):1)
#define XkbKeyActionsPtr(d,k) (&(d)->server->acts[(d)->server->key_acts[k]]) #define XkbKeyActionsPtr(d,k) (&(d)->server->acts[(d)->server->key_acts[k]])
#define XkbKeyAction(d,k,n) \ #define XkbKeyAction(d,k,n) \
(XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL) (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)

View File

@ -82,34 +82,17 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
} }
if (which & XkbKeySymsMask) { if (which & XkbKeySymsMask) {
int nKeys = XkbNumKeys(xkb);
if (!map->syms) {
map->size_syms = (nKeys * 15) / 10;
map->syms = uTypedCalloc(map->size_syms, xkb_keysym_t);
if (!map->syms) {
map->size_syms = 0;
return BadAlloc;
}
map->num_syms = 1;
map->syms[0] = XKB_KEYSYM_NO_SYMBOL;
}
if (!map->key_sym_map) { if (!map->key_sym_map) {
i = xkb->max_key_code + 1; map->key_sym_map = uTypedCalloc(xkb->max_key_code + 1,
map->key_sym_map = uTypedCalloc(i, struct xkb_sym_map); struct xkb_sym_map);
if (!map->key_sym_map) if (!map->key_sym_map)
return BadAlloc; return BadAlloc;
} }
} }
if (which & XkbModifierMapMask) { if (which & XkbModifierMapMask) {
if (!xkb_keymap_keycode_range_is_legal(xkb))
return BadMatch;
if (!map->modmap) { if (!map->modmap) {
i = xkb->max_key_code + 1; map->modmap = uTypedCalloc(xkb->max_key_code + 1, unsigned char);
map->modmap = uTypedCalloc(i, unsigned char);
if (!map->modmap) if (!map->modmap)
return BadAlloc; return BadAlloc;
} }
@ -258,70 +241,25 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into)
return Success; return Success;
} }
xkb_keysym_t * Bool
XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key, XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key,
unsigned int needed) unsigned int needed)
{ {
uint32_t i, nSyms, nKeySyms; if (xkb->map->key_sym_map[key].size_syms >= needed)
uint32_t nOldSyms; return True;
xkb_keysym_t *newSyms;
if (needed == 0) { xkb->map->key_sym_map[key].syms =
xkb->map->key_sym_map[key].offset = 0; uTypedRecalloc(xkb->map->key_sym_map[key].syms,
return xkb->map->syms; xkb->map->key_sym_map[key].size_syms,
needed,
xkb_keysym_t);
if (!xkb->map->key_sym_map[key].syms) {
xkb->map->key_sym_map[key].size_syms = 0;
return False;
} }
xkb->map->key_sym_map[key].size_syms = needed;
nOldSyms = XkbKeyNumSyms(xkb, key); return True;
if (nOldSyms >= needed)
return XkbKeySymsPtr(xkb, key);
if (xkb->map->size_syms - xkb->map->num_syms >= needed) {
if (nOldSyms > 0)
memcpy(&xkb->map->syms[xkb->map->num_syms],
XkbKeySymsPtr(xkb, key), nOldSyms * sizeof(xkb_keysym_t));
if ((needed - nOldSyms) > 0)
memset(&xkb->map->syms[xkb->map->num_syms + XkbKeyNumSyms(xkb, key)],
0, (needed - nOldSyms) * sizeof(xkb_keysym_t));
xkb->map->key_sym_map[key].offset = xkb->map->num_syms;
xkb->map->num_syms += needed;
return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
}
xkb->map->size_syms += (needed > 32 ? needed : 32);
newSyms = uTypedCalloc(xkb->map->size_syms, xkb_keysym_t);
if (!newSyms)
return NULL;
newSyms[0] = XKB_KEYSYM_NO_SYMBOL;
nSyms = 1;
for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
uint32_t nCopy;
nCopy = nKeySyms = XkbKeyNumSyms(xkb, i);
if ((nKeySyms == 0) && (i != key))
continue;
if (i == key)
nKeySyms = needed;
if (nCopy != 0)
memcpy(&newSyms[nSyms], XkbKeySymsPtr(xkb, i),
nCopy * sizeof(xkb_keysym_t));
if (nKeySyms > nCopy)
memset(&newSyms[nSyms + nCopy], 0,
(nKeySyms - nCopy) * sizeof(xkb_keysym_t));
xkb->map->key_sym_map[i].offset = nSyms;
nSyms += nKeySyms;
}
free(xkb->map->syms);
xkb->map->syms = newSyms;
xkb->map->num_syms = nSyms;
return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
} }
union xkb_action * union xkb_action *
@ -336,7 +274,7 @@ XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed)
} }
if (XkbKeyHasActions(xkb, key) && if (XkbKeyHasActions(xkb, key) &&
(XkbKeyNumSyms(xkb, key) >= (int)needed)) (XkbKeyGroupsWidth(xkb, key) >= needed))
return XkbKeyActionsPtr(xkb, key); return XkbKeyActionsPtr(xkb, key);
if (xkb->server->size_acts - xkb->server->num_acts >= (int)needed) { if (xkb->server->size_acts - xkb->server->num_acts >= (int)needed) {
@ -387,9 +325,10 @@ XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed)
void void
XkbcFreeClientMap(struct xkb_desc * xkb) XkbcFreeClientMap(struct xkb_desc * xkb)
{ {
int i;
struct xkb_client_map * map; struct xkb_client_map * map;
struct xkb_key_type * type; struct xkb_key_type * type;
xkb_keycode_t key;
int i;
if (!xkb || !xkb->map) if (!xkb || !xkb->map)
return; return;
@ -406,8 +345,14 @@ XkbcFreeClientMap(struct xkb_desc * xkb)
free(UNCONSTIFY(type->name)); free(UNCONSTIFY(type->name));
} }
free(map->types); free(map->types);
for (key = xkb->min_key_code; key < xkb->max_key_code; key++) {
free(map->key_sym_map[key].sym_index);
free(map->key_sym_map[key].num_syms);
free(map->key_sym_map[key].syms);
}
free(map->key_sym_map); free(map->key_sym_map);
free(map->syms);
free(map->modmap); free(map->modmap);
free(xkb->map); free(xkb->map);
xkb->map = NULL; xkb->map = NULL;

View File

@ -304,11 +304,19 @@ unsigned int
xkb_key_get_syms_by_level(struct xkb_desc *xkb, xkb_keycode_t key, unsigned int group, xkb_key_get_syms_by_level(struct xkb_desc *xkb, xkb_keycode_t key, unsigned int group,
unsigned int level, xkb_keysym_t **syms_out) unsigned int level, xkb_keysym_t **syms_out)
{ {
*syms_out = &(XkbKeySymEntry(xkb, key, level, group)); int num_syms;
if (**syms_out == XKB_KEYSYM_NO_SYMBOL)
if (group >= XkbKeyNumGroups(xkb, key))
goto err;
if (level >= XkbKeyGroupWidth(xkb, key, group))
goto err; goto err;
return 1; num_syms = XkbKeyNumSyms(xkb, key, group, level);
if (num_syms == 0)
goto err;
*syms_out = XkbKeySymEntry(xkb, key, group, level);
return num_syms;
err: err:
*syms_out = NULL; *syms_out = NULL;

View File

@ -60,7 +60,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions);
extern int extern int
XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type *into); XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type *into);
extern xkb_keysym_t * extern Bool
XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed); XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed);
extern union xkb_action * extern union xkb_action *

View File

@ -914,7 +914,7 @@ FindInterpForKey(struct xkb_desc *xkb, xkb_keycode_t key, uint32_t group, uint32
uint32_t mods; uint32_t mods;
Bool found; Bool found;
if ((num_syms != 1 || interp->sym != syms[0]) && if ((num_syms > 1 || interp->sym != syms[0]) &&
interp->sym != XKB_KEYSYM_NO_SYMBOL) interp->sym != XKB_KEYSYM_NO_SYMBOL)
continue; continue;

View File

@ -389,33 +389,17 @@ ActionCreate(xkb_atom_t name, ExprDef * args)
return NULL; return NULL;
} }
ExprDef * static Bool
CreateKeysymList(char *sym) ResizeKeysymList(ExprDef *list, unsigned int extra)
{ {
ExprDef *def; int i;
def = ExprCreate(ExprKeysymList, TypeSymbols); if (list->value.list.nSyms + extra > list->value.list.szSyms)
if (def)
{
def->value.list.nSyms = 1;
def->value.list.szSyms = 4;
def->value.list.syms = uTypedCalloc(4, char *);
if (def->value.list.syms != NULL)
{
def->value.list.syms[0] = sym;
return def;
}
}
FATAL("Couldn't allocate expression for keysym list in parser\n");
return NULL;
}
ExprDef *
AppendKeysymList(ExprDef * list, char *sym)
{
if (list->value.list.nSyms >= list->value.list.szSyms)
{ {
list->value.list.szSyms *= 2; list->value.list.szSyms *= 2;
list->value.list.szSyms += extra;
if (list->value.list.szSyms == 1)
list->value.list.szSyms = 4;
list->value.list.syms = uTypedRecalloc(list->value.list.syms, list->value.list.syms = uTypedRecalloc(list->value.list.syms,
list->value.list.nSyms, list->value.list.nSyms,
list->value.list.szSyms, list->value.list.szSyms,
@ -423,10 +407,128 @@ AppendKeysymList(ExprDef * list, char *sym)
if (list->value.list.syms == NULL) if (list->value.list.syms == NULL)
{ {
FATAL("Couldn't resize list of symbols for append\n"); FATAL("Couldn't resize list of symbols for append\n");
return NULL; return False;
} }
} }
if (list->value.list.nLevels >= list->value.list.szLevels)
{
list->value.list.szLevels *= 2;
if (list->value.list.szLevels == 0)
list->value.list.szLevels = 4;
list->value.list.symsMapIndex =
uTypedRecalloc(list->value.list.symsMapIndex,
list->value.list.nLevels,
list->value.list.szLevels,
int);
if (list->value.list.symsMapIndex == NULL)
{
FATAL("Couldn't resize keysym index map for append\n");
return False;
}
list->value.list.symsNumEntries =
uTypedRecalloc(list->value.list.symsNumEntries,
list->value.list.nLevels,
list->value.list.szLevels,
unsigned int);
if (list->value.list.symsNumEntries == NULL)
{
FATAL("Couldn't resize num keysym entries for append\n");
return False;
}
for (i = list->value.list.nLevels; i < list->value.list.szLevels; i++)
list->value.list.symsMapIndex[i] = -1;
}
return True;
}
ExprDef *
CreateKeysymList(char *sym)
{
ExprDef *def;
def = ExprCreate(ExprKeysymList, TypeSymbols);
if (!def)
{
FATAL("Couldn't allocate expression for keysym list in parser\n");
return NULL;
}
def->value.list.nSyms = 0;
def->value.list.szSyms = 0;
def->value.list.nLevels = 0;
def->value.list.szLevels = 0;
def->value.list.syms = NULL;
def->value.list.symsMapIndex = NULL;
def->value.list.symsNumEntries = NULL;
if (!ResizeKeysymList(def, 1))
{
FreeStmt(&def->common);
return NULL;
}
def->value.list.syms[0] = sym;
def->value.list.symsMapIndex[0] = 0;
def->value.list.symsNumEntries[0] = 1;
def->value.list.nLevels = 1;
def->value.list.nSyms = 1;
return def;
}
ExprDef *
CreateMultiKeysymList(ExprDef *list)
{
int i;
for (i = 1; i < list->value.list.szLevels; i++)
{
list->value.list.symsMapIndex[i] = -1;
list->value.list.symsNumEntries[i] = 0;
}
list->value.list.symsMapIndex[0] = 0;
list->value.list.symsNumEntries[0] = list->value.list.nLevels;
list->value.list.nLevels = 1;
return list;
}
ExprDef *
AppendKeysymList(ExprDef * list, char *sym)
{
if (!ResizeKeysymList(list, 1))
return NULL;
list->value.list.symsMapIndex[list->value.list.nLevels] =
list->value.list.nSyms;
list->value.list.symsNumEntries[list->value.list.nLevels] = 1;
list->value.list.syms[list->value.list.nSyms++] = sym; list->value.list.syms[list->value.list.nSyms++] = sym;
list->value.list.nLevels++;
return list;
}
ExprDef *
AppendMultiKeysymList(ExprDef * list, ExprDef * append)
{
int i;
if (!ResizeKeysymList(list, append->value.list.nSyms))
return NULL;
list->value.list.symsMapIndex[list->value.list.nLevels] =
list->value.list.nSyms;
list->value.list.symsNumEntries[list->value.list.nLevels] =
append->value.list.nSyms;
for (i = 0; i < append->value.list.nSyms; i++) {
list->value.list.syms[list->value.list.nSyms++] =
append->value.list.syms[i];
append->value.list.syms[i] = NULL;
}
list->value.list.nLevels++;
FreeStmt(&append->common);
return list; return list;
} }
@ -646,6 +748,8 @@ FreeExpr(ExprDef *expr)
for (i = 0; i < expr->value.list.nSyms; i++) for (i = 0; i < expr->value.list.nSyms; i++)
free(expr->value.list.syms[i]); free(expr->value.list.syms[i]);
free(expr->value.list.syms); free(expr->value.list.syms);
free(expr->value.list.symsMapIndex);
free(expr->value.list.symsNumEntries);
break; break;
default: default:
break; break;

View File

@ -113,9 +113,16 @@ extern ExprDef *ActionCreate(xkb_atom_t /* name */ ,
ExprDef * /* args */ ExprDef * /* args */
); );
extern ExprDef *CreateMultiKeysymList(ExprDef * /* list */
);
extern ExprDef *CreateKeysymList(char * /* sym */ extern ExprDef *CreateKeysymList(char * /* sym */
); );
extern ExprDef *AppendMultiKeysymList(ExprDef * /* list */ ,
ExprDef * /* append */
);
extern ExprDef *AppendKeysymList(ExprDef * /* list */ , extern ExprDef *AppendKeysymList(ExprDef * /* list */ ,
char * /* sym */ char * /* sym */
); );

View File

@ -65,6 +65,9 @@ typedef struct _KeyInfo
unsigned char actsDefined; unsigned char actsDefined;
unsigned int numLevels[XkbNumKbdGroups]; unsigned int numLevels[XkbNumKbdGroups];
xkb_keysym_t *syms[XkbNumKbdGroups]; xkb_keysym_t *syms[XkbNumKbdGroups];
int sizeSyms[XkbNumKbdGroups];
int *symsMapIndex[XkbNumKbdGroups];
unsigned int *symsMapNumEntries[XkbNumKbdGroups];
union xkb_action *acts[XkbNumKbdGroups]; union xkb_action *acts[XkbNumKbdGroups];
xkb_atom_t types[XkbNumKbdGroups]; xkb_atom_t types[XkbNumKbdGroups];
unsigned repeat; unsigned repeat;
@ -95,6 +98,9 @@ InitKeyInfo(KeyInfo * info)
info->numLevels[i] = 0; info->numLevels[i] = 0;
info->types[i] = XKB_ATOM_NONE; info->types[i] = XKB_ATOM_NONE;
info->syms[i] = NULL; info->syms[i] = NULL;
info->sizeSyms[i] = 0;
info->symsMapIndex[i] = NULL;
info->symsMapNumEntries[i] = NULL;
info->acts[i] = NULL; info->acts[i] = NULL;
} }
info->dfltType = XKB_ATOM_NONE; info->dfltType = XKB_ATOM_NONE;
@ -125,6 +131,11 @@ FreeKeyInfo(KeyInfo * info)
info->types[i] = XKB_ATOM_NONE; info->types[i] = XKB_ATOM_NONE;
free(info->syms[i]); free(info->syms[i]);
info->syms[i] = NULL; info->syms[i] = NULL;
info->sizeSyms[i] = 0;
free(info->symsMapIndex[i]);
info->symsMapIndex[i] = NULL;
free(info->symsMapNumEntries[i]);
info->symsMapNumEntries[i] = NULL;
free(info->acts[i]); free(info->acts[i]);
info->acts[i] = NULL; info->acts[i] = NULL;
} }
@ -153,7 +164,10 @@ CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
for (i = 0; i < XkbNumKbdGroups; i++) for (i = 0; i < XkbNumKbdGroups; i++)
{ {
old->numLevels[i] = 0; old->numLevels[i] = 0;
old->symsMapIndex[i] = NULL;
old->symsMapNumEntries[i] = NULL;
old->syms[i] = NULL; old->syms[i] = NULL;
old->sizeSyms[i] = 0;
old->acts[i] = NULL; old->acts[i] = NULL;
} }
} }
@ -165,21 +179,57 @@ CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
width = new->numLevels[i]; width = new->numLevels[i];
if (old->syms[i] != NULL) if (old->syms[i] != NULL)
{ {
new->syms[i] = uTypedCalloc(width, xkb_keysym_t); new->syms[i] = uTypedCalloc(new->sizeSyms[i], xkb_keysym_t);
if (!new->syms[i]) if (!new->syms[i])
{ {
new->syms[i] = NULL; new->syms[i] = NULL;
new->sizeSyms[i] = 0;
new->numLevels[i] = 0; new->numLevels[i] = 0;
new->acts[i] = NULL;
return False; return False;
} }
memcpy(new->syms[i], old->syms[i], width * sizeof(xkb_keysym_t)); memcpy(new->syms[i], old->syms[i],
new->sizeSyms[i] * sizeof(xkb_keysym_t));
new->symsMapIndex[i] = uTypedCalloc(width, int);
if (!new->symsMapIndex[i])
{
free(new->syms[i]);
new->syms[i] = NULL;
new->sizeSyms[i] = 0;
new->numLevels[i] = 0;
new->acts[i] = NULL;
return False;
}
memcpy(new->symsMapIndex[i], old->symsMapIndex[i],
width * sizeof(int));
new->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
if (!new->symsMapNumEntries[i])
{
free(new->syms[i]);
new->syms[i] = NULL;
new->sizeSyms[i] = 0;
free(new->symsMapIndex[i]);
new->symsMapIndex[i] = NULL;
new->numLevels[i] = 0;
new->acts[i] = NULL;
return False;
}
memcpy(new->symsMapNumEntries[i], old->symsMapNumEntries[i],
sizeof(unsigned int));
} }
if (old->acts[i] != NULL) if (old->acts[i] != NULL)
{ {
new->acts[i] = uTypedCalloc(width, union xkb_action); new->acts[i] = uTypedCalloc(width, union xkb_action);
if (!new->acts[i]) if (!new->acts[i])
{ {
new->acts[i] = NULL; free(new->syms[i]);
new->syms[i] = NULL;
new->sizeSyms[i] = 0;
free(new->symsMapIndex[i]);
new->symsMapIndex[i] = NULL;
free(new->symsMapNumEntries[i]);
new->symsMapNumEntries[i] = NULL;
new->numLevels[i] = 0;
return False; return False;
} }
memcpy(new->acts[i], old->acts[i], memcpy(new->acts[i], old->acts[i],
@ -269,36 +319,58 @@ FreeSymbolsInfo(SymbolsInfo * info)
} }
static Bool static Bool
ResizeKeyGroup(KeyInfo * key, ResizeKeyGroup(KeyInfo * key, unsigned int group, unsigned int numLevels,
unsigned group, unsigned atLeastSize, Bool forceActions) unsigned sizeSyms, Bool forceActions)
{ {
Bool tooSmall; Bool tooSmall;
unsigned newWidth; unsigned newWidth;
int i;
tooSmall = (key->numLevels[group] < atLeastSize); if (key->syms[group] == NULL || key->sizeSyms[group] < sizeSyms)
if (tooSmall)
newWidth = atLeastSize;
else
newWidth = key->numLevels[group];
if ((key->syms[group] == NULL) || tooSmall)
{ {
key->syms[group] = uTypedRecalloc(key->syms[group], key->syms[group] = uTypedRecalloc(key->syms[group],
key->numLevels[group], newWidth, key->sizeSyms[group],
sizeSyms,
xkb_keysym_t); xkb_keysym_t);
if (!key->syms[group]) if (!key->syms[group]) {
key->sizeSyms[group] = 0;
return False;
}
key->sizeSyms[group] = sizeSyms;
}
if (!key->symsMapIndex[group] || key->numLevels[group] < numLevels)
{
key->symsMapIndex[group] = uTypedRealloc(key->symsMapIndex[group],
numLevels,
int);
if (!key->symsMapIndex[group])
return False;
for (i = key->numLevels[group]; i < numLevels; i++)
key->symsMapIndex[group][i] = -1;
}
if (!key->symsMapNumEntries[group] || key->numLevels[group] < numLevels)
{
key->symsMapNumEntries[group] =
uTypedRecalloc(key->symsMapNumEntries[group],
key->numLevels[group],
numLevels,
unsigned int);
if (!key->symsMapNumEntries[group])
return False; return False;
} }
if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) || if ((forceActions &&
(tooSmall && (key->acts[group] != NULL))) (key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
(key->numLevels[group] < numLevels && (key->acts[group] != NULL)))
{ {
key->acts[group] = uTypedRecalloc(key->acts[group], key->acts[group] = uTypedRecalloc(key->acts[group],
key->numLevels[group], newWidth, key->numLevels[group],
numLevels,
union xkb_action); union xkb_action);
if (!key->acts[group]) if (!key->acts[group])
return False; return False;
} }
key->numLevels[group] = newWidth; if (key->numLevels[group] < numLevels)
key->numLevels[group] = numLevels;
return True; return True;
} }
@ -309,7 +381,9 @@ MergeKeyGroups(SymbolsInfo * info,
xkb_keysym_t *resultSyms; xkb_keysym_t *resultSyms;
union xkb_action *resultActs; union xkb_action *resultActs;
unsigned int resultWidth; unsigned int resultWidth;
unsigned int i; unsigned int resultSize = 0;
int cur_idx = 0;
int i, j;
Bool report, clobber; Bool report, clobber;
clobber = (from->defs.merge != MergeAugment); clobber = (from->defs.merge != MergeAugment);
@ -317,27 +391,33 @@ MergeKeyGroups(SymbolsInfo * info,
((into->defs.fileID == from->defs.fileID) && (warningLevel > 0)); ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
if (into->numLevels[group] >= from->numLevels[group]) if (into->numLevels[group] >= from->numLevels[group])
{ {
resultSyms = into->syms[group];
resultActs = into->acts[group]; resultActs = into->acts[group];
resultWidth = into->numLevels[group]; resultWidth = into->numLevels[group];
} }
else else
{ {
resultSyms = from->syms[group];
resultActs = from->acts[group]; resultActs = from->acts[group];
resultWidth = from->numLevels[group]; resultWidth = from->numLevels[group];
} into->symsMapIndex[group] = uTypedRealloc(into->symsMapIndex[group],
if (resultSyms == NULL) from->numLevels[group],
{ int);
resultSyms = uTypedCalloc(resultWidth, xkb_keysym_t); into->symsMapNumEntries[group] =
if (!resultSyms) uTypedRecalloc(into->symsMapNumEntries[group],
from->numLevels[group],
into->numLevels[group],
unsigned int);
if (!into->symsMapIndex[group] || !into->symsMapNumEntries[group])
{ {
WSGO("Could not allocate symbols for group merge\n"); WSGO("Could not allocate level indices for key info merge\n");
ACTION("Group %d of key %s not merged\n", group, ACTION("Group %d of key %s not merged\n", group,
longText(into->name)); longText(into->name));
return False; return False;
} }
for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
into->symsMapIndex[group][i] = -1;
} }
if ((resultActs == NULL) && (into->acts[group] || from->acts[group])) if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
{ {
resultActs = uTypedCalloc(resultWidth, union xkb_action); resultActs = uTypedCalloc(resultWidth, union xkb_action);
@ -346,51 +426,9 @@ MergeKeyGroups(SymbolsInfo * info,
WSGO("Could not allocate actions for group merge\n"); WSGO("Could not allocate actions for group merge\n");
ACTION("Group %d of key %s not merged\n", group, ACTION("Group %d of key %s not merged\n", group,
longText(into->name)); longText(into->name));
if (resultSyms != into->syms[group] &&
resultSyms != from->syms[group])
free(resultSyms);
return False; return False;
} }
} for (i = 0; i < resultWidth; i++)
for (i = 0; i < resultWidth; i++)
{
xkb_keysym_t fromSym, toSym;
if (from->syms[group] && (i < from->numLevels[group]))
fromSym = from->syms[group][i];
else
fromSym = XKB_KEYSYM_NO_SYMBOL;
if (into->syms[group] && (i < into->numLevels[group]))
toSym = into->syms[group][i];
else
toSym = XKB_KEYSYM_NO_SYMBOL;
if ((fromSym == XKB_KEYSYM_NO_SYMBOL) || (fromSym == toSym))
resultSyms[i] = toSym;
else if (toSym == XKB_KEYSYM_NO_SYMBOL)
resultSyms[i] = fromSym;
else
{
xkb_keysym_t use, ignore;
if (clobber)
{
use = fromSym;
ignore = toSym;
}
else
{
use = toSym;
ignore = fromSym;
}
if (report)
{
WARN
("Multiple symbols for level %d/group %d on key %s\n",
i + 1, group + 1, longText(into->name));
ACTION("Using %s, ignoring %s\n",
XkbcKeysymText(use), XkbcKeysymText(ignore));
}
resultSyms[i] = use;
}
if (resultActs != NULL)
{ {
union xkb_action *fromAct, *toAct; union xkb_action *fromAct, *toAct;
fromAct = (from->acts[group] ? &from->acts[group][i] : NULL); fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
@ -432,23 +470,112 @@ MergeKeyGroups(SymbolsInfo * info,
} }
} }
} }
if (resultSyms != into->syms[group])
free(into->syms[group]); for (i = 0; i < resultWidth; i++)
if (resultSyms != from->syms[group]) {
free(from->syms[group]); unsigned int fromSize = 0;
unsigned toSize = 0;
if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
fromSize = from->symsMapNumEntries[group][i];
if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
toSize = into->symsMapNumEntries[group][i];
if (fromSize == 0 || fromSize == toSize || clobber)
{
fromSize += toSize;
}
else if (toSize == 0)
{
resultSize += fromSize;
}
}
if (resultSize == 0)
goto out;
resultSyms = uTypedCalloc(resultSize, xkb_keysym_t);
if (!resultSyms)
{
WSGO("Could not allocate symbols for group merge\n");
ACTION("Group %d of key %s not merged\n", group, longText(into->name));
return False;
}
for (i = 0; i < resultWidth; i++)
{
enum { NONE, FROM, TO } use;
unsigned int fromSize = 0;
unsigned int toSize = 0;
if (from->symsMapNumEntries[group] && (i < from->numLevels[group]))
fromSize = from->symsMapNumEntries[group][i];
if (into->symsMapNumEntries[group] && (i < into->numLevels[group]))
toSize = into->symsMapNumEntries[group][i];
if (!fromSize && !toSize)
{
into->symsMapIndex[group][i] = -1;
into->symsMapNumEntries[group][i] = 0;
continue;
}
if ((fromSize && !toSize) || clobber)
use = FROM;
else
use = TO;
if (toSize && fromSize && report)
{
INFO("Multiple symbols for group %d, level %d on key %s\n",
group + 1, i + 1, longText(into->name));
ACTION("Using %s, ignoring %s\n",
(use == FROM ? "from" : "to"),
(use == FROM ? "to" : "from"));
}
if (use == FROM)
{
memcpy(&resultSyms[cur_idx],
&from->syms[group][from->symsMapIndex[group][i]],
from->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
into->symsMapIndex[group][i] = cur_idx;
into->symsMapNumEntries[group][i] =
from->symsMapNumEntries[group][i];
}
else
{
memcpy(&resultSyms[cur_idx],
&into->syms[group][from->symsMapIndex[group][i]],
into->symsMapNumEntries[group][i] * sizeof(xkb_keysym_t));
into->symsMapIndex[group][i] = cur_idx;
}
cur_idx += into->symsMapNumEntries[group][i];
}
out:
if (resultActs != into->acts[group]) if (resultActs != into->acts[group])
free(into->acts[group]); free(into->acts[group]);
if (resultActs != from->acts[group]) if (resultActs != from->acts[group])
free(from->acts[group]); free(from->acts[group]);
into->numLevels[group] = resultWidth; into->numLevels[group] = resultWidth;
free(into->syms[group]);
into->syms[group] = resultSyms; into->syms[group] = resultSyms;
free(from->syms[group]);
from->syms[group] = NULL; from->syms[group] = NULL;
from->sizeSyms[group] = 0;
into->sizeSyms[group] = resultSize;
free(from->symsMapIndex[group]);
from->symsMapIndex[group] = NULL;
free(from->symsMapNumEntries[group]);
from->symsMapNumEntries[group] = NULL;
into->acts[group] = resultActs; into->acts[group] = resultActs;
from->acts[group] = NULL; from->acts[group] = NULL;
into->symsDefined |= (1 << group); into->symsDefined |= (1 << group);
from->symsDefined &= ~(1 << group); from->symsDefined &= ~(1 << group);
into->actsDefined |= (1 << group); into->actsDefined |= (1 << group);
from->actsDefined &= ~(1 << group); from->actsDefined &= ~(1 << group);
return True; return True;
} }
@ -484,9 +611,15 @@ MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
{ {
into->numLevels[i] = from->numLevels[i]; into->numLevels[i] = from->numLevels[i];
into->syms[i] = from->syms[i]; into->syms[i] = from->syms[i];
into->sizeSyms[i] = from->sizeSyms[i];
into->symsMapIndex[i] = from->symsMapIndex[i];
into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
into->acts[i] = from->acts[i]; into->acts[i] = from->acts[i];
into->symsDefined |= (1 << i); into->symsDefined |= (1 << i);
from->syms[i] = NULL; from->syms[i] = NULL;
from->sizeSyms[i] = 0;
from->symsMapIndex[i] = NULL;
from->symsMapNumEntries[i] = NULL;
from->acts[i] = NULL; from->acts[i] = NULL;
from->numLevels[i] = 0; from->numLevels[i] = 0;
from->symsDefined &= ~(1 << i); from->symsDefined &= ~(1 << i);
@ -889,7 +1022,7 @@ AddSymbolsToKey(KeyInfo * key,
char *field, char *field,
ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info) ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
{ {
unsigned ndx, nSyms; unsigned ndx, nSyms, nLevels;
unsigned int i; unsigned int i;
long j; long j;
@ -907,7 +1040,7 @@ AddSymbolsToKey(KeyInfo * key,
longText(key->name)); longText(key->name));
return False; return False;
} }
if (key->syms[ndx] != NULL) if (key->sizeSyms[ndx] != 0)
{ {
ERROR("Symbols for key %s, group %d already defined\n", ERROR("Symbols for key %s, group %d already defined\n",
longText(key->name), ndx + 1); longText(key->name), ndx + 1);
@ -915,8 +1048,9 @@ AddSymbolsToKey(KeyInfo * key,
return False; return False;
} }
nSyms = value->value.list.nSyms; nSyms = value->value.list.nSyms;
nLevels = value->value.list.nLevels;
if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) && if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
(!ResizeKeyGroup(key, ndx, nSyms, False))) (!ResizeKeyGroup(key, ndx, nLevels, nSyms, False)))
{ {
WSGO("Could not resize group %d of key %s to contain %d levels\n", WSGO("Could not resize group %d of key %s to contain %d levels\n",
ndx + 1, longText(key->name), nSyms); ndx + 1, longText(key->name), nSyms);
@ -924,19 +1058,28 @@ AddSymbolsToKey(KeyInfo * key,
return False; return False;
} }
key->symsDefined |= (1 << ndx); key->symsDefined |= (1 << ndx);
for (i = 0; i < nSyms; i++) { for (i = 0; i < nLevels; i++) {
if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) { key->symsMapIndex[ndx][i] = value->value.list.symsMapIndex[i];
WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n", key->symsMapNumEntries[ndx][i] = value->value.list.symsNumEntries[i];
value->value.list.syms[i], longText(key->name), ndx + 1, for (j = 0; j < key->symsMapNumEntries[ndx][i]; j++) {
XkbcAtomText(info->groupNames[ndx]), nSyms); if (key->symsMapIndex[ndx][i] + j >= nSyms)
key->syms[ndx][i] = XKB_KEYSYM_NO_SYMBOL; abort();
if (!LookupKeysym(value->value.list.syms[value->value.list.symsMapIndex[i] + j],
&key->syms[ndx][key->symsMapIndex[ndx][i] + j])) {
WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
value->value.list.syms[i], longText(key->name), ndx + 1,
XkbcAtomText(info->groupNames[ndx]), nSyms);
while (--j >= 0)
key->syms[ndx][key->symsMapIndex[ndx][i] + j] = NoSymbol;
key->symsMapIndex[ndx][i] = -1;
key->symsMapNumEntries[ndx][i] = 0;
break;
}
} }
} }
for (j = key->numLevels[ndx] - 1; for (j = key->numLevels[ndx] - 1;
(j >= 0) && (key->syms[ndx][j] == XKB_KEYSYM_NO_SYMBOL); j--) j >= 0 && key->symsMapNumEntries[ndx][j] == 0; j--)
{
key->numLevels[ndx]--; key->numLevels[ndx]--;
}
return True; return True;
} }
@ -982,7 +1125,7 @@ AddActionsToKey(KeyInfo * key,
return False; return False;
} }
if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) && if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
(!ResizeKeyGroup(key, ndx, nActs, True))) (!ResizeKeyGroup(key, ndx, nActs, nActs, True)))
{ {
WSGO("Could not resize group %d of key %s\n", ndx, WSGO("Could not resize group %d of key %s\n", ndx,
longText(key->name)); longText(key->name));
@ -1371,6 +1514,12 @@ SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
key->numLevels[0] = 0; key->numLevels[0] = 0;
key->syms[group] = key->syms[0]; key->syms[group] = key->syms[0];
key->syms[0] = NULL; key->syms[0] = NULL;
key->sizeSyms[group] = key->sizeSyms[0];
key->sizeSyms[0] = 0;
key->symsMapIndex[group] = key->symsMapIndex[0];
key->symsMapIndex[0] = NULL;
key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
key->symsMapNumEntries[0] = NULL;
key->acts[group] = key->acts[0]; key->acts[group] = key->acts[0];
key->acts[0] = NULL; key->acts[0] = NULL;
key->types[group] = key->types[0]; key->types[group] = key->types[0];
@ -1515,28 +1664,24 @@ HandleSymbolsFile(XkbFile * file,
static Bool static Bool
FindKeyForSymbol(struct xkb_desc * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn) FindKeyForSymbol(struct xkb_desc * xkb, xkb_keysym_t sym, xkb_keycode_t *kc_rtrn)
{ {
int i, j; xkb_keycode_t key;
Bool gotOne; unsigned int group, level;
j = 0; for (key = xkb->min_key_code; key <= xkb->max_key_code; key++)
do
{ {
gotOne = False; for (group = 0; group < XkbKeyNumGroups(xkb, key); group++)
for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
{ {
if (j < (int) XkbKeyNumSyms(xkb, i)) for (level = 0; level < XkbKeyGroupWidth(xkb, key, group); level++)
{ {
gotOne = True; if (XkbKeyNumSyms(xkb, key, group, level) != 1 ||
if (XkbKeySym(xkb, i, j) == sym) (XkbKeySymEntry(xkb, key, group, level))[0] != sym)
{ continue;
*kc_rtrn = i; *kc_rtrn = key;
return True; return True;
}
} }
} }
j++;
} }
while (gotOne);
return False; return False;
} }
@ -1676,12 +1821,34 @@ PrepareKeyDef(KeyInfo * key)
width * sizeof(union xkb_action)); width * sizeof(union xkb_action));
key->actsDefined |= 1 << i; key->actsDefined |= 1 << i;
} }
if ((key->symsDefined & 1) && key->syms[0]) if ((key->symsDefined & 1) && key->sizeSyms[0])
{ {
key->syms[i] = uTypedCalloc(width, xkb_keysym_t); key->syms[i] = uTypedCalloc(key->sizeSyms[0], xkb_keysym_t);
if (key->syms[i] == NULL) if (key->syms[i] == NULL)
continue; continue;
memcpy(key->syms[i], key->syms[0], width * sizeof(xkb_keysym_t)); memcpy(key->syms[i], key->syms[0],
key->sizeSyms[0] * sizeof(xkb_keysym_t));
key->symsMapIndex[i] = uTypedCalloc(width, int);
if (!key->symsMapIndex[i])
{
free(key->syms[i]);
key->syms[i] = NULL;
continue;
}
memcpy(key->symsMapIndex[i], key->symsMapIndex[0],
width * sizeof(int));
key->symsMapNumEntries[i] = uTypedCalloc(width, unsigned int);
if (!key->symsMapNumEntries[i])
{
free(key->syms[i]);
key->syms[i] = NULL;
free(key->symsMapIndex[i]);
key->symsMapIndex[i] = NULL;
continue;
}
memcpy(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
width * sizeof(int));
key->sizeSyms[i] = key->sizeSyms[0];
key->symsDefined |= 1 << i; key->symsDefined |= 1 << i;
} }
if (defined & 1) if (defined & 1)
@ -1702,12 +1869,30 @@ PrepareKeyDef(KeyInfo * key)
} }
if ((key->syms[i] != key->syms[0]) && if ((key->syms[i] != key->syms[0]) &&
(key->syms[i] == NULL || key->syms[0] == NULL || (key->syms[i] == NULL || key->syms[0] == NULL ||
key->sizeSyms[i] != key->sizeSyms[0] ||
memcmp(key->syms[i], key->syms[0], memcmp(key->syms[i], key->syms[0],
sizeof(xkb_keysym_t) * key->numLevels[0]))) sizeof(xkb_keysym_t) * key->sizeSyms[0])))
{ {
identical = False; identical = False;
break; break;
} }
if ((key->symsMapIndex[i] != key->symsMapIndex[i]) &&
(key->symsMapIndex[i] == NULL || key->symsMapIndex[0] == NULL ||
memcmp(key->symsMapIndex[i], key->symsMapIndex[0],
key->numLevels[0] * sizeof(int))))
{
identical = False;
continue;
}
if ((key->symsMapNumEntries[i] != key->symsMapNumEntries[i]) &&
(key->symsMapNumEntries[i] == NULL ||
key->symsMapNumEntries[0] == NULL ||
memcmp(key->symsMapNumEntries[i], key->symsMapNumEntries[0],
key->numLevels[0] * sizeof(int))))
{
identical = False;
continue;
}
if ((key->acts[i] != key->acts[0]) && if ((key->acts[i] != key->acts[0]) &&
(key->acts[i] == NULL || key->acts[0] == NULL || (key->acts[i] == NULL || key->acts[0] == NULL ||
memcmp(key->acts[i], key->acts[0], memcmp(key->acts[i], key->acts[0],
@ -1724,6 +1909,11 @@ PrepareKeyDef(KeyInfo * key)
key->numLevels[i] = 0; key->numLevels[i] = 0;
free(key->syms[i]); free(key->syms[i]);
key->syms[i] = NULL; key->syms[i] = NULL;
key->sizeSyms[i] = 0;
free(key->symsMapIndex[i]);
key->symsMapIndex[i] = NULL;
free(key->symsMapNumEntries[i]);
key->symsMapNumEntries[i] = NULL;
free(key->acts[i]); free(key->acts[i]);
key->acts[i] = NULL; key->acts[i] = NULL;
key->types[i] = 0; key->types[i] = 0;
@ -1744,12 +1934,14 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
{ {
unsigned int i; unsigned int i;
xkb_keycode_t kc; xkb_keycode_t kc;
unsigned int sizeSyms = 0;
unsigned width, tmp, nGroups; unsigned width, tmp, nGroups;
struct xkb_key_type * type; struct xkb_key_type * type;
Bool haveActions, autoType, useAlias; Bool haveActions, autoType, useAlias;
xkb_keysym_t *outSyms; xkb_keysym_t *outSyms;
union xkb_action *outActs; union xkb_action *outActs;
unsigned types[XkbNumKbdGroups]; unsigned types[XkbNumKbdGroups];
unsigned int symIndex = 0;
useAlias = (start_from == 0); useAlias = (start_from == 0);
@ -1812,7 +2004,7 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
} }
types[i] = XkbTwoLevelIndex; types[i] = XkbTwoLevelIndex;
} }
/* if the type specifies less syms than the key has, shrink the key */ /* if the type specifies fewer levels than the key has, shrink the key */
type = &xkb->map->types[types[i]]; type = &xkb->map->types[types[i]];
if (type->num_levels < key->numLevels[i]) if (type->num_levels < key->numLevels[i])
{ {
@ -1829,13 +2021,10 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
width = key->numLevels[i]; width = key->numLevels[i];
if (type->num_levels > width) if (type->num_levels > width)
width = type->num_levels; width = type->num_levels;
sizeSyms += key->sizeSyms[i];
} }
/* width is now the largest width found */ if (!XkbcResizeKeySyms(xkb, kc, sizeSyms))
i = width * nGroups;
outSyms = XkbcResizeKeySyms(xkb, kc, i);
if (outSyms == NULL)
{ {
WSGO("Could not enlarge symbols for %s (keycode %d)\n", WSGO("Could not enlarge symbols for %s (keycode %d)\n",
longText(key->name), kc); longText(key->name), kc);
@ -1843,7 +2032,7 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
} }
if (haveActions) if (haveActions)
{ {
outActs = XkbcResizeKeyActions(xkb, kc, i); outActs = XkbcResizeKeyActions(xkb, kc, width * nGroups);
if (outActs == NULL) if (outActs == NULL)
{ {
WSGO("Could not enlarge actions for %s (key %d)\n", WSGO("Could not enlarge actions for %s (key %d)\n",
@ -1861,6 +2050,9 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups); xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
xkb->map->key_sym_map[kc].width = width; xkb->map->key_sym_map[kc].width = width;
xkb->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width, int);
xkb->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
unsigned int);
for (i = 0; i < nGroups; i++) for (i = 0; i < nGroups; i++)
{ {
/* assign kt_index[i] to the index of the type in map->types. /* assign kt_index[i] to the index of the type in map->types.
@ -1872,15 +2064,29 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
*/ */
if (key->numLevels[i]) if (key->numLevels[i])
xkb->map->key_sym_map[kc].kt_index[i] = types[i]; xkb->map->key_sym_map[kc].kt_index[i] = types[i];
if (key->syms[i] != NULL) if (key->sizeSyms[i] != 0)
{ {
/* fill key to "width" symbols*/ /* fill key to "width" symbols*/
for (tmp = 0; tmp < width; tmp++) for (tmp = 0; tmp < width; tmp++)
{ {
if (tmp < key->numLevels[i]) if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
outSyms[tmp] = key->syms[i][tmp]; {
memcpy(&xkb->map->key_sym_map[kc].syms[symIndex],
&key->syms[i][key->symsMapIndex[i][tmp]],
key->symsMapNumEntries[i][tmp] *
sizeof(xkb_keysym_t));
xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
symIndex;
xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
key->symsMapNumEntries[i][tmp];
symIndex +=
xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp];
}
else else
outSyms[tmp] = XKB_KEYSYM_NO_SYMBOL; {
xkb->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
xkb->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
}
if ((outActs != NULL) && (key->acts[i] != NULL)) if ((outActs != NULL) && (key->acts[i] != NULL))
{ {
if (tmp < key->numLevels[i]) if (tmp < key->numLevels[i])
@ -1890,9 +2096,6 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
} }
} }
} }
outSyms += width;
if (outActs)
outActs += width;
} }
switch (key->behavior.type & XkbKB_OpMask) switch (key->behavior.type & XkbKB_OpMask)
{ {

View File

@ -138,6 +138,10 @@ typedef struct _Expr
int nSyms; int nSyms;
int szSyms; int szSyms;
char **syms; char **syms;
int nLevels;
int szLevels;
int *symsMapIndex;
unsigned int *symsNumEntries;
} list; } list;
struct _Expr *child; struct _Expr *child;
xkb_atom_t str; xkb_atom_t str;

View File

@ -723,14 +723,11 @@ OptKeySymList : KeySymList { $$= $1; }
KeySymList : KeySymList COMMA KeySym KeySymList : KeySymList COMMA KeySym
{ $$= AppendKeysymList($1,$3); } { $$= AppendKeysymList($1,$3); }
| KeySymList COMMA KeySyms | KeySymList COMMA KeySyms
{ { $$= AppendMultiKeysymList($1,$3); }
$$= AppendKeysymList($1, strdup("NoSymbol"));
FreeStmt(&$3->common);
}
| KeySym | KeySym
{ $$= CreateKeysymList($1); } { $$= CreateKeysymList($1); }
| KeySyms | KeySyms
{ $$= CreateKeysymList(strdup("NoSymbol")); } { $$= CreateMultiKeysymList($1); }
; ;
KeySyms : OBRACE KeySymList CBRACE KeySyms : OBRACE KeySymList CBRACE