Store actions inside struct xkb_key
Cuts out a lot of useless redirection and space. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
7bcc5fabbd
commit
87dff888ab
|
@ -732,7 +732,7 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key->explicit & XkbExplicitInterpretMask)
|
if (key->explicit & XkbExplicitInterpretMask)
|
||||||
showActions = XkbKeyHasActions(key);
|
showActions = (key->actions != NULL);
|
||||||
else
|
else
|
||||||
showActions = false;
|
showActions = false;
|
||||||
|
|
||||||
|
@ -746,10 +746,8 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
||||||
write_buf(buf, " ] };\n");
|
write_buf(buf, " ] };\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
union xkb_action *acts;
|
xkb_level_index_t level;
|
||||||
int level;
|
|
||||||
|
|
||||||
acts = XkbKeyActionsPtr(keymap, key);
|
|
||||||
for (group = 0; group < key->num_groups; group++) {
|
for (group = 0; group < key->num_groups; group++) {
|
||||||
if (group != 0)
|
if (group != 0)
|
||||||
write_buf(buf, ",");
|
write_buf(buf, ",");
|
||||||
|
@ -765,10 +763,11 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
||||||
level++) {
|
level++) {
|
||||||
if (level != 0)
|
if (level != 0)
|
||||||
write_buf(buf, ", ");
|
write_buf(buf, ", ");
|
||||||
write_action(keymap, buf, &acts[level], NULL, NULL);
|
write_action(keymap, buf,
|
||||||
|
XkbKeyActionEntry(key, group, level),
|
||||||
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
write_buf(buf, " ]");
|
write_buf(buf, " ]");
|
||||||
acts += key->width;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_buf(buf, "\n\t\t};\n");
|
write_buf(buf, "\n\t\t};\n");
|
||||||
|
|
|
@ -118,7 +118,7 @@ xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
|
||||||
if (XkbKeycodeInRange(state->keymap, kc))
|
if (XkbKeycodeInRange(state->keymap, kc))
|
||||||
key = XkbKey(state->keymap, kc);
|
key = XkbKey(state->keymap, kc);
|
||||||
|
|
||||||
if (!key || !XkbKeyHasActions(key))
|
if (!key || !key->actions)
|
||||||
return &fake;
|
return &fake;
|
||||||
|
|
||||||
group = xkb_key_get_group(state, kc);
|
group = xkb_key_get_group(state, kc);
|
||||||
|
@ -129,7 +129,7 @@ xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
|
||||||
if (level == XKB_LEVEL_INVALID)
|
if (level == XKB_LEVEL_INVALID)
|
||||||
return &fake;
|
return &fake;
|
||||||
|
|
||||||
return XkbKeyActionEntry(state->keymap, key, group, level);
|
return XkbKeyActionEntry(key, group, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct xkb_filter *
|
static struct xkb_filter *
|
||||||
|
|
|
@ -321,8 +321,7 @@ struct xkb_key {
|
||||||
|
|
||||||
bool repeats;
|
bool repeats;
|
||||||
|
|
||||||
/* Index into keymap->acts */
|
union xkb_action *actions;
|
||||||
size_t acts_index;
|
|
||||||
|
|
||||||
unsigned char kt_index[XkbNumKbdGroups];
|
unsigned char kt_index[XkbNumKbdGroups];
|
||||||
|
|
||||||
|
@ -369,8 +368,6 @@ struct xkb_keymap {
|
||||||
struct xkb_mods groups[XkbNumKbdGroups];
|
struct xkb_mods groups[XkbNumKbdGroups];
|
||||||
const char *group_names[XkbNumKbdGroups];
|
const char *group_names[XkbNumKbdGroups];
|
||||||
|
|
||||||
darray(union xkb_action) acts;
|
|
||||||
|
|
||||||
struct xkb_indicator_map indicators[XkbNumIndicators];
|
struct xkb_indicator_map indicators[XkbNumIndicators];
|
||||||
const char *indicator_names[XkbNumIndicators];
|
const char *indicator_names[XkbNumIndicators];
|
||||||
|
|
||||||
|
@ -446,33 +443,11 @@ XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group,
|
||||||
return XkbKeySym(key, XkbKeySymOffset(key, group, level));
|
return XkbKeySym(key, XkbKeySymOffset(key, group, level));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
|
||||||
XkbKeyHasActions(struct xkb_key *key)
|
|
||||||
{
|
|
||||||
return key->acts_index != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline unsigned int
|
|
||||||
XkbKeyNumActions(struct xkb_key *key)
|
|
||||||
{
|
|
||||||
if (XkbKeyHasActions(key))
|
|
||||||
return key->width * key->num_groups;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline union xkb_action *
|
static inline union xkb_action *
|
||||||
XkbKeyActionsPtr(struct xkb_keymap *keymap, struct xkb_key *key)
|
XkbKeyActionEntry(struct xkb_key *key, xkb_group_index_t group,
|
||||||
|
xkb_level_index_t level)
|
||||||
{
|
{
|
||||||
return darray_mem(keymap->acts, key->acts_index);
|
return &key->actions[key->width * group + level];
|
||||||
}
|
|
||||||
|
|
||||||
static inline union xkb_action *
|
|
||||||
XkbKeyActionEntry(struct xkb_keymap *keymap, struct xkb_key *key,
|
|
||||||
xkb_group_index_t group, xkb_level_index_t level)
|
|
||||||
{
|
|
||||||
if (XkbKeyHasActions(key))
|
|
||||||
return &XkbKeyActionsPtr(keymap, key)[key->width * group + level];
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
|
|
|
@ -1296,45 +1296,3 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
|
||||||
old->next = new;
|
old->next = new;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***====================================================================***/
|
|
||||||
|
|
||||||
union xkb_action *
|
|
||||||
ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
|
|
||||||
uint32_t needed)
|
|
||||||
{
|
|
||||||
size_t old_ndx, old_num_acts, new_ndx;
|
|
||||||
|
|
||||||
if (needed == 0) {
|
|
||||||
key->acts_index = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XkbKeyHasActions(key) && key->width >= needed)
|
|
||||||
return XkbKeyActionsPtr(keymap, key);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The key may already be in the array, but without enough space.
|
|
||||||
* This should not happen often, so in order to avoid moving and
|
|
||||||
* copying stuff from acts and key_acts, we just allocate new
|
|
||||||
* space for the key at the end, and leave the old space alone.
|
|
||||||
*/
|
|
||||||
|
|
||||||
old_ndx = key->acts_index;
|
|
||||||
old_num_acts = XkbKeyNumActions(key);
|
|
||||||
new_ndx = darray_size(keymap->acts);
|
|
||||||
|
|
||||||
darray_resize0(keymap->acts, new_ndx + needed);
|
|
||||||
key->acts_index = 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->acts, new_ndx),
|
|
||||||
darray_mem(keymap->acts, old_ndx),
|
|
||||||
old_num_acts * sizeof(union xkb_action));
|
|
||||||
|
|
||||||
return XkbKeyActionsPtr(keymap, key);
|
|
||||||
}
|
|
||||||
|
|
|
@ -76,10 +76,6 @@ SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
|
||||||
ExprDef *index, ExprDef *value,
|
ExprDef *index, ExprDef *value,
|
||||||
ActionInfo **info_rtrn);
|
ActionInfo **info_rtrn);
|
||||||
|
|
||||||
union xkb_action *
|
|
||||||
ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
|
|
||||||
uint32_t needed);
|
|
||||||
|
|
||||||
extern const LookupEntry ctrlNames[];
|
extern const LookupEntry ctrlNames[];
|
||||||
|
|
||||||
#endif /* ACTION_H */
|
#endif /* ACTION_H */
|
||||||
|
|
|
@ -1382,7 +1382,6 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
|
||||||
{
|
{
|
||||||
#define INTERP_SIZE (8 * 4)
|
#define INTERP_SIZE (8 * 4)
|
||||||
struct xkb_sym_interpret *interps[INTERP_SIZE];
|
struct xkb_sym_interpret *interps[INTERP_SIZE];
|
||||||
union xkb_action *acts;
|
|
||||||
xkb_mod_mask_t vmodmask = 0;
|
xkb_mod_mask_t vmodmask = 0;
|
||||||
int num_acts = 0;
|
int num_acts = 0;
|
||||||
xkb_group_index_t group;
|
xkb_group_index_t group;
|
||||||
|
@ -1408,11 +1407,12 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_acts)
|
if (num_acts && !key->actions) {
|
||||||
num_acts = key->num_groups * key->width;
|
key->actions = calloc(key->num_groups * key->width,
|
||||||
acts = ResizeKeyActions(keymap, key, num_acts);
|
sizeof(*key->actions));
|
||||||
if (num_acts && !acts)
|
if (!key->actions)
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (group = 0; group < key->num_groups; group++) {
|
for (group = 0; group < key->num_groups; group++) {
|
||||||
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
|
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
|
||||||
|
@ -1437,7 +1437,8 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
|
||||||
if (interp->virtual_mod != XkbNoModifier)
|
if (interp->virtual_mod != XkbNoModifier)
|
||||||
vmodmask |= (1 << interp->virtual_mod);
|
vmodmask |= (1 << interp->virtual_mod);
|
||||||
}
|
}
|
||||||
acts[i] = interp->act;
|
|
||||||
|
key->actions[i] = interp->act;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1496,9 +1497,11 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
|
||||||
|
|
||||||
/* Update action modifiers. */
|
/* Update action modifiers. */
|
||||||
xkb_foreach_key(key, keymap) {
|
xkb_foreach_key(key, keymap) {
|
||||||
union xkb_action *acts = XkbKeyActionsPtr(keymap, key);
|
if (!key->actions)
|
||||||
for (i = 0; i < XkbKeyNumActions(key); i++)
|
continue;
|
||||||
UpdateActionMods(keymap, &acts[i], key->modmap);
|
|
||||||
|
for (i = 0; i < key->num_groups * key->width; i++)
|
||||||
|
UpdateActionMods(keymap, &key->actions[i], key->modmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update group modifiers. */
|
/* Update group modifiers. */
|
||||||
|
|
|
@ -1691,7 +1691,6 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
|
||||||
struct xkb_key_type * type;
|
struct xkb_key_type * type;
|
||||||
bool haveActions, autoType, useAlias;
|
bool haveActions, autoType, useAlias;
|
||||||
unsigned types[XkbNumKbdGroups];
|
unsigned types[XkbNumKbdGroups];
|
||||||
union xkb_action *outActs;
|
|
||||||
unsigned int symIndex = 0;
|
unsigned int symIndex = 0;
|
||||||
|
|
||||||
useAlias = (start_from == 0);
|
useAlias = (start_from == 0);
|
||||||
|
@ -1769,27 +1768,23 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
|
||||||
|
|
||||||
darray_resize0(key->syms, sizeSyms);
|
darray_resize0(key->syms, sizeSyms);
|
||||||
|
|
||||||
|
key->num_groups = nGroups;
|
||||||
|
|
||||||
|
key->width = width;
|
||||||
|
|
||||||
|
key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
|
||||||
|
|
||||||
|
key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
|
||||||
|
|
||||||
if (haveActions) {
|
if (haveActions) {
|
||||||
outActs = ResizeKeyActions(keymap, key, width * nGroups);
|
key->actions = calloc(nGroups * width, sizeof(*key->actions));
|
||||||
if (outActs == NULL) {
|
|
||||||
log_wsgo(info->keymap->ctx,
|
|
||||||
"Could not enlarge actions for %s (key %d)\n",
|
|
||||||
LongKeyNameText(keyi->name), kc);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
key->explicit |= XkbExplicitInterpretMask;
|
key->explicit |= XkbExplicitInterpretMask;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
outActs = NULL;
|
|
||||||
|
|
||||||
key->num_groups = nGroups;
|
|
||||||
if (keyi->defined & KEY_FIELD_GROUPINFO) {
|
if (keyi->defined & KEY_FIELD_GROUPINFO) {
|
||||||
key->out_of_range_group_number = keyi->out_of_range_group_number;
|
key->out_of_range_group_number = keyi->out_of_range_group_number;
|
||||||
key->out_of_range_group_action = keyi->out_of_range_group_action;
|
key->out_of_range_group_action = keyi->out_of_range_group_action;
|
||||||
}
|
}
|
||||||
key->width = width;
|
|
||||||
key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
|
|
||||||
key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
|
|
||||||
|
|
||||||
for (i = 0; i < nGroups; i++) {
|
for (i = 0; i < nGroups; i++) {
|
||||||
/* assign kt_index[i] to the index of the type in map->types.
|
/* assign kt_index[i] to the index of the type in map->types.
|
||||||
|
@ -1820,11 +1815,11 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
|
||||||
key->sym_index[(i * width) + tmp] = -1;
|
key->sym_index[(i * width) + tmp] = -1;
|
||||||
key->num_syms[(i * width) + tmp] = 0;
|
key->num_syms[(i * width) + tmp] = 0;
|
||||||
}
|
}
|
||||||
if (outActs != NULL && !darray_empty(keyi->acts[i])) {
|
if (key->actions && !darray_empty(keyi->acts[i])) {
|
||||||
if (tmp < keyi->numLevels[i])
|
if (tmp < keyi->numLevels[i])
|
||||||
outActs[tmp] = darray_item(keyi->acts[i], tmp);
|
key->actions[tmp] = darray_item(keyi->acts[i], tmp);
|
||||||
else
|
else
|
||||||
outActs[tmp].type = XkbSA_NoAction;
|
key->actions[tmp].type = XkbSA_NoAction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1906,8 +1901,6 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
|
||||||
if (info.errorCount != 0)
|
if (info.errorCount != 0)
|
||||||
goto err_info;
|
goto err_info;
|
||||||
|
|
||||||
darray_resize0(keymap->acts, darray_size(keymap->acts) + 32 + 1);
|
|
||||||
|
|
||||||
if (info.name)
|
if (info.name)
|
||||||
keymap->symbols_section_name = strdup(info.name);
|
keymap->symbols_section_name = strdup(info.name);
|
||||||
|
|
||||||
|
|
|
@ -333,11 +333,10 @@ xkb_map_unref(struct xkb_keymap *keymap)
|
||||||
free(key->sym_index);
|
free(key->sym_index);
|
||||||
free(key->num_syms);
|
free(key->num_syms);
|
||||||
darray_free(key->syms);
|
darray_free(key->syms);
|
||||||
|
free(key->actions);
|
||||||
}
|
}
|
||||||
darray_free(keymap->keys);
|
darray_free(keymap->keys);
|
||||||
|
|
||||||
darray_free(keymap->acts);
|
|
||||||
|
|
||||||
darray_free(keymap->sym_interpret);
|
darray_free(keymap->sym_interpret);
|
||||||
|
|
||||||
darray_free(keymap->key_aliases);
|
darray_free(keymap->key_aliases);
|
||||||
|
|
Loading…
Reference in New Issue