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>
master
Ran Benita 2013-02-08 13:09:33 +02:00
parent 3d7aff5fcd
commit ca3170ad38
8 changed files with 31 additions and 21 deletions

View File

@ -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;

View File

@ -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);
}
/**

View File

@ -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;

View File

@ -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)))

View File

@ -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;

View File

@ -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),

View File

@ -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;

View File

@ -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;
}