keymap: store a pointer to the type in xkb_group instead of index
Gets rid of some more unneeded indirection, including the XkbKeyType macro. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
01b00d7540
commit
c955f8e2f9
|
@ -565,7 +565,7 @@ write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
|
|||
#define OUT_BUF_LEN 128
|
||||
char out_buf[OUT_BUF_LEN];
|
||||
|
||||
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group); level++) {
|
||||
for (level = 0; level < XkbKeyGroupWidth(key, group); level++) {
|
||||
if (level != 0)
|
||||
write_buf(buf, ", ");
|
||||
num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode,
|
||||
|
@ -634,13 +634,12 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
|||
if (key->groups[group].explicit_type)
|
||||
explicit_types = true;
|
||||
|
||||
if (group != 0 &&
|
||||
XkbKeyType(keymap, key, group) != XkbKeyType(keymap, key, 0))
|
||||
if (group != 0 && key->groups[group].type != key->groups[0].type)
|
||||
multi_type = true;
|
||||
}
|
||||
|
||||
if (explicit_types) {
|
||||
struct xkb_key_type *type = XkbKeyType(keymap, key, 0);
|
||||
const struct xkb_key_type *type;
|
||||
simple = false;
|
||||
|
||||
if (multi_type) {
|
||||
|
@ -648,13 +647,14 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
|||
if (!key->groups[group].explicit_type)
|
||||
continue;
|
||||
|
||||
type = XkbKeyType(keymap, key, group);
|
||||
type = key->groups[group].type;
|
||||
write_buf(buf, "\n\t\t\ttype[group%u]= \"%s\",",
|
||||
group + 1,
|
||||
xkb_atom_text(keymap->ctx, type->name));
|
||||
}
|
||||
}
|
||||
else {
|
||||
type = key->groups[0].type;
|
||||
write_buf(buf, "\n\t\t\ttype= \"%s\",",
|
||||
xkb_atom_text(keymap->ctx, type->name));
|
||||
}
|
||||
|
@ -713,8 +713,7 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
|||
write_buf(buf, ",\n\t\t\tactions[Group%u]= [ ",
|
||||
group + 1);
|
||||
for (level = 0;
|
||||
level < XkbKeyGroupWidth(keymap, key, group);
|
||||
level++) {
|
||||
level < XkbKeyGroupWidth(key, group); level++) {
|
||||
if (level != 0)
|
||||
write_buf(buf, ", ");
|
||||
write_action(keymap, buf,
|
||||
|
|
|
@ -91,7 +91,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
|
|||
|
||||
darray_foreach(key, keymap->keys) {
|
||||
for (i = 0; i < key->num_groups; i++) {
|
||||
for (j = 0; j < XkbKeyGroupWidth(keymap, key, i); j++)
|
||||
for (j = 0; j < XkbKeyGroupWidth(key, i); j++)
|
||||
if (key->groups[i].levels[j].num_syms > 1)
|
||||
free(key->groups[i].levels[j].u.syms);
|
||||
free(key->groups[i].levels);
|
||||
|
@ -248,7 +248,7 @@ xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc,
|
|||
if (!key)
|
||||
return 0;
|
||||
|
||||
return XkbKeyGroupWidth(keymap, key, layout);
|
||||
return XkbKeyGroupWidth(key, layout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,7 +318,7 @@ xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
|
|||
goto err;
|
||||
if (layout >= key->num_groups)
|
||||
goto err;
|
||||
if (level >= XkbKeyGroupWidth(keymap, key, layout))
|
||||
if (level >= XkbKeyGroupWidth(key, layout))
|
||||
goto err;
|
||||
|
||||
num_syms = XkbKeyNumSyms(key, layout, level);
|
||||
|
|
15
src/keymap.h
15
src/keymap.h
|
@ -331,7 +331,8 @@ struct xkb_level {
|
|||
|
||||
struct xkb_group {
|
||||
bool explicit_type;
|
||||
unsigned type_index;
|
||||
/* Points to a type in keymap->types. */
|
||||
const struct xkb_key_type *type;
|
||||
/* Use XkbKeyGroupWidth for the number of levels. */
|
||||
struct xkb_level *levels;
|
||||
};
|
||||
|
@ -406,18 +407,10 @@ XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
|
|||
#define xkb_foreach_key(iter, keymap) \
|
||||
darray_foreach(iter, keymap->keys)
|
||||
|
||||
static inline struct xkb_key_type *
|
||||
XkbKeyType(struct xkb_keymap *keymap, const struct xkb_key *key,
|
||||
xkb_layout_index_t layout)
|
||||
{
|
||||
return &keymap->types[key->groups[layout].type_index];
|
||||
}
|
||||
|
||||
static inline xkb_level_index_t
|
||||
XkbKeyGroupWidth(struct xkb_keymap *keymap, const struct xkb_key *key,
|
||||
xkb_layout_index_t layout)
|
||||
XkbKeyGroupWidth(const struct xkb_key *key, xkb_layout_index_t layout)
|
||||
{
|
||||
return XkbKeyType(keymap, key, layout)->num_levels;
|
||||
return key->groups[layout].type->num_levels;
|
||||
}
|
||||
|
||||
static inline unsigned int
|
||||
|
|
10
src/state.c
10
src/state.c
|
@ -105,15 +105,15 @@ struct xkb_state {
|
|||
struct xkb_keymap *keymap;
|
||||
};
|
||||
|
||||
static struct xkb_kt_map_entry *
|
||||
static const struct xkb_kt_map_entry *
|
||||
get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
|
||||
xkb_layout_index_t group)
|
||||
{
|
||||
struct xkb_key_type *type;
|
||||
const struct xkb_key_type *type;
|
||||
xkb_mod_mask_t active_mods;
|
||||
unsigned int i;
|
||||
|
||||
type = XkbKeyType(state->keymap, key, group);
|
||||
type = key->groups[group].type;
|
||||
active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
|
||||
active_mods &= type->mods.mask;
|
||||
|
||||
|
@ -133,7 +133,7 @@ xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
|
|||
xkb_layout_index_t layout)
|
||||
{
|
||||
const struct xkb_key *key = XkbKey(state->keymap, kc);
|
||||
struct xkb_kt_map_entry *entry;
|
||||
const struct xkb_kt_map_entry *entry;
|
||||
|
||||
if (!key || layout >= key->num_groups)
|
||||
return XKB_LEVEL_INVALID;
|
||||
|
@ -1019,7 +1019,7 @@ xkb_state_led_name_is_active(struct xkb_state *state, const char *name)
|
|||
static xkb_mod_mask_t
|
||||
key_get_consumed(struct xkb_state *state, const struct xkb_key *key)
|
||||
{
|
||||
struct xkb_kt_map_entry *entry;
|
||||
const struct xkb_kt_map_entry *entry;
|
||||
xkb_layout_index_t group;
|
||||
|
||||
group = xkb_state_key_get_layout(state, key->keycode);
|
||||
|
|
|
@ -139,7 +139,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
|
|||
return true;
|
||||
|
||||
for (group = 0; group < key->num_groups; group++) {
|
||||
width = XkbKeyGroupWidth(keymap, key, group);
|
||||
width = XkbKeyGroupWidth(key, group);
|
||||
for (level = 0; level < width; level++) {
|
||||
struct xkb_sym_interpret *interp;
|
||||
|
||||
|
@ -220,7 +220,7 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap)
|
|||
/* Update action modifiers. */
|
||||
xkb_foreach_key(key, keymap)
|
||||
for (i = 0; i < key->num_groups; i++)
|
||||
for (j = 0; j < XkbKeyGroupWidth(keymap, key, i); j++)
|
||||
for (j = 0; j < XkbKeyGroupWidth(key, i); j++)
|
||||
UpdateActionMods(keymap, &key->groups[i].levels[j].action,
|
||||
key->modmap);
|
||||
|
||||
|
|
|
@ -1308,7 +1308,7 @@ FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
|
|||
|
||||
xkb_foreach_key(key, keymap) {
|
||||
for (group = 0; group < key->num_groups; group++) {
|
||||
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
|
||||
for (level = 0; level < XkbKeyGroupWidth(key, group);
|
||||
level++) {
|
||||
if (XkbKeyNumSyms(key, group, level) != 1 ||
|
||||
(XkbKeySymEntry(key, group, level))[0] != sym)
|
||||
|
@ -1338,13 +1338,14 @@ FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
|
|||
}
|
||||
|
||||
static bool
|
||||
FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
|
||||
FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name,
|
||||
const struct xkb_key_type **type_rtrn)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < keymap->num_types; i++) {
|
||||
if (keymap->types[i].name == name) {
|
||||
*type_rtrn = i;
|
||||
*type_rtrn = &keymap->types[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1472,7 +1473,6 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
|
|||
|
||||
/* * Find and assign the groups' types in the keymap. */
|
||||
darray_enumerate(i, groupi, keyi->groups) {
|
||||
struct xkb_key_type *type;
|
||||
struct xkb_group *group = &key->groups[i];
|
||||
bool autoType = false;
|
||||
|
||||
|
@ -1492,10 +1492,11 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
|
|||
}
|
||||
|
||||
/* Find the type in the keymap, if it was defined in xkb_types. */
|
||||
if (FindNamedType(keymap, groupi->type, &group->type_index)) {
|
||||
if (FindNamedType(keymap, groupi->type, &group->type)) {
|
||||
if (!autoType || darray_size(groupi->levels) > 2)
|
||||
key->groups[i].explicit_type = true;
|
||||
}
|
||||
/* Not found, use a default. */
|
||||
else {
|
||||
log_vrb(info->keymap->ctx, 3,
|
||||
"Type \"%s\" is not defined; "
|
||||
|
@ -1506,26 +1507,26 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
|
|||
* Index 0 is guaranteed to contain something, usually
|
||||
* ONE_LEVEL or at least some default one-level type.
|
||||
*/
|
||||
group->type_index = 0;
|
||||
group->type = &keymap->types[0];
|
||||
}
|
||||
|
||||
/* Always have as many levels as the type specifies. */
|
||||
type = &keymap->types[group->type_index];
|
||||
if (type->num_levels < darray_size(groupi->levels)) {
|
||||
if (group->type->num_levels < darray_size(groupi->levels)) {
|
||||
struct xkb_level *leveli;
|
||||
|
||||
log_vrb(info->keymap->ctx, 1,
|
||||
"Type \"%s\" has %d levels, but %s has %d levels; "
|
||||
"Ignoring extra symbols\n",
|
||||
xkb_atom_text(keymap->ctx, type->name),
|
||||
type->num_levels,
|
||||
xkb_atom_text(keymap->ctx, group->type->name),
|
||||
group->type->num_levels,
|
||||
LongKeyNameText(keyi->name),
|
||||
(int) darray_size(groupi->levels));
|
||||
|
||||
darray_foreach_from(leveli, groupi->levels, type->num_levels)
|
||||
darray_foreach_from(leveli, groupi->levels,
|
||||
group->type->num_levels)
|
||||
ClearLevelInfo(leveli);
|
||||
}
|
||||
darray_resize0(groupi->levels, type->num_levels);
|
||||
darray_resize0(groupi->levels, group->type->num_levels);
|
||||
}
|
||||
|
||||
/* Copy levels. */
|
||||
|
|
Loading…
Reference in New Issue