Use xkb_mod_mask_t and xkb_mask_index_t throughout

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-24 13:15:40 +03:00
parent 74be17627e
commit 6cb9820000
9 changed files with 137 additions and 107 deletions

View File

@ -48,7 +48,7 @@ tbGetBuffer(unsigned int size)
}
static const char *
XkbcVModIndexText(struct xkb_keymap *keymap, unsigned ndx)
XkbcVModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
{
int len;
char *rtrn;
@ -76,14 +76,17 @@ XkbcVModIndexText(struct xkb_keymap *keymap, unsigned ndx)
}
const char *
XkbcVModMaskText(struct xkb_keymap *keymap, unsigned modMask, unsigned mask)
XkbcVModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t modMask,
xkb_mod_mask_t mask)
{
int i, bit, len, rem;
xkb_mod_index_t i;
xkb_mod_mask_t bit;
int len, rem;
const char *mm = NULL;
char *rtrn, *str;
char buf[BUFFER_SIZE];
if ((modMask == 0) && (mask == 0))
if (modMask == 0 && mask == 0)
return "none";
if (modMask != 0)
@ -111,16 +114,16 @@ XkbcVModMaskText(struct xkb_keymap *keymap, unsigned modMask, unsigned mask)
else
str = NULL;
len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
((str && mm) ? 1 : 0);
len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
(str && mm ? 1 : 0);
if (len >= BUFFER_SIZE)
len = BUFFER_SIZE - 1;
rtrn = tbGetBuffer(len + 1);
rtrn[0] = '\0';
snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
(mm && str) ? "+" : "", (str) ? str : "");
snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
(mm && str ? "+" : ""), (str ? str : ""));
return rtrn;
}
@ -137,7 +140,7 @@ static const char *modNames[XkbNumModifiers] = {
};
const char *
XkbcModIndexText(unsigned ndx)
XkbcModIndexText(xkb_mod_index_t ndx)
{
char *buf;
@ -153,9 +156,10 @@ XkbcModIndexText(unsigned ndx)
}
const char *
XkbcModMaskText(unsigned mask, bool cFormat)
XkbcModMaskText(xkb_mod_mask_t mask, bool cFormat)
{
int i, rem, bit;
int i, rem;
xkb_mod_index_t bit;
char *str, *buf;
if ((mask & 0xff) == 0xff)

View File

@ -29,14 +29,15 @@
#include "xkb-priv.h"
extern const char *
XkbcVModMaskText(struct xkb_keymap *keymap, unsigned modMask, unsigned mask);
const char *
XkbcVModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t modMask,
xkb_mod_mask_t mask);
extern const char *
XkbcModIndexText(unsigned ndx);
const char *
XkbcModIndexText(xkb_mod_index_t ndx);
extern const char *
XkbcModMaskText(unsigned mask, bool cFormat);
const char *
XkbcModMaskText(xkb_mod_mask_t mask, bool cFormat);
extern const char *
XkbcFileTypeText(enum xkb_file_type type);

View File

@ -235,8 +235,8 @@ union xkb_action {
};
struct xkb_mods {
uint32_t mask; /* effective mods */
uint32_t vmods;
xkb_mod_mask_t mask; /* effective mods */
xkb_mod_mask_t vmods;
uint8_t real_mods;
};
@ -259,7 +259,7 @@ struct xkb_sym_interpret {
unsigned char flags;
unsigned char match;
uint8_t mods;
uint32_t virtual_mod;
xkb_mod_index_t virtual_mod;
union xkb_action act;
};
@ -304,7 +304,7 @@ struct xkb_key {
unsigned char explicit;
unsigned char modmap;
uint32_t vmodmap;
xkb_mod_mask_t vmodmap;
struct xkb_behavior behavior;
@ -351,7 +351,7 @@ struct xkb_keymap {
darray(struct xkb_sym_interpret) sym_interpret;
/* vmod -> mod mapping */
uint32_t vmods[XkbNumVirtualMods];
xkb_mod_index_t vmods[XkbNumVirtualMods];
const char *vmod_names[XkbNumVirtualMods];
struct xkb_mods groups[XkbNumKbdGroups];
@ -489,7 +489,7 @@ xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom);
const char *
xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
extern unsigned int
xkb_group_index_t
xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc);
extern unsigned int

View File

@ -240,7 +240,7 @@ CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
static bool
CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
unsigned *flags_inout, unsigned *mods_rtrn)
unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn)
{
ExprResult rtrn;
@ -255,9 +255,11 @@ CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
return true;
}
}
if (!ExprResolveVModMask(keymap, value, &rtrn))
return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
*mods_rtrn = rtrn.uval;
*mods_rtrn = (xkb_mod_mask_t) rtrn.ival;
*flags_inout &= ~XkbSA_UseModMapMods;
return true;
}
@ -268,7 +270,8 @@ HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
{
struct xkb_mod_action *act;
unsigned rtrn;
unsigned t1, t2;
unsigned t1;
xkb_mod_mask_t t2;
act = (struct xkb_mod_action *) action;
if (array_ndx != NULL) {
@ -307,7 +310,8 @@ HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
unsigned field, ExprDef *array_ndx, ExprDef *value)
{
struct xkb_mod_action *act;
unsigned t1, t2;
unsigned t1;
xkb_mod_mask_t t2;
act = (struct xkb_mod_action *) action;
if ((array_ndx != NULL) && (field == F_Modifiers))
@ -599,7 +603,8 @@ HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
{
ExprResult rtrn;
struct xkb_iso_action *act;
unsigned flags, mods;
unsigned flags;
xkb_mod_mask_t mods;
xkb_group_index_t group;
act = (struct xkb_iso_action *) action;
@ -825,7 +830,8 @@ HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
ExprResult rtrn;
struct xkb_key *key;
struct xkb_redirect_key_action *act;
unsigned t1, t2;
unsigned t1;
xkb_mod_mask_t t2;
unsigned long tmp;
if (array_ndx != NULL)

View File

@ -55,7 +55,7 @@ typedef struct _LEDInfo {
unsigned char flags;
unsigned char which_mods;
unsigned char real_mods;
unsigned short vmods;
xkb_mod_mask_t vmods;
unsigned char which_groups;
uint32_t groups;
unsigned int ctrls;
@ -1270,11 +1270,11 @@ err_info:
return false;
}
uint32_t
VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask)
xkb_mod_mask_t
VModsToReal(struct xkb_keymap *keymap, xkb_mod_mask_t vmodmask)
{
uint32_t ret = 0;
int i;
xkb_mod_mask_t ret = 0;
xkb_mod_index_t i;
if (!vmodmask)
return 0;
@ -1290,7 +1290,7 @@ VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask)
static void
UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
uint32_t rmodmask)
xkb_mod_mask_t rmodmask)
{
switch (act->type) {
case XkbSA_SetMods:
@ -1383,7 +1383,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
#define INTERP_SIZE (8 * 4)
struct xkb_sym_interpret *interps[INTERP_SIZE];
union xkb_action *acts;
uint32_t vmodmask = 0;
xkb_mod_mask_t vmodmask = 0;
int num_acts = 0;
xkb_group_index_t group;
int level;
@ -1460,8 +1460,11 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
bool
UpdateModifiersFromCompat(struct xkb_keymap *keymap)
{
struct xkb_key *key;
xkb_mod_index_t vmod;
xkb_group_index_t grp;
xkb_led_index_t led;
int i;
struct xkb_key *key;
struct xkb_key_type *type;
struct xkb_kt_map_entry *entry;
@ -1472,34 +1475,36 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
return false;
/* Update keymap->vmods, the virtual -> real mod mapping. */
for (i = 0; i < XkbNumVirtualMods; i++)
keymap->vmods[i] = 0;
for (vmod = 0; vmod < XkbNumVirtualMods; vmod++)
keymap->vmods[vmod] = 0;
xkb_foreach_key(key, keymap) {
if (!key->vmodmap)
continue;
for (i = 0; i < XkbNumVirtualMods; i++) {
if (!(key->vmodmap & (1 << i)))
for (vmod = 0; vmod < XkbNumVirtualMods; vmod++) {
if (!(key->vmodmap & (1 << vmod)))
continue;
keymap->vmods[i] |= key->modmap;
keymap->vmods[vmod] |= key->modmap;
}
}
/* Now update the level masks for all the types to reflect the vmods. */
darray_foreach(type, keymap->types) {
uint32_t mask = 0;
int j;
xkb_mod_mask_t mask = 0;
type->mods.mask = type->mods.real_mods;
type->mods.mask |= VModsToReal(keymap, type->mods.vmods);
for (j = 0; j < XkbNumVirtualMods; j++) {
if (!(type->mods.vmods & (1 << j)))
/* FIXME: We compute the mask with doing anything with it? */
for (vmod = 0; vmod < XkbNumVirtualMods; vmod++) {
if (!(type->mods.vmods & (1 << vmod)))
continue;
mask |= keymap->vmods[j];
mask |= keymap->vmods[vmod];
}
darray_foreach(entry, type->map)
entry->mods.mask = entry->mods.real_mods |
VModsToReal(keymap, entry->mods.vmods);
entry->mods.mask = entry->mods.real_mods |
VModsToReal(keymap, entry->mods.vmods);
}
/* Update action modifiers. */
@ -1513,15 +1518,15 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap)
}
/* Update group modifiers. */
for (i = 0; i < XkbNumKbdGroups; i++) {
struct xkb_mods *group = &keymap->groups[i];
for (grp = 0; grp < XkbNumKbdGroups; grp++) {
struct xkb_mods *group = &keymap->groups[grp];
group->mask = group->real_mods | VModsToReal(keymap, group->vmods);
}
/* Update vmod -> indicator maps. */
for (i = 0; i < XkbNumIndicators; i++) {
struct xkb_mods *led = &keymap->indicators[i].mods;
led->mask = led->real_mods | VModsToReal(keymap, led->vmods);
for (led = 0; led < XkbNumIndicators; led++) {
struct xkb_mods *mods = &keymap->indicators[led].mods;
mods->mask = mods->real_mods | VModsToReal(keymap, mods->vmods);
}
return true;

View File

@ -50,8 +50,8 @@ typedef struct _KeyTypeInfo {
struct list entry;
xkb_atom_t name;
unsigned mask;
unsigned vmask;
xkb_mod_mask_t mask;
xkb_mod_mask_t vmask;
unsigned numLevels;
darray(struct xkb_kt_map_entry) entries;
struct list preserves;

View File

@ -36,7 +36,8 @@ InitVModInfo(VModInfo *info, struct xkb_keymap *keymap)
void
ClearVModInfo(VModInfo *info, struct xkb_keymap *keymap)
{
int i, bit;
xkb_mod_index_t i;
xkb_mod_mask_t bit;
info->newlyDefined = info->defined = info->available = 0;
@ -60,55 +61,62 @@ ClearVModInfo(VModInfo *info, struct xkb_keymap *keymap)
*/
bool
HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
enum merge_mode mergeMode,
VModInfo *info)
enum merge_mode mergeMode, VModInfo *info)
{
int i, bit, nextFree;
xkb_mod_index_t i;
int nextFree;
xkb_mod_mask_t bit;
ExprResult mod;
for (i = 0, bit = 1, nextFree = -1; i < XkbNumVirtualMods; i++, bit <<=
1) {
nextFree = -1;
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
const char *str1;
const char *str2 = "";
if (!(info->defined & bit)) {
if (nextFree < 0)
nextFree = i;
continue;
}
if (keymap->vmod_names[i] &&
strcmp(keymap->vmod_names[i],
xkb_atom_text(keymap->ctx, stmt->name)) == 0) { /* already defined */
info->available |= bit;
if (stmt->value == NULL)
return true;
else {
const char *str1;
const char *str2 = "";
/* already defined */
if (!keymap->vmod_names[i])
continue;
if (!ExprResolveModMask(keymap->ctx, stmt->value,
&mod)) {
log_err(keymap->ctx, "Declaration of %s ignored\n",
xkb_atom_text(keymap->ctx, stmt->name));
return false;
}
if (strcmp(keymap->vmod_names[i],
xkb_atom_text(keymap->ctx, stmt->name)) != 0)
continue;
if (mod.uval == keymap->vmods[i])
return true;
str1 = XkbcModMaskText(keymap->vmods[i], true);
if (mergeMode == MERGE_OVERRIDE) {
str2 = str1;
str1 = XkbcModMaskText(mod.uval, true);
}
log_warn(keymap->ctx,
"Virtual modifier %s multiply defined; "
"Using %s, ignoring %s\n",
xkb_atom_text(keymap->ctx, stmt->name), str1, str2);
info->available |= bit;
if (mergeMode == MERGE_OVERRIDE)
keymap->vmods[i] = mod.uval;
return true;
}
if (!stmt->value)
return true;
if (!ExprResolveModMask(keymap->ctx, stmt->value, &mod)) {
log_err(keymap->ctx, "Declaration of %s ignored\n",
xkb_atom_text(keymap->ctx, stmt->name));
return false;
}
if (mod.uval == keymap->vmods[i])
return true;
str1 = XkbcModMaskText(keymap->vmods[i], true);
if (mergeMode == MERGE_OVERRIDE) {
str2 = str1;
str1 = XkbcModMaskText(mod.uval, true);
}
log_warn(keymap->ctx,
"Virtual modifier %s defined multiple times; "
"Using %s, ignoring %s\n",
xkb_atom_text(keymap->ctx, stmt->name), str1, str2);
if (mergeMode == MERGE_OVERRIDE)
keymap->vmods[i] = mod.uval;
return true;
}
if (nextFree < 0) {
@ -117,19 +125,24 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
XkbNumVirtualMods);
return false;
}
info->defined |= (1 << nextFree);
info->newlyDefined |= (1 << nextFree);
info->available |= (1 << nextFree);
keymap->vmod_names[nextFree] = xkb_atom_text(keymap->ctx, stmt->name);
if (stmt->value == NULL)
return true;
if (ExprResolveModMask(keymap->ctx, stmt->value, &mod)) {
keymap->vmods[nextFree] = mod.uval;
if (!stmt->value)
return true;
if (!ExprResolveModMask(keymap->ctx, stmt->value, &mod)) {
log_err(keymap->ctx, "Declaration of %s ignored\n",
xkb_atom_text(keymap->ctx, stmt->name));
return false;
}
log_err(keymap->ctx, "Declaration of %s ignored\n",
xkb_atom_text(keymap->ctx, stmt->name));
return false;
keymap->vmods[nextFree] = mod.uval;
return true;
}
/**
@ -147,7 +160,7 @@ static int
LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
unsigned type, ExprResult * val_rtrn)
{
int i;
xkb_mod_index_t i;
const char *name = xkb_atom_text(keymap->ctx, field);
if (type != TypeInt)
@ -211,8 +224,10 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
ExprResult *val_rtrn, VModInfo *info)
{
if (def->op == ExprIdent) {
int i, bit;
xkb_mod_index_t i;
xkb_mod_mask_t bit;
const char *name = xkb_atom_text(keymap->ctx, def->value.str);
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
if ((info->available & bit) && keymap->vmod_names[i] &&
strcmp(keymap->vmod_names[i], name) == 0) {

View File

@ -31,9 +31,9 @@
#include "expr.h"
typedef struct _VModInfo {
unsigned defined;
unsigned available;
unsigned newlyDefined;
xkb_mod_mask_t defined;
xkb_mod_mask_t available;
xkb_mod_mask_t newlyDefined;
int errorCount;
} VModInfo;

View File

@ -29,7 +29,6 @@
#include "xkbcomp.h"
#include "text.h"
#include "utils.h"
extern bool
ProcessIncludeFile(struct xkb_context *ctx, IncludeStmt *stmt,
@ -47,8 +46,8 @@ FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
extern bool
UpdateModifiersFromCompat(struct xkb_keymap *keymap);
uint32_t
VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask);
xkb_mod_mask_t
VModsToReal(struct xkb_keymap *keymap, xkb_mod_mask_t vmodmask);
static inline unsigned long
KeyNameToLong(const char *name)