state, map: constify references to xkb_key

Makes it clear that we treat the keys as immutible values in these
files.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-09-14 11:17:30 +03:00
parent 841f32230a
commit c2570d51d1
6 changed files with 54 additions and 44 deletions

View File

@ -367,7 +367,8 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf, int num)
static bool
write_action(struct xkb_keymap *keymap, struct buf *buf,
union xkb_action *action, const char *prefix, const char *suffix)
const union xkb_action *action,
const char *prefix, const char *suffix)
{
const char *type;
const char *args = NULL;

View File

@ -218,7 +218,7 @@ xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name)
XKB_EXPORT xkb_group_index_t
xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
struct xkb_key *key = XkbKey(keymap, kc);
const struct xkb_key *key = XkbKey(keymap, kc);
if (!key)
return 0;
@ -276,7 +276,7 @@ xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name)
}
static struct xkb_kt_map_entry *
get_entry_for_key_state(struct xkb_state *state, struct xkb_key *key,
get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
xkb_group_index_t group)
{
struct xkb_key_type *type;
@ -299,7 +299,7 @@ get_entry_for_key_state(struct xkb_state *state, struct xkb_key *key,
* XKB_LEVEL_INVALID.
*/
xkb_level_index_t
xkb_key_get_level(struct xkb_state *state, struct xkb_key *key,
xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
xkb_group_index_t group)
{
struct xkb_kt_map_entry *entry;
@ -317,7 +317,7 @@ xkb_key_get_level(struct xkb_state *state, struct xkb_key *key,
* wrapping/clamping/etc into account, or XKB_GROUP_INVALID.
*/
xkb_group_index_t
xkb_key_get_group(struct xkb_state *state, struct xkb_key *key)
xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key)
{
xkb_group_index_t ret = xkb_state_serialize_group(state,
XKB_STATE_EFFECTIVE);
@ -352,7 +352,8 @@ xkb_key_get_group(struct xkb_state *state, struct xkb_key *key)
* As below, but takes an explicit group/level rather than state.
*/
int
xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
xkb_key_get_syms_by_level(struct xkb_keymap *keymap,
const struct xkb_key *key,
xkb_group_index_t group, xkb_level_index_t level,
const xkb_keysym_t **syms_out)
{
@ -384,11 +385,9 @@ xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
const xkb_keysym_t **syms_out)
{
struct xkb_keymap *keymap = xkb_state_get_map(state);
struct xkb_key *key;
xkb_group_index_t group;
xkb_level_index_t level;
key = XkbKey(keymap, kc);
const struct xkb_key *key = XkbKey(keymap, kc);
if (!key)
return -1;
@ -413,7 +412,7 @@ err:
XKB_EXPORT int
xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
struct xkb_key *key = XkbKey(keymap, kc);
const struct xkb_key *key = XkbKey(keymap, kc);
if (!key)
return 0;
@ -421,7 +420,7 @@ xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc)
}
static xkb_mod_mask_t
key_get_consumed(struct xkb_state *state, struct xkb_key *key)
key_get_consumed(struct xkb_state *state, const struct xkb_key *key)
{
struct xkb_kt_map_entry *entry;
xkb_group_index_t group;
@ -453,7 +452,7 @@ XKB_EXPORT int
xkb_key_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t kc,
xkb_mod_index_t idx)
{
struct xkb_key *key = XkbKey(xkb_state_get_map(state), kc);
const struct xkb_key *key = XkbKey(xkb_state_get_map(state), kc);
if (!key)
return 0;
@ -472,7 +471,7 @@ XKB_EXPORT xkb_mod_mask_t
xkb_key_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t kc,
xkb_mod_mask_t mask)
{
struct xkb_key *key = XkbKey(xkb_state_get_map(state), kc);
const struct xkb_key *key = XkbKey(xkb_state_get_map(state), kc);
if (!key)
return 0;

View File

@ -67,10 +67,10 @@
struct xkb_filter {
struct xkb_state *state;
union xkb_action action;
struct xkb_key *key;
const struct xkb_key *key;
uint32_t priv;
int (*func)(struct xkb_filter *filter,
struct xkb_key *key,
const struct xkb_key *key,
enum xkb_key_direction direction);
int refcnt;
};
@ -110,7 +110,7 @@ struct xkb_state {
static const union xkb_action fake = { .type = ACTION_TYPE_NONE };
static const union xkb_action *
xkb_key_get_action(struct xkb_state *state, struct xkb_key *key)
xkb_key_get_action(struct xkb_state *state, const struct xkb_key *key)
{
xkb_group_index_t group;
xkb_level_index_t level;
@ -154,7 +154,8 @@ xkb_filter_new(struct xkb_state *state)
/***====================================================================***/
static int
xkb_filter_group_set_func(struct xkb_filter *filter, struct xkb_key *key,
xkb_filter_group_set_func(struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
if (key != filter->key) {
@ -183,7 +184,8 @@ xkb_filter_group_set_func(struct xkb_filter *filter, struct xkb_key *key,
}
static int
xkb_filter_group_set_new(struct xkb_state *state, struct xkb_key *key,
xkb_filter_group_set_new(struct xkb_state *state,
const struct xkb_key *key,
const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@ -206,7 +208,8 @@ xkb_filter_group_set_new(struct xkb_state *state, struct xkb_key *key,
}
static int
xkb_filter_group_lock_func(struct xkb_filter *filter, struct xkb_key *key,
xkb_filter_group_lock_func(struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
if (key != filter->key)
@ -224,7 +227,8 @@ xkb_filter_group_lock_func(struct xkb_filter *filter, struct xkb_key *key,
}
static int
xkb_filter_group_lock_new(struct xkb_state *state, struct xkb_key *key,
xkb_filter_group_lock_new(struct xkb_state *state,
const struct xkb_key *key,
const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@ -244,7 +248,8 @@ xkb_filter_group_lock_new(struct xkb_state *state, struct xkb_key *key,
}
static int
xkb_filter_mod_set_func(struct xkb_filter *filter, struct xkb_key *key,
xkb_filter_mod_set_func(struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
if (key != filter->key) {
@ -269,7 +274,8 @@ xkb_filter_mod_set_func(struct xkb_filter *filter, struct xkb_key *key,
}
static int
xkb_filter_mod_set_new(struct xkb_state *state, struct xkb_key *key,
xkb_filter_mod_set_new(struct xkb_state *state,
const struct xkb_key *key,
const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@ -286,7 +292,8 @@ xkb_filter_mod_set_new(struct xkb_state *state, struct xkb_key *key,
}
static int
xkb_filter_mod_lock_func(struct xkb_filter *filter, struct xkb_key *key,
xkb_filter_mod_lock_func(struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
if (key != filter->key)
@ -306,7 +313,8 @@ xkb_filter_mod_lock_func(struct xkb_filter *filter, struct xkb_key *key,
}
static int
xkb_filter_mod_lock_new(struct xkb_state *state, struct xkb_key *key,
xkb_filter_mod_lock_new(struct xkb_state *state,
const struct xkb_key *key,
const union xkb_action *action)
{
struct xkb_filter *filter = xkb_filter_new(state);
@ -348,7 +356,8 @@ xkb_action_breaks_latch(const union xkb_action *action)
}
static int
xkb_filter_mod_latch_func(struct xkb_filter *filter, struct xkb_key *key,
xkb_filter_mod_latch_func(struct xkb_filter *filter,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
enum xkb_key_latch_state latch = filter->priv;
@ -426,7 +435,8 @@ xkb_filter_mod_latch_func(struct xkb_filter *filter, struct xkb_key *key,
}
static int
xkb_filter_mod_latch_new(struct xkb_state *state, struct xkb_key *key,
xkb_filter_mod_latch_new(struct xkb_state *state,
const struct xkb_key *key,
const union xkb_action *action)
{
enum xkb_key_latch_state latch = LATCH_KEY_DOWN;
@ -450,7 +460,8 @@ xkb_filter_mod_latch_new(struct xkb_state *state, struct xkb_key *key,
* apply a new filter from the key action.
*/
static void
xkb_filter_apply_all(struct xkb_state *state, struct xkb_key *key,
xkb_filter_apply_all(struct xkb_state *state,
const struct xkb_key *key,
enum xkb_key_direction direction)
{
struct xkb_filter *filter;
@ -601,11 +612,9 @@ XKB_EXPORT void
xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc,
enum xkb_key_direction direction)
{
struct xkb_key *key;
xkb_mod_index_t i;
xkb_mod_mask_t bit;
key = XkbKey(state->keymap, kc);
const struct xkb_key *key = XkbKey(state->keymap, kc);
if (!key)
return;

View File

@ -409,7 +409,7 @@ struct xkb_keymap {
char *compat_section_name;
};
static inline struct xkb_key *
static inline const struct xkb_key *
XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
if (kc < keymap->min_key_code || kc > keymap->max_key_code)
@ -418,7 +418,7 @@ XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
}
static inline xkb_keycode_t
XkbKeyGetKeycode(struct xkb_keymap *keymap, struct xkb_key *key)
XkbKeyGetKeycode(struct xkb_keymap *keymap, const struct xkb_key *key)
{
/* Hack to avoid having to keep the keycode inside the xkb_key. */
return (xkb_keycode_t)(key - keymap->keys.item);
@ -428,35 +428,35 @@ XkbKeyGetKeycode(struct xkb_keymap *keymap, struct xkb_key *key)
darray_foreach(iter, keymap->keys)
static inline struct xkb_key_type *
XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
XkbKeyType(struct xkb_keymap *keymap, const struct xkb_key *key,
xkb_group_index_t group)
{
return &keymap->types[key->kt_index[group]];
}
static inline xkb_level_index_t
XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
XkbKeyGroupWidth(struct xkb_keymap *keymap, const struct xkb_key *key,
xkb_group_index_t group)
{
return XkbKeyType(keymap, key, group)->num_levels;
}
static inline unsigned int
XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group,
XkbKeyNumSyms(const struct xkb_key *key, xkb_group_index_t group,
xkb_level_index_t level)
{
return key->num_syms[group * key->width + level];
}
static inline xkb_keysym_t *
XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group,
static inline const xkb_keysym_t *
XkbKeySymEntry(const struct xkb_key *key, xkb_group_index_t group,
xkb_level_index_t level)
{
return &key->syms[key->sym_index[group * key->width + level]];
}
static inline union xkb_action *
XkbKeyActionEntry(struct xkb_key *key, xkb_group_index_t group,
static inline const union xkb_action *
XkbKeyActionEntry(const struct xkb_key *key, xkb_group_index_t group,
xkb_level_index_t level)
{
return &key->actions[key->width * group + level];
@ -491,14 +491,15 @@ const char *
xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
xkb_group_index_t
xkb_key_get_group(struct xkb_state *state, struct xkb_key *key);
xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key);
xkb_level_index_t
xkb_key_get_level(struct xkb_state *state, struct xkb_key *key,
xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
xkb_group_index_t group);
extern int
xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
xkb_key_get_syms_by_level(struct xkb_keymap *keymap,
const struct xkb_key *key,
xkb_group_index_t group, xkb_level_index_t level,
const xkb_keysym_t **syms_out);

View File

@ -809,7 +809,7 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
darray_resize0(keymap->keys, keymap->max_key_code + 1);
for (kc = info->computedMin; kc <= info->computedMax; kc++)
LongToKeyName(darray_item(info->names, kc),
XkbKey(keymap, kc)->name);
darray_item(keymap->keys, kc).name);
keymap->keycodes_section_name = strdup_safe(info->name);

View File

@ -178,7 +178,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
return false;
}
*XkbKeyActionEntry(key, group, level) = interp->act;
key->actions[group * key->width + level] = interp->act;
}
}
}