symbols: improve FindKeyForSymbol()
A bit more involved, but can short circuit. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
485b736f17
commit
2c259f1782
|
@ -1243,38 +1243,32 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
|
||||||
static struct xkb_key *
|
static struct xkb_key *
|
||||||
FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
|
FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
|
||||||
{
|
{
|
||||||
struct xkb_key *key, *ret = NULL;
|
struct xkb_key *key;
|
||||||
xkb_layout_index_t group, min_group = UINT32_MAX;
|
xkb_layout_index_t group;
|
||||||
xkb_level_index_t level, min_level = UINT32_MAX;
|
xkb_level_index_t level;
|
||||||
|
bool got_one_group, got_one_level;
|
||||||
|
|
||||||
xkb_keys_foreach(key, keymap) {
|
group = 0;
|
||||||
for (group = 0; group < key->num_groups; group++) {
|
do {
|
||||||
for (level = 0; level < XkbKeyGroupWidth(key, group); level++) {
|
got_one_group = false;
|
||||||
if (key->groups[group].levels[level].num_syms != 1 ||
|
level = 0;
|
||||||
key->groups[group].levels[level].u.sym != sym)
|
do {
|
||||||
continue;
|
got_one_level = false;
|
||||||
|
xkb_keys_foreach(key, keymap) {
|
||||||
/*
|
if (group < key->num_groups &&
|
||||||
* If the keysym was found in a group or level > 0, we must
|
level < XkbKeyGroupWidth(key, group)) {
|
||||||
* keep looking since we might find a key in which the keysym
|
got_one_group = got_one_level = true;
|
||||||
* is in a lower group or level.
|
if (key->groups[group].levels[level].num_syms == 1 &&
|
||||||
*/
|
key->groups[group].levels[level].u.sym == sym)
|
||||||
if (group < min_group ||
|
return key;
|
||||||
(group == min_group && level < min_level)) {
|
|
||||||
ret = key;
|
|
||||||
if (group == 0 && level == 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
min_group = group;
|
|
||||||
min_level = level;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
level++;
|
||||||
}
|
} while (got_one_level);
|
||||||
|
group++;
|
||||||
|
} while (got_one_group);
|
||||||
|
|
||||||
return ret;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue