Use xkb_mod_mask_t and xkb_mask_index_t throughout Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
diff --git a/src/text.c b/src/text.c
index a691ede..6f1d0e6 100644
--- a/src/text.c
+++ b/src/text.c
@@ -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)
diff --git a/src/text.h b/src/text.h
index 67d3f3a..43a212e 100644
--- a/src/text.h
+++ b/src/text.h
@@ -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);
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 14984e9..7bfa660 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -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
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 8c4c7f4..4b4ac95 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -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)
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 787ede2..ede08a6 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -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;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index fa9eaeb..0264b10 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -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;
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 803682d..70407f2 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -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 = "";
-
- 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 multiply defined; "
- "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;
- }
+ /* already defined */
+ if (!keymap->vmod_names[i])
+ continue;
+
+ if (strcmp(keymap->vmod_names[i],
+ xkb_atom_text(keymap->ctx, stmt->name)) != 0)
+ continue;
+
+
+ info->available |= bit;
+
+ 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) {
diff --git a/src/xkbcomp/vmod.h b/src/xkbcomp/vmod.h
index f08e037..30df71a 100644
--- a/src/xkbcomp/vmod.h
+++ b/src/xkbcomp/vmod.h
@@ -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;
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 01033f8..c92ba5a 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -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)