symbols: use darray for xkb_sym_map

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-05-22 15:20:47 +03:00
parent 4daa34b5a3
commit 07c88b551b
3 changed files with 80 additions and 74 deletions

View File

@ -43,14 +43,8 @@ XkbcAllocClientMap(struct xkb_keymap *keymap, unsigned which,
if (which & XkbKeyTypesMask)
darray_growalloc(keymap->map->types, nTotalTypes);
if (which & XkbKeySymsMask) {
if (!keymap->map->key_sym_map) {
keymap->map->key_sym_map = uTypedCalloc(keymap->max_key_code + 1,
struct xkb_sym_map);
if (!keymap->map->key_sym_map)
return BadAlloc;
}
}
if (which & XkbKeySymsMask)
darray_resize0(keymap->map->key_sym_map, keymap->max_key_code + 1);
if (which & XkbModifierMapMask) {
if (!keymap->map->modmap) {
@ -193,20 +187,20 @@ bool
XkbcResizeKeySyms(struct xkb_keymap *keymap, xkb_keycode_t key,
unsigned int needed)
{
if (keymap->map->key_sym_map[key].size_syms >= needed)
struct xkb_sym_map *sym_map =
&darray_item(keymap->map->key_sym_map, key);
if (sym_map->size_syms >= needed)
return true;
keymap->map->key_sym_map[key].syms =
uTypedRecalloc(keymap->map->key_sym_map[key].syms,
keymap->map->key_sym_map[key].size_syms,
needed,
xkb_keysym_t);
if (!keymap->map->key_sym_map[key].syms) {
keymap->map->key_sym_map[key].size_syms = 0;
sym_map->syms = uTypedRecalloc(sym_map->syms, sym_map->size_syms,
needed, xkb_keysym_t);
if (!sym_map->syms) {
sym_map->size_syms = 0;
return false;
}
keymap->map->key_sym_map[key].size_syms = needed;
sym_map->size_syms = needed;
return true;
}
@ -276,7 +270,7 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
{
struct xkb_client_map * map;
struct xkb_key_type * type;
xkb_keycode_t key;
struct xkb_sym_map *sym_map;
if (!keymap || !keymap->map)
return;
@ -294,14 +288,12 @@ XkbcFreeClientMap(struct xkb_keymap *keymap)
}
darray_free(map->types);
if (map->key_sym_map) {
for (key = keymap->min_key_code; key < keymap->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);
}
darray_foreach(sym_map, map->key_sym_map) {
free(sym_map->sym_index);
free(sym_map->num_syms);
free(sym_map->syms);
}
free(map->key_sym_map);
darray_free(map->key_sym_map);
free(map->modmap);
free(keymap->map);

View File

@ -280,8 +280,8 @@ struct xkb_sym_map {
struct xkb_client_map {
darray(struct xkb_key_type) types;
struct xkb_sym_map * key_sym_map;
unsigned char *modmap;
darray(struct xkb_sym_map) key_sym_map;
unsigned char *modmap;
};
struct xkb_behavior {
@ -370,39 +370,52 @@ struct xkb_keymap {
struct xkb_compat_map * compat;
};
#define XkbNumGroups(g) ((g)&0x0f)
#define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
#define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
#define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
#define XkbSetGroupInfo(g,w,n) (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
#define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
#define XkbNumGroups(g) ((g) & 0x0f)
#define XkbOutOfRangeGroupInfo(g) ((g) & 0xf0)
#define XkbOutOfRangeGroupAction(g) ((g) & 0xc0)
#define XkbOutOfRangeGroupNumber(g) (((g) & 0x30) >> 4)
#define XkbSetGroupInfo(g, w, n) (((w) & 0xc0) | (((n) & 3) << 4) | ((g) & 0x0f))
#define XkbSetNumGroups(g, n) (((g) & 0xf0) | ((n) & 0x0f))
#define XkbKeyGroupInfo(d,k) ((d)->map->key_sym_map[k].group_info)
#define XkbKeyNumGroups(d,k) (XkbNumGroups((d)->map->key_sym_map[k].group_info))
#define XkbKeyGroupWidth(d,k,g) (XkbKeyType(d,k,g)->num_levels)
#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 XkbKeyType(d,k,g) (&darray_item((d)->map->types, XkbKeyTypeIndex(d,k,g)))
#define XkbKeyNumSyms(d,k,g,sl) \
((d)->map->key_sym_map[k].num_syms[(g*XkbKeyGroupsWidth(d,k))+sl])
#define XkbKeySym(d,k,n) (&(d)->map->key_sym_map[k].syms[n])
#define XkbKeySymOffset(d,k,g,sl) \
((d)->map->key_sym_map[k].sym_index[(g*XkbKeyGroupsWidth(d,k))+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 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 XkbKeyAction(d,k,n) \
(XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
#define XkbKeyActionEntry(d,k,sl,g) \
(XkbKeyHasActions(d,k)?\
XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
#define XkbKeyGroupInfo(d, k) \
(darray_item((d)->map->key_sym_map, k).group_info)
#define XkbKeyNumGroups(d, k) \
(XkbNumGroups(darray_item((d)->map->key_sym_map, k).group_info))
#define XkbKeyGroupWidth(d, k, g) \
(XkbKeyType(d, k, g)->num_levels)
#define XkbKeyGroupsWidth(d, k) \
(darray_item((d)->map->key_sym_map, k).width)
#define XkbKeyTypeIndex(d, k, g) \
(darray_item((d)->map->key_sym_map, k).kt_index[g & 0x3])
#define XkbKeyType(d, k, g) \
(&darray_item((d)->map->types, XkbKeyTypeIndex(d, k, g)))
#define XkbKeyNumSyms(d, k, g, sl) \
(darray_item((d)->map->key_sym_map, k).num_syms[(g * XkbKeyGroupsWidth(d, k)) + sl])
#define XkbKeySym(d, k, n) \
(&darray_item((d)->map->key_sym_map, k).syms[n])
#define XkbKeySymOffset(d, k, g, sl) \
(darray_item((d)->map->key_sym_map, k).sym_index[(g * XkbKeyGroupsWidth(d, k)) + 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 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 XkbKeyAction(d, k, n) \
(XkbKeyHasActions(d, k) ? &XkbKeyActionsPtr(d, k)[n] : NULL)
#define XkbKeyActionEntry(d, k, sl, g) \
(XkbKeyHasActions(d, k) ? \
XkbKeyAction(d, k, ((XkbKeyGroupsWidth(d, k) * (g)) + (sl))) : \
NULL)
#define XkbKeycodeInRange(d,k) (((k)>=(d)->min_key_code)&&\
((k)<=(d)->max_key_code))
#define XkbNumKeys(d) ((d)->max_key_code-(d)->min_key_code+1)
#define XkbKeycodeInRange(d, k) \
(((k) >= (d)->min_key_code) && ((k) <= (d)->max_key_code))
#define XkbNumKeys(d) \
((d)->max_key_code - (d)->min_key_code + 1)
struct xkb_state {
xkb_group_index_t base_group; /**< depressed */

View File

@ -1929,6 +1929,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
unsigned types[XkbNumKbdGroups];
union xkb_action *outActs;
unsigned int symIndex = 0;
struct xkb_sym_map *sym_map;
useAlias = (start_from == 0);
@ -2030,17 +2031,19 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
}
else
outActs = NULL;
sym_map = &darray_item(keymap->map->key_sym_map, kc);
if (key->defs.defined & _Key_GroupInfo)
i = key->groupInfo;
else
i = keymap->map->key_sym_map[kc].group_info;
i = sym_map->group_info;
sym_map->group_info = XkbSetNumGroups(i, nGroups);
sym_map->width = width;
sym_map->sym_index = uTypedCalloc(nGroups * width, int);
sym_map->num_syms = uTypedCalloc(nGroups * width, unsigned int);
keymap->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
keymap->map->key_sym_map[kc].width = width;
keymap->map->key_sym_map[kc].sym_index = uTypedCalloc(nGroups * width,
int);
keymap->map->key_sym_map[kc].num_syms = uTypedCalloc(nGroups * width,
unsigned int);
for (i = 0; i < nGroups; i++)
{
/* assign kt_index[i] to the index of the type in map->types.
@ -2051,7 +2054,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
* FIXME: There should be a better fix for this.
*/
if (key->numLevels[i])
keymap->map->key_sym_map[kc].kt_index[i] = types[i];
sym_map->kt_index[i] = types[i];
if (key->sizeSyms[i] != 0)
{
/* fill key to "width" symbols*/
@ -2059,21 +2062,19 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
{
if (tmp < key->numLevels[i] && key->symsMapNumEntries[i][tmp])
{
memcpy(&keymap->map->key_sym_map[kc].syms[symIndex],
memcpy(&sym_map->syms[symIndex],
&key->syms[i][key->symsMapIndex[i][tmp]],
key->symsMapNumEntries[i][tmp] *
sizeof(xkb_keysym_t));
keymap->map->key_sym_map[kc].sym_index[(i * width) + tmp] =
symIndex;
keymap->map->key_sym_map[kc].num_syms[(i * width) + tmp] =
sym_map->sym_index[(i * width) + tmp] = symIndex;
sym_map->num_syms[(i * width) + tmp] =
key->symsMapNumEntries[i][tmp];
symIndex +=
keymap->map->key_sym_map[kc].num_syms[(i * width) + tmp];
symIndex += sym_map->num_syms[(i * width) + tmp];
}
else
{
keymap->map->key_sym_map[kc].sym_index[(i * width) + tmp] = -1;
keymap->map->key_sym_map[kc].num_syms[(i * width) + tmp] = 0;
sym_map->sym_index[(i * width) + tmp] = -1;
sym_map->num_syms[(i * width) + tmp] = 0;
}
if ((outActs != NULL) && (key->acts[i] != NULL))
{