diff options
author | Ran Benita <ran234@gmail.com> | 2013-02-08 13:09:33 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2014-04-19 16:20:09 +0300 |
commit | ca3170ad3813389a3325513130c37e8038fa02f9 (patch) | |
tree | f743e6b3f056bcdcfab7f8b029a03c9818cb2dd7 | |
parent | 3d7aff5fcdad501856662e6b84a76ef883b35784 (diff) | |
download | libxkbcommon-ca3170ad3813389a3325513130c37e8038fa02f9.tar.gz libxkbcommon-ca3170ad3813389a3325513130c37e8038fa02f9.tar.bz2 libxkbcommon-ca3170ad3813389a3325513130c37e8038fa02f9.zip |
Add struct xkb_mod_set
The only thing that the compilation phase needs the keymap for currently
is for access to the modifier information (it also modifies it in
place!). We want to only pass along the neccessary information, to make
it more tractable and testable, so instead of passing the entire keymap
we add a new 'mod_set' object and pass a (const) reference to that.
The new object is just the old array of 'struct xkb_mod'.
Signed-off-by: Ran Benita <ran234@gmail.com>
-rw-r--r-- | src/keymap-priv.c | 5 | ||||
-rw-r--r-- | src/keymap.c | 9 | ||||
-rw-r--r-- | src/keymap.h | 6 | ||||
-rw-r--r-- | src/text.c | 7 | ||||
-rw-r--r-- | src/x11/keymap.c | 11 | ||||
-rw-r--r-- | src/xkbcomp/keymap-dump.c | 4 | ||||
-rw-r--r-- | src/xkbcomp/keymap.c | 4 | ||||
-rw-r--r-- | src/xkbcomp/vmod.c | 6 |
8 files changed, 31 insertions, 21 deletions
diff --git a/src/keymap-priv.c b/src/keymap-priv.c index 73d722f..83d8894 100644 --- a/src/keymap-priv.c +++ b/src/keymap-priv.c @@ -45,7 +45,8 @@ update_builtin_keymap_fields(struct xkb_keymap *keymap) * Add predefined (AKA real, core, X11) modifiers. * The order is important! */ - darray_append_items(keymap->mods, builtin_mods, ARRAY_SIZE(builtin_mods)); + darray_append_items(keymap->mods.mods, + builtin_mods, ARRAY_SIZE(builtin_mods)); } struct xkb_keymap * @@ -129,7 +130,7 @@ XkbModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name, xkb_mod_index_t i; const struct xkb_mod *mod; - darray_enumerate(i, mod, keymap->mods) + darray_enumerate(i, mod, keymap->mods.mods) if ((mod->type & type) && name == mod->name) return i; diff --git a/src/keymap.c b/src/keymap.c index 9bf669b..fba8b18 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -93,7 +93,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap) free(keymap->sym_interprets); free(keymap->key_aliases); free(keymap->group_names); - darray_free(keymap->mods); + darray_free(keymap->mods.mods); darray_free(keymap->leds); free(keymap->keycodes_section_name); free(keymap->symbols_section_name); @@ -263,7 +263,7 @@ xkb_keymap_get_as_string(struct xkb_keymap *keymap, XKB_EXPORT xkb_mod_index_t xkb_keymap_num_mods(struct xkb_keymap *keymap) { - return darray_size(keymap->mods); + return darray_size(keymap->mods.mods); } /** @@ -272,10 +272,11 @@ xkb_keymap_num_mods(struct xkb_keymap *keymap) XKB_EXPORT const char * xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx) { - if (idx >= darray_size(keymap->mods)) + if (idx >= darray_size(keymap->mods.mods)) return NULL; - return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, idx).name); + return xkb_atom_text(keymap->ctx, + darray_item(keymap->mods.mods, idx).name); } /** diff --git a/src/keymap.h b/src/keymap.h index 3bc8c03..d84ea70 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -353,6 +353,10 @@ struct xkb_mod { xkb_mod_mask_t mapping; /* vmod -> real mod mapping */ }; +struct xkb_mod_set { + darray(struct xkb_mod) mods; +}; + /* Common keyboard description structure */ struct xkb_keymap { struct xkb_context *ctx; @@ -377,7 +381,7 @@ struct xkb_keymap { unsigned int num_sym_interprets; struct xkb_sym_interpret *sym_interprets; - darray(struct xkb_mod) mods; + struct xkb_mod_set mods; /* Number of groups in the key with the most groups. */ xkb_layout_index_t num_groups; @@ -212,10 +212,11 @@ ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx) if (ndx == XKB_MOD_INVALID) return "none"; - if (ndx >= darray_size(keymap->mods)) + if (ndx >= darray_size(keymap->mods.mods)) return NULL; - return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, ndx).name); + return xkb_atom_text(keymap->ctx, + darray_item(keymap->mods.mods, ndx).name); } const char * @@ -263,7 +264,7 @@ ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask) if (mask == MOD_REAL_MASK_ALL) return "all"; - darray_enumerate(i, mod, keymap->mods) { + darray_enumerate(i, mod, keymap->mods.mods) { int ret; if (!(mask & (1u << i))) diff --git a/src/x11/keymap.c b/src/x11/keymap.c index 76adf74..716fc51 100644 --- a/src/x11/keymap.c +++ b/src/x11/keymap.c @@ -508,13 +508,14 @@ get_vmods(struct xkb_keymap *keymap, xcb_connection_t *conn, { uint8_t *iter = xcb_xkb_get_map_map_vmods_rtrn(map); - darray_resize0(keymap->mods, + darray_resize0(keymap->mods.mods, NUM_REAL_MODS + msb_pos(reply->virtualMods)); for (unsigned i = 0; i < NUM_VMODS; i++) { if (reply->virtualMods & (1u << i)) { uint8_t wire = *iter; - struct xkb_mod *mod = &darray_item(keymap->mods, NUM_REAL_MODS + i); + struct xkb_mod *mod = &darray_item(keymap->mods.mods, + NUM_REAL_MODS + i); mod->type = MOD_VIRT; mod->mapping = translate_mods(wire, 0, 0); @@ -919,12 +920,14 @@ get_vmod_names(struct xkb_keymap *keymap, xcb_connection_t *conn, * tells us which vmods exist (a vmod must have a name), so we fix * up the size here. */ - darray_resize0(keymap->mods, NUM_REAL_MODS + msb_pos(reply->virtualMods)); + darray_resize0(keymap->mods.mods, + NUM_REAL_MODS + msb_pos(reply->virtualMods)); for (unsigned i = 0; i < NUM_VMODS; i++) { if (reply->virtualMods & (1u << i)) { xcb_atom_t wire = *iter; - struct xkb_mod *mod = &darray_item(keymap->mods, NUM_REAL_MODS + i); + struct xkb_mod *mod = &darray_item(keymap->mods.mods, + NUM_REAL_MODS + i); if (!adopt_atom(keymap->ctx, conn, wire, &mod->name)) return false; diff --git a/src/xkbcomp/keymap-dump.c b/src/xkbcomp/keymap-dump.c index 7f70ca3..9e3f3e8 100644 --- a/src/xkbcomp/keymap-dump.c +++ b/src/xkbcomp/keymap-dump.c @@ -126,7 +126,7 @@ write_vmods(struct xkb_keymap *keymap, struct buf *buf) const struct xkb_mod *mod; xkb_mod_index_t num_vmods = 0; - darray_foreach(mod, keymap->mods) { + darray_foreach(mod, keymap->mods.mods) { if (mod->type != MOD_VIRT) continue; @@ -621,7 +621,7 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf) if (key->modmap == 0) continue; - darray_enumerate(i, mod, keymap->mods) + darray_enumerate(i, mod, keymap->mods.mods) if (key->modmap & (1u << i)) write_buf(buf, "\tmodifier_map %s { %s };\n", xkb_atom_text(keymap->ctx, mod->name), diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c index 8a70577..3e067f7 100644 --- a/src/xkbcomp/keymap.c +++ b/src/xkbcomp/keymap.c @@ -38,7 +38,7 @@ ComputeEffectiveMask(struct xkb_keymap *keymap, struct xkb_mods *mods) /* The effective mask is only real mods for now. */ mods->mask = mods->mods & MOD_REAL_MASK_ALL; - darray_enumerate(i, mod, keymap->mods) + darray_enumerate(i, mod, keymap->mods.mods) if (mods->mods & (1u << i)) mods->mask |= mod->mapping; } @@ -193,7 +193,7 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap) /* Update keymap->mods, the virtual -> real mod mapping. */ xkb_foreach_key(key, keymap) - darray_enumerate(i, mod, keymap->mods) + darray_enumerate(i, mod, keymap->mods.mods) if (key->vmodmap & (1u << i)) mod->mapping |= key->modmap; diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index 86e7bec..95b86bd 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -57,7 +57,7 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt, mapping = 0; } - darray_enumerate(i, mod, keymap->mods) { + darray_enumerate(i, mod, keymap->mods.mods) { if (mod->name == stmt->name) { if (mod->type != MOD_VIRT) { log_err(keymap->ctx, @@ -91,7 +91,7 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt, } } - if (darray_size(keymap->mods) >= XKB_MAX_MODS) { + if (darray_size(keymap->mods.mods) >= XKB_MAX_MODS) { log_err(keymap->ctx, "Too many modifiers defined (maximum %d)\n", XKB_MAX_MODS); @@ -101,6 +101,6 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt, new.name = stmt->name; new.mapping = mapping; new.type = MOD_VIRT; - darray_append(keymap->mods, new); + darray_append(keymap->mods.mods, new); return true; } |