Add and use xkb_level_index_t
Several types are used over the code for shift levels; better to use just one. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
b804aec292
commit
59d947c9c1
|
@ -657,7 +657,8 @@ write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
|
|||
struct xkb_key *key, xkb_group_index_t group)
|
||||
{
|
||||
const xkb_keysym_t *syms;
|
||||
int num_syms, level;
|
||||
int num_syms;
|
||||
xkb_level_index_t level;
|
||||
#define OUT_BUF_LEN 128
|
||||
char out_buf[OUT_BUF_LEN];
|
||||
|
||||
|
|
|
@ -213,14 +213,14 @@ xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name)
|
|||
/**
|
||||
* Returns the level to use for the given key and state, or -1 if invalid.
|
||||
*/
|
||||
unsigned int
|
||||
xkb_level_index_t
|
||||
xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
|
||||
xkb_group_index_t group)
|
||||
{
|
||||
struct xkb_keymap *keymap = xkb_state_get_map(state);
|
||||
struct xkb_key_type *type;
|
||||
struct xkb_kt_map_entry *entry;
|
||||
unsigned int active_mods;
|
||||
xkb_mod_mask_t active_mods;
|
||||
|
||||
if (!XkbKeycodeInRange(keymap, kc))
|
||||
return 0;
|
||||
|
@ -281,7 +281,7 @@ xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc)
|
|||
*/
|
||||
int
|
||||
xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
xkb_group_index_t group, unsigned int level,
|
||||
xkb_group_index_t group, xkb_level_index_t level,
|
||||
const xkb_keysym_t **syms_out)
|
||||
{
|
||||
int num_syms;
|
||||
|
@ -314,7 +314,7 @@ xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
|
|||
struct xkb_keymap *keymap = xkb_state_get_map(state);
|
||||
struct xkb_key *key;
|
||||
xkb_group_index_t group;
|
||||
unsigned int level;
|
||||
xkb_level_index_t level;
|
||||
|
||||
if (!state || !XkbKeycodeInRange(keymap, kc))
|
||||
return -1;
|
||||
|
|
|
@ -110,7 +110,7 @@ static union xkb_action *
|
|||
xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
|
||||
{
|
||||
xkb_group_index_t group;
|
||||
unsigned int level;
|
||||
xkb_level_index_t level;
|
||||
struct xkb_key *key = NULL;
|
||||
|
||||
if (XkbKeycodeInRange(state->keymap, kc))
|
||||
|
|
|
@ -91,6 +91,8 @@
|
|||
#include "darray.h"
|
||||
#include "list.h"
|
||||
|
||||
typedef uint16_t xkb_level_index_t;
|
||||
|
||||
enum xkb_file_type {
|
||||
/* The top level file which includes the other component files. */
|
||||
FILE_TYPE_KEYMAP = (1 << 0),
|
||||
|
@ -241,13 +243,13 @@ struct xkb_mods {
|
|||
};
|
||||
|
||||
struct xkb_kt_map_entry {
|
||||
uint16_t level;
|
||||
xkb_level_index_t level;
|
||||
struct xkb_mods mods;
|
||||
};
|
||||
|
||||
struct xkb_key_type {
|
||||
struct xkb_mods mods;
|
||||
uint16_t num_levels;
|
||||
xkb_level_index_t num_levels;
|
||||
darray(struct xkb_kt_map_entry) map;
|
||||
struct xkb_mods *preserve;
|
||||
const char *name;
|
||||
|
@ -317,7 +319,7 @@ struct xkb_key {
|
|||
|
||||
xkb_group_index_t num_groups;
|
||||
/* How many levels the largest group has. */
|
||||
unsigned char width;
|
||||
xkb_level_index_t width;
|
||||
|
||||
uint8_t out_of_range_group_action;
|
||||
xkb_group_index_t out_of_range_group_number;
|
||||
|
@ -400,7 +402,7 @@ XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
|
|||
return &darray_item(keymap->types, XkbKeyTypeIndex(key, group));
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
static inline xkb_level_index_t
|
||||
XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
xkb_group_index_t group)
|
||||
{
|
||||
|
@ -408,7 +410,8 @@ XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
|
|||
}
|
||||
|
||||
static inline unsigned int
|
||||
XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group, unsigned int level)
|
||||
XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group,
|
||||
xkb_level_index_t level)
|
||||
{
|
||||
return key->num_syms[group * key->width + level];
|
||||
}
|
||||
|
@ -421,13 +424,14 @@ XkbKeySym(struct xkb_key *key, int ndx)
|
|||
|
||||
static inline int
|
||||
XkbKeySymOffset(struct xkb_key *key, xkb_group_index_t group,
|
||||
unsigned int level)
|
||||
xkb_level_index_t level)
|
||||
{
|
||||
return key->sym_index[group * key->width + level];
|
||||
}
|
||||
|
||||
static inline xkb_keysym_t *
|
||||
XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group, unsigned int level)
|
||||
XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group,
|
||||
xkb_level_index_t level)
|
||||
{
|
||||
return XkbKeySym(key, XkbKeySymOffset(key, group, level));
|
||||
}
|
||||
|
@ -454,7 +458,7 @@ XkbKeyActionsPtr(struct xkb_keymap *keymap, struct xkb_key *key)
|
|||
|
||||
static inline union xkb_action *
|
||||
XkbKeyActionEntry(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
xkb_group_index_t group, unsigned int level)
|
||||
xkb_group_index_t group, xkb_level_index_t level)
|
||||
{
|
||||
if (XkbKeyHasActions(key))
|
||||
return &XkbKeyActionsPtr(keymap, key)[key->width * group + level];
|
||||
|
@ -492,13 +496,13 @@ xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
|
|||
xkb_group_index_t
|
||||
xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc);
|
||||
|
||||
extern unsigned int
|
||||
xkb_level_index_t
|
||||
xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
|
||||
xkb_group_index_t group);
|
||||
|
||||
extern int
|
||||
xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
xkb_group_index_t group, unsigned int level,
|
||||
xkb_group_index_t group, xkb_level_index_t level,
|
||||
const xkb_keysym_t **syms_out);
|
||||
|
||||
/**
|
||||
|
|
|
@ -1334,7 +1334,7 @@ UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
|
|||
*/
|
||||
static struct xkb_sym_interpret *
|
||||
FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
|
||||
xkb_group_index_t group, uint32_t level)
|
||||
xkb_group_index_t group, xkb_level_index_t level)
|
||||
{
|
||||
struct xkb_sym_interpret *ret = NULL;
|
||||
struct xkb_sym_interpret *interp;
|
||||
|
@ -1399,8 +1399,8 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
|
|||
xkb_mod_mask_t vmodmask = 0;
|
||||
int num_acts = 0;
|
||||
xkb_group_index_t group;
|
||||
int level;
|
||||
int i;
|
||||
xkb_level_index_t level;
|
||||
unsigned int i;
|
||||
|
||||
/* If we've been told not to bind interps to this key, then don't. */
|
||||
if (key->explicit & XkbExplicitInterpretMask)
|
||||
|
|
|
@ -509,7 +509,7 @@ ExprResolveGroup(struct xkb_context *ctx, const ExprDef *expr,
|
|||
|
||||
bool
|
||||
ExprResolveLevel(struct xkb_context *ctx, const ExprDef *expr,
|
||||
unsigned int *level_rtrn)
|
||||
xkb_level_index_t *level_rtrn)
|
||||
{
|
||||
bool ok;
|
||||
int result;
|
||||
|
|
|
@ -76,7 +76,7 @@ ExprResolveInteger(struct xkb_context *ctx, const ExprDef *expr,
|
|||
|
||||
bool
|
||||
ExprResolveLevel(struct xkb_context *ctx, const ExprDef *expr,
|
||||
unsigned int *level_rtrn);
|
||||
xkb_level_index_t *level_rtrn);
|
||||
|
||||
bool
|
||||
ExprResolveGroup(struct xkb_context *ctx, const ExprDef *expr,
|
||||
|
|
|
@ -53,7 +53,7 @@ typedef struct _KeyTypeInfo {
|
|||
xkb_atom_t name;
|
||||
xkb_mod_mask_t mask;
|
||||
xkb_mod_mask_t vmask;
|
||||
unsigned numLevels;
|
||||
xkb_level_index_t numLevels;
|
||||
darray(struct xkb_kt_map_entry) entries;
|
||||
struct list preserves;
|
||||
darray(xkb_atom_t) lvlNames;
|
||||
|
@ -491,7 +491,7 @@ AddMapEntry(KeyTypesInfo *info, KeyTypeInfo *type,
|
|||
if ((old = FindMatchingMapEntry(type, new->mods.real_mods,
|
||||
new->mods.vmods))) {
|
||||
if (report && (old->level != new->level)) {
|
||||
unsigned use, ignore;
|
||||
xkb_level_index_t use, ignore;
|
||||
if (clobber) {
|
||||
use = new->level + 1;
|
||||
ignore = old->level + 1;
|
||||
|
@ -634,7 +634,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
|
|||
|
||||
static bool
|
||||
AddLevelName(KeyTypesInfo *info, KeyTypeInfo *type,
|
||||
unsigned level, xkb_atom_t name, bool clobber)
|
||||
xkb_level_index_t level, xkb_atom_t name, bool clobber)
|
||||
{
|
||||
if (level >= darray_size(type->lvlNames))
|
||||
darray_resize0(type->lvlNames, level + 1);
|
||||
|
@ -670,7 +670,7 @@ static bool
|
|||
SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
|
||||
ExprDef *value)
|
||||
{
|
||||
unsigned level;
|
||||
xkb_level_index_t level;
|
||||
xkb_atom_t level_name;
|
||||
struct xkb_context *ctx = info->keymap->ctx;
|
||||
const char *str;
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
*
|
||||
********************************************************/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "xkbcomp-priv.h"
|
||||
#include "parseutils.h"
|
||||
#include "action.h"
|
||||
|
@ -72,7 +70,7 @@ typedef struct _KeyInfo {
|
|||
unsigned char typesDefined;
|
||||
unsigned char symsDefined;
|
||||
unsigned char actsDefined;
|
||||
unsigned int numLevels[XkbNumKbdGroups];
|
||||
xkb_level_index_t numLevels[XkbNumKbdGroups];
|
||||
|
||||
/* syms[group] -> Single array for all the keysyms in the group. */
|
||||
darray_xkb_keysym_t syms[XkbNumKbdGroups];
|
||||
|
@ -249,10 +247,11 @@ FreeSymbolsInfo(SymbolsInfo * info)
|
|||
}
|
||||
|
||||
static bool
|
||||
ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group, unsigned int numLevels,
|
||||
unsigned sizeSyms, bool forceActions)
|
||||
ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group,
|
||||
xkb_level_index_t numLevels, unsigned sizeSyms,
|
||||
bool forceActions)
|
||||
{
|
||||
int i;
|
||||
xkb_level_index_t i;
|
||||
|
||||
if (darray_size(keyi->syms[group]) < sizeSyms)
|
||||
darray_resize0(keyi->syms[group], sizeSyms);
|
||||
|
@ -292,10 +291,10 @@ MergeKeyGroups(SymbolsInfo * info,
|
|||
darray_xkb_keysym_t resultSyms;
|
||||
enum key_group_selector using = NONE;
|
||||
darray_xkb_action resultActs;
|
||||
unsigned int resultWidth;
|
||||
xkb_level_index_t resultWidth;
|
||||
unsigned int resultSize = 0;
|
||||
int cur_idx = 0;
|
||||
int i;
|
||||
xkb_level_index_t i;
|
||||
bool report, clobber;
|
||||
int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
|
||||
|
||||
|
@ -852,8 +851,9 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
|
|||
ExprDef *value)
|
||||
{
|
||||
xkb_group_index_t ndx;
|
||||
size_t nSyms, nLevels;
|
||||
size_t i;
|
||||
size_t nSyms;
|
||||
xkb_level_index_t nLevels;
|
||||
xkb_level_index_t i;
|
||||
int j;
|
||||
|
||||
if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
|
||||
|
@ -1471,8 +1471,8 @@ static struct xkb_key *
|
|||
FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
|
||||
{
|
||||
struct xkb_key *key, *ret = NULL;
|
||||
xkb_group_index_t group, min_group = UINT_MAX;
|
||||
unsigned int level, min_level = UINT_MAX;
|
||||
xkb_group_index_t group, min_group = UINT32_MAX;
|
||||
xkb_level_index_t level, min_level = UINT16_MAX;
|
||||
|
||||
xkb_foreach_key(key, keymap) {
|
||||
for (group = 0; group < key->num_groups; group++) {
|
||||
|
@ -1553,7 +1553,7 @@ FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
|
|||
* symbol per level.
|
||||
*/
|
||||
static bool
|
||||
FindAutomaticType(struct xkb_keymap *keymap, int width,
|
||||
FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
|
||||
const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
|
||||
bool *autoType)
|
||||
{
|
||||
|
@ -1605,7 +1605,8 @@ static void
|
|||
PrepareKeyDef(KeyInfo *keyi)
|
||||
{
|
||||
xkb_group_index_t i, lastGroup;
|
||||
int j, width, defined;
|
||||
unsigned int defined;
|
||||
xkb_level_index_t j, width;
|
||||
bool identical;
|
||||
|
||||
defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
|
||||
|
@ -1722,7 +1723,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
|
|||
struct xkb_key *key;
|
||||
size_t sizeSyms = 0;
|
||||
xkb_group_index_t i, nGroups;
|
||||
unsigned width, tmp;
|
||||
xkb_level_index_t width, tmp;
|
||||
struct xkb_key_type * type;
|
||||
bool haveActions, autoType, useAlias;
|
||||
unsigned types[XkbNumKbdGroups];
|
||||
|
|
Loading…
Reference in New Issue