From 3de9d87498f7041372ff0e49fd45f1d852a02f25 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 15 Jul 2012 00:26:28 +0300 Subject: [PATCH] Get rid of xkb_server_map Same as xkb_client_map which was removed before. Signed-off-by: Ran Benita --- src/alloc.c | 95 ++++++------------------------------------- src/alloc.h | 7 ---- src/keymap-dump.c | 20 ++++----- src/xkb-priv.h | 31 ++++++++------ src/xkbcomp/compat.c | 31 +++++++------- src/xkbcomp/symbols.c | 35 +++++++++++----- src/xkbcomp/vmod.c | 13 +++--- 7 files changed, 84 insertions(+), 148 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index d29c740..8b8fb2b 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -26,62 +26,6 @@ #include "xkb-priv.h" #include "alloc.h" -int -XkbcAllocServerMap(struct xkb_keymap *keymap, unsigned which, - unsigned nNewActions) -{ - unsigned i; - struct xkb_server_map * map; - - if (!keymap) - return BadMatch; - - if (!keymap->server) { - map = uTypedCalloc(1, struct xkb_server_map); - if (!map) - return BadAlloc; - - for (i = 0; i < XkbNumVirtualMods; i++) - map->vmods[i] = XkbNoModifierMask; - - keymap->server = map; - } - else - map = keymap->server; - - if (!which) - return Success; - - if (!map->explicit) { - i = keymap->max_key_code + 1; - map->explicit = uTypedCalloc(i, unsigned char); - if (!map->explicit) - return BadAlloc; - } - - if (nNewActions < 1) - nNewActions = 1; - - darray_resize0(map->acts, darray_size(map->acts) + nNewActions + 1); - darray_resize0(map->key_acts, keymap->max_key_code + 1); - - if (!map->behaviors) { - i = keymap->max_key_code + 1; - map->behaviors = uTypedCalloc(i, struct xkb_behavior); - if (!map->behaviors) - return BadAlloc; - } - - if (!map->vmodmap) { - i = keymap->max_key_code + 1; - map->vmodmap = uTypedCalloc(i, uint32_t); - if (!map->vmodmap) - return BadAlloc; - } - - return Success; -} - int XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into) { @@ -137,7 +81,7 @@ XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t key, size_t old_ndx, old_num_acts, new_ndx; if (needed == 0) { - darray_item(keymap->server->key_acts, key) = 0; + darray_item(keymap->key_acts, key) = 0; return NULL; } @@ -152,20 +96,20 @@ XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t key, * space for the key at the end, and leave the old space alone. */ - old_ndx = darray_item(keymap->server->key_acts, key); + old_ndx = darray_item(keymap->key_acts, key); old_num_acts = XkbKeyNumActions(keymap, key); - new_ndx = darray_size(keymap->server->acts); + new_ndx = darray_size(keymap->acts); - darray_resize0(keymap->server->acts, new_ndx + needed); - darray_item(keymap->server->key_acts, key) = new_ndx; + darray_resize0(keymap->acts, new_ndx + needed); + darray_item(keymap->key_acts, key) = new_ndx; /* * The key was already in the array, copy the old actions to the * new space. */ if (old_ndx != 0) - memcpy(darray_mem(keymap->server->acts, new_ndx), - darray_mem(keymap->server->acts, old_ndx), + memcpy(darray_mem(keymap->acts, new_ndx), + darray_mem(keymap->acts, old_ndx), old_num_acts * sizeof(union xkb_action)); return XkbKeyActionsPtr(keymap, key); @@ -201,25 +145,6 @@ free_sym_maps(struct xkb_keymap *keymap) darray_free(keymap->key_sym_map); } -void -XkbcFreeServerMap(struct xkb_keymap *keymap) -{ - struct xkb_server_map * map; - - if (!keymap || !keymap->server) - return; - - map = keymap->server; - - free(map->explicit); - darray_free(map->key_acts); - darray_free(map->acts); - free(map->behaviors); - free(map->vmodmap); - free(keymap->server); - keymap->server = NULL; -} - int XkbcAllocCompatMap(struct xkb_keymap *keymap, unsigned nSI) { @@ -407,7 +332,11 @@ XkbcFreeKeyboard(struct xkb_keymap *keymap) free_types(keymap); free_sym_maps(keymap); free(keymap->modmap); - XkbcFreeServerMap(keymap); + free(keymap->explicit); + darray_free(keymap->key_acts); + darray_free(keymap->acts); + free(keymap->behaviors); + free(keymap->vmodmap); XkbcFreeCompatMap(keymap); XkbcFreeIndicatorMaps(keymap); XkbcFreeNames(keymap); diff --git a/src/alloc.h b/src/alloc.h index bea53cf..a933929 100644 --- a/src/alloc.h +++ b/src/alloc.h @@ -48,10 +48,6 @@ XkbcAllocKeyboard(struct xkb_context *ctx); extern void XkbcFreeKeyboard(struct xkb_keymap *keymap); -extern int -XkbcAllocServerMap(struct xkb_keymap *keymap, unsigned which, - unsigned nNewActions); - extern int XkbcCopyKeyType(const struct xkb_key_type *from, struct xkb_key_type *into); @@ -63,7 +59,4 @@ extern union xkb_action * XkbcResizeKeyActions(struct xkb_keymap *keymap, xkb_keycode_t key, uint32_t needed); -extern void -XkbcFreeServerMap(struct xkb_keymap *keymap); - #endif /* ALLOC_H */ diff --git a/src/keymap-dump.c b/src/keymap-dump.c index 6870ca7..8443e7d 100644 --- a/src/keymap-dump.c +++ b/src/keymap-dump.c @@ -779,7 +779,6 @@ static bool write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size, size_t *offset) { - struct xkb_server_map *srv = keymap->server; xkb_keycode_t key; int group, tmp; bool showActions; @@ -809,8 +808,8 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size, write_buf(keymap, buf, size, offset, "\t\tkey %6s {", XkbcKeyNameText(darray_item(keymap->names->keys, key).name)); - if (srv->explicit) { - if ((srv->explicit[key] & XkbExplicitKeyTypesMask)) { + if (keymap->explicit) { + if ((keymap->explicit[key] & XkbExplicitKeyTypesMask)) { bool multi_type = false; int type = XkbKeyTypeIndex(keymap, key, 0); @@ -827,7 +826,7 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size, for (group = 0; group < xkb_key_num_groups(keymap, key); group++) { - if (!(srv->explicit[key] & (1 << group))) + if (!(keymap->explicit[key] & (1 << group))) continue; type = XkbKeyTypeIndex(keymap, key, group); write_buf(keymap, buf, size, offset, @@ -843,7 +842,7 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size, } } if (keymap->ctrls && - (srv->explicit[key] & XkbExplicitAutoRepeatMask)) { + (keymap->explicit[key] & XkbExplicitAutoRepeatMask)) { if (keymap->ctrls->per_key_repeat[key / 8] & (1 << (key % 8))) write_buf(keymap, buf, size, offset, "\n\t\t\trepeat= Yes,"); @@ -852,12 +851,11 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size, "\n\t\t\trepeat= No,"); simple = false; } - if (keymap->server->vmodmap[key] && - (srv->explicit[key] & XkbExplicitVModMapMask)) { + if (keymap->vmodmap[key] && + (keymap->explicit[key] & XkbExplicitVModMapMask)) { write_buf(keymap, buf, size, offset, "\n\t\t\tvirtualMods= %s,", - get_mod_mask_text(keymap, 0, - keymap->server->vmodmap[key])); + get_mod_mask_text(keymap, 0, keymap->vmodmap[key])); } } @@ -874,8 +872,8 @@ write_symbols(struct xkb_keymap *keymap, char **buf, size_t *size, break; } - if (srv->explicit == NULL || - (srv->explicit[key] & XkbExplicitInterpretMask)) + if (keymap->explicit == NULL || + (keymap->explicit[key] & XkbExplicitInterpretMask)) showActions = XkbKeyHasActions(keymap, key); else showActions = false; diff --git a/src/xkb-priv.h b/src/xkb-priv.h index bb7410c..2072010 100644 --- a/src/xkb-priv.h +++ b/src/xkb-priv.h @@ -280,16 +280,6 @@ struct xkb_behavior { unsigned char data; }; -struct xkb_server_map { - unsigned char * explicit; - - darray(union xkb_action) acts; - darray(size_t) key_acts; /* acts[key_acts[keycode]] */ - struct xkb_behavior *behaviors; - uint32_t vmods[XkbNumVirtualMods]; /* vmod -> mod mapping */ - uint32_t *vmodmap; /* key -> vmod mapping */ -}; - struct xkb_indicator_map { unsigned char flags; unsigned char which_groups; @@ -354,14 +344,29 @@ struct xkb_keymap { xkb_keycode_t max_key_code; struct xkb_controls * ctrls; - struct xkb_server_map * server; struct xkb_indicator * indicators; struct xkb_names * names; struct xkb_compat_map * compat; + /* key -> explicit flags mapping */ + unsigned char *explicit; + darray(struct xkb_key_type) types; + darray(struct xkb_sym_map) key_sym_map; + + /* key -> mod mapping */ unsigned char *modmap; + /* vmod -> mod mapping */ + uint32_t vmods[XkbNumVirtualMods]; + /* key -> vmod mapping */ + uint32_t *vmodmap; + + /* acts[key_acts[keycode]] */ + darray(union xkb_action) acts; + darray(size_t ) key_acts; + + struct xkb_behavior *behaviors; }; #define XkbNumGroups(g) ((g) & 0x0f) @@ -396,13 +401,13 @@ struct xkb_keymap { #define XkbKeySymEntry(d, k, g, sl) \ (XkbKeySym(d, k, XkbKeySymOffset(d, k, g, sl))) #define XkbKeyHasActions(d, k) \ - (darray_item((d)->server->key_acts, k) != 0) + (darray_item((d)->key_acts, k) != 0) #define XkbKeyNumActions(d, k) \ (XkbKeyHasActions(d, k) ? \ (XkbKeyGroupsWidth(d, k) * XkbKeyNumGroups(d, k)) : \ 1) #define XkbKeyActionsPtr(d, k) \ - (darray_mem((d)->server->acts, darray_item((d)->server->key_acts, k))) + (darray_mem((d)->acts, darray_item((d)->key_acts, k))) #define XkbKeyAction(d, k, n) \ (XkbKeyHasActions(d, k) ? &XkbKeyActionsPtr(d, k)[n] : NULL) #define XkbKeyActionEntry(d, k, sl, g) \ diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index ec743f2..c9cf637 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -794,7 +794,7 @@ VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask) for (i = 0; i < XkbNumVirtualMods; i++) { if (!(vmodmask & (1 << i))) continue; - ret |= keymap->server->vmods[i]; + ret |= keymap->vmods[i]; } return ret; @@ -902,7 +902,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, xkb_keycode_t key) int i; /* If we've been told not to bind interps to this key, then don't. */ - if (keymap->server->explicit[key] & XkbExplicitInterpretMask) + if (keymap->explicit[key] & XkbExplicitInterpretMask) return true; for (i = 0; i < INTERP_SIZE; i++) @@ -936,14 +936,13 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, xkb_keycode_t key) /* Infer default key behaviours from the base level. */ if (group == 0 && level == 0) { - if (!(keymap->server->explicit[key] & - XkbExplicitAutoRepeatMask) && + if (!(keymap->explicit[key] & XkbExplicitAutoRepeatMask) && (!interp || interp->flags & XkbSI_AutoRepeat)) - keymap->ctrls->per_key_repeat[key / 8] |= (1 << (key % 8)); - if (!(keymap->server->explicit[key] & - XkbExplicitBehaviorMask) && + keymap->ctrls->per_key_repeat[key / 8] |= + (1 << (key % 8)); + if (!(keymap->explicit[key] & XkbExplicitBehaviorMask) && interp && (interp->flags & XkbSI_LockingKey)) - keymap->server->behaviors[key].type = XkbKB_Lock; + keymap->behaviors[key].type = XkbKB_Lock; } if (!interp) @@ -958,8 +957,8 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, xkb_keycode_t key) } } - if (!(keymap->server->explicit[key] & XkbExplicitVModMapMask)) - keymap->server->vmodmap[key] = vmodmask; + if (!(keymap->explicit[key] & XkbExplicitVModMapMask)) + keymap->vmodmap[key] = vmodmask; return true; #undef INTERP_SIZE @@ -985,16 +984,16 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap) if (!ApplyInterpsToKey(keymap, key)) return false; - /* Update keymap->server->vmods, the virtual -> real mod mapping. */ + /* Update keymap->vmods, the virtual -> real mod mapping. */ for (i = 0; i < XkbNumVirtualMods; i++) - keymap->server->vmods[i] = 0; + keymap->vmods[i] = 0; for (key = keymap->min_key_code; key <= keymap->max_key_code; key++) { - if (!keymap->server->vmodmap[key]) + if (!keymap->vmodmap[key]) continue; for (i = 0; i < XkbNumVirtualMods; i++) { - if (!(keymap->server->vmodmap[key] & (1 << i))) + if (!(keymap->vmodmap[key] & (1 << i))) continue; - keymap->server->vmods[i] |= keymap->modmap[key]; + keymap->vmods[i] |= keymap->modmap[key]; } } @@ -1007,7 +1006,7 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap) for (j = 0; j < XkbNumVirtualMods; j++) { if (!(type->mods.vmods & (1 << j))) continue; - mask |= keymap->server->vmods[j]; + mask |= keymap->vmods[j]; } darray_foreach(entry, type->map) diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index d1d6b0b..2ae0ebe 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1739,7 +1739,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from) } if (FindNamedType(keymap, key->types[i], &types[i])) { if (!autoType || key->numLevels[i] > 2) - keymap->server->explicit[kc] |= (1 << i); + keymap->explicit[kc] |= (1 << i); } else { if (warningLevel >= 3) { @@ -1780,7 +1780,7 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from) longText(key->name), kc); return false; } - keymap->server->explicit[kc] |= XkbExplicitInterpretMask; + keymap->explicit[kc] |= XkbExplicitInterpretMask; } else outActs = NULL; @@ -1840,20 +1840,20 @@ CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from) break; default: - keymap->server->behaviors[kc] = key->behavior; - keymap->server->explicit[kc] |= XkbExplicitBehaviorMask; + keymap->behaviors[kc] = key->behavior; + keymap->explicit[kc] |= XkbExplicitBehaviorMask; break; } if (key->defs.defined & _Key_VModMap) { - keymap->server->vmodmap[kc] = key->vmodmap; - keymap->server->explicit[kc] |= XkbExplicitVModMapMask; + keymap->vmodmap[kc] = key->vmodmap; + keymap->explicit[kc] |= XkbExplicitVModMapMask; } if (key->repeat != RepeatUndefined) { if (key->repeat == RepeatYes) keymap->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8)); else keymap->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8)); - keymap->server->explicit[kc] |= XkbExplicitAutoRepeatMask; + keymap->explicit[kc] |= XkbExplicitAutoRepeatMask; } /* do the same thing for the next key */ @@ -1930,11 +1930,24 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, if (!keymap->modmap) goto err_info; - if (XkbcAllocServerMap(keymap, XkbAllServerInfoMask, 32) != Success) { - WSGO("Could not allocate server map in CompileSymbols\n"); - ACTION("Symbols not added\n"); + i = keymap->max_key_code + 1; + keymap->explicit = calloc(keymap->max_key_code + 1, + sizeof(*keymap->explicit)); + if (!keymap->explicit) + goto err_info; + + darray_resize0(keymap->acts, darray_size(keymap->acts) + 32 + 1); + darray_resize0(keymap->key_acts, keymap->max_key_code + 1); + + keymap->behaviors = calloc(keymap->max_key_code + 1, + sizeof(*keymap->behaviors)); + if (!keymap->behaviors) + goto err_info; + + keymap->vmodmap = calloc(keymap->max_key_code + 1, + sizeof(*keymap->vmodmap)); + if (!keymap->vmodmap) goto err_info; - } if (XkbcAllocControls(keymap) != Success) { WSGO("Could not allocate controls in CompileSymbols\n"); diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index 2a90603..341f6be 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -43,8 +43,8 @@ ClearVModInfo(VModInfo *info, struct xkb_keymap *keymap) if (XkbcAllocNames(keymap, 0, 0) != Success) return; - if (XkbcAllocServerMap(keymap, 0, 0) != Success) - return; + for (i = 0; i < XkbNumVirtualMods; i++) + keymap->vmods[i] = XkbNoModifierMask; info->keymap = keymap; if (keymap && keymap->names) { @@ -73,7 +73,6 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, { int i, bit, nextFree; ExprResult mod; - struct xkb_server_map *srv = keymap->server; struct xkb_names *names = keymap->names; for (i = 0, bit = 1, nextFree = -1; i < XkbNumVirtualMods; i++, bit <<= @@ -94,19 +93,19 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, ACTION("Declaration of %s ignored\n", str1); return false; } - if (mod.uval == srv->vmods[i]) + if (mod.uval == keymap->vmods[i]) return true; str1 = xkb_atom_text(keymap->ctx, stmt->name); WARN("Virtual modifier %s multiply defined\n", str1); - str1 = XkbcModMaskText(srv->vmods[i], true); + str1 = XkbcModMaskText(keymap->vmods[i], true); if (mergeMode == MERGE_OVERRIDE) { str2 = str1; str1 = XkbcModMaskText(mod.uval, true); } ACTION("Using %s, ignoring %s\n", str1, str2); if (mergeMode == MERGE_OVERRIDE) - srv->vmods[i] = mod.uval; + keymap->vmods[i] = mod.uval; return true; } } @@ -126,7 +125,7 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, if (stmt->value == NULL) return true; if (ExprResolveModMask(keymap->ctx, stmt->value, &mod)) { - srv->vmods[nextFree] = mod.uval; + keymap->vmods[nextFree] = mod.uval; return true; } ACTION("Declaration of %s ignored\n",