Introduce xkb_keycode_t for keycodes And use it consistently everywhere, including with a special long-safe internal keycode type, to ease the transition to large keycodes. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
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 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h
index b353759..e88bdd9 100644
--- a/include/xkbcommon/xkbcommon.h
+++ b/include/xkbcommon/xkbcommon.h
@@ -60,9 +60,16 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <X11/Xfuncproto.h>
#include <X11/extensions/XKB.h>
-#ifndef X_PROTOCOL
-typedef unsigned char KeyCode;
-#endif
+typedef uint8_t xkb_keycode_t;
+
+#define XKB_KEYCODE_MAX 255
+#define xkb_keycode_is_legal_ext(kc) (kc <= XKB_KEYCODE_MAX)
+#define xkb_keycode_is_legal_x11(kc) (kc <= XKB_KEYCODE_MAX)
+#define xkb_keymap_keycode_range_is_legal(xkb) \
+ (xkb->max_key_code > 0 && \
+ xkb->max_key_code > xkb->min_key_code && \
+ xkb_keycode_is_legal_ext(xkb->min_key_code) && \
+ xkb_keycode_is_legal_ext(xkb->max_key_code))
/* Duplicate the modifier mask defines so libxkcommon can be used
* without X.h */
@@ -153,7 +160,7 @@ struct xkb_switch_screen_action {
struct xkb_redirect_key_action {
uint8_t type;
- uint8_t new_key;
+ xkb_keycode_t new_key;
uint8_t mods_mask;
uint8_t mods;
uint16_t vmods_mask;
@@ -254,8 +261,8 @@ struct xkb_client_map {
unsigned char num_types;
struct xkb_key_type * types;
- unsigned short size_syms;
- unsigned short num_syms;
+ uint32_t size_syms;
+ uint32_t num_syms;
uint32_t *syms;
struct xkb_sym_map * key_sym_map;
@@ -335,8 +342,8 @@ struct xkb_names {
uint32_t *radio_groups;
uint32_t phys_symbols;
- unsigned char num_keys;
- unsigned char num_key_aliases;
+ xkb_keycode_t num_keys;
+ xkb_keycode_t num_key_aliases;
unsigned short num_rg;
};
@@ -599,7 +606,7 @@ struct xkb_controls {
unsigned short axt_opts_values;
unsigned int axt_ctrls_mask;
unsigned int axt_ctrls_values;
- unsigned char per_key_repeat[XkbPerKeyBitArraySize];
+ unsigned char *per_key_repeat;
};
/* Common keyboard description structure */
@@ -607,8 +614,8 @@ struct xkb_desc {
unsigned int defined;
unsigned short flags;
unsigned short device_spec;
- KeyCode min_key_code;
- KeyCode max_key_code;
+ xkb_keycode_t min_key_code;
+ xkb_keycode_t max_key_code;
struct xkb_controls * ctrls;
struct xkb_server_map * server;
@@ -645,23 +652,22 @@ struct xkb_desc {
struct xkb_map_changes {
unsigned short changed;
- KeyCode min_key_code;
- KeyCode max_key_code;
+ xkb_keycode_t min_key_code;
+ xkb_keycode_t max_key_code;
unsigned char first_type;
unsigned char num_types;
- KeyCode first_key_sym;
- unsigned char num_key_syms;
- KeyCode first_key_act;
- unsigned char num_key_acts;
- KeyCode first_key_behavior;
- unsigned char num_key_behaviors;
- KeyCode first_key_explicit;
- unsigned char num_key_explicit;
- KeyCode first_modmap_key;
- unsigned char num_modmap_keys;
- KeyCode first_vmodmap_key;
- unsigned char num_vmodmap_keys;
- unsigned char pad;
+ xkb_keycode_t first_key_sym;
+ xkb_keycode_t num_key_syms;
+ xkb_keycode_t first_key_act;
+ xkb_keycode_t num_key_acts;
+ xkb_keycode_t first_key_behavior;
+ xkb_keycode_t num_key_behaviors;
+ xkb_keycode_t first_key_explicit;
+ xkb_keycode_t num_key_explicit;
+ xkb_keycode_t first_modmap_key;
+ xkb_keycode_t num_modmap_keys;
+ xkb_keycode_t first_vmodmap_key;
+ xkb_keycode_t num_vmodmap_keys;
unsigned short vmods;
};
@@ -682,10 +688,10 @@ struct xkb_name_changes {
unsigned char num_types;
unsigned char first_lvl;
unsigned char num_lvls;
- unsigned char num_aliases;
+ xkb_keycode_t num_aliases;
unsigned char num_rg;
- unsigned char first_key;
- unsigned char num_keys;
+ xkb_keycode_t first_key;
+ xkb_keycode_t num_keys;
unsigned short changed_vmods;
unsigned long changed_indicators;
unsigned char changed_groups;
diff --git a/src/alloc.c b/src/alloc.c
index c6ac8a8..3d1c7b2 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -144,10 +144,8 @@ XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalRG, int nTotalAl
}
if ((which & XkbKeyNamesMask) && !names->keys) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))
- return BadValue;
+ if (!xkb_keymap_keycode_range_is_legal(xkb))
+ return BadMatch;
names->keys = _XkbTypedCalloc(xkb->max_key_code + 1, struct xkb_key_name);
if (!names->keys)
@@ -267,6 +265,13 @@ XkbcAllocControls(struct xkb_desc * xkb, unsigned which)
return BadAlloc;
}
+ if (!xkb->ctrls->per_key_repeat) {
+ xkb->ctrls->per_key_repeat = _XkbTypedCalloc(xkb->max_key_code << 3,
+ unsigned char);
+ if (!xkb->ctrls->per_key_repeat)
+ return BadAlloc;
+ }
+
return Success;
}
diff --git a/src/malloc.c b/src/malloc.c
index 9c985c3..b6144f1 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -37,10 +37,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
if (!xkb || ((nTotalTypes > 0) && (nTotalTypes < XkbNumRequiredTypes)))
return BadValue;
- if ((which & XkbKeySymsMask) &&
- ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))) {
+ if ((which & XkbKeySymsMask) && !xkb_keymap_keycode_range_is_legal(xkb)) {
#ifdef DEBUG
fprintf(stderr, "bad keycode (%d,%d) in XkbAllocClientMap\n",
xkb->min_key_code, xkb->max_key_code);
@@ -106,9 +103,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
}
if (which & XkbModifierMapMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))
+ if (!xkb_keymap_keycode_range_is_legal(xkb))
return BadMatch;
if (!map->modmap) {
@@ -144,12 +139,13 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
else
map = xkb->server;
- if (which & XkbExplicitComponentsMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))
- return BadMatch;
+ if (!which)
+ return Success;
+
+ if (!xkb_keymap_keycode_range_is_legal(xkb))
+ return BadMatch;
+ if (which & XkbExplicitComponentsMask) {
if (!map->explicit) {
i = xkb->max_key_code + 1;
map->explicit = _XkbTypedCalloc(i, unsigned char);
@@ -159,11 +155,6 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
}
if (which&XkbKeyActionsMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))
- return BadMatch;
-
if (nNewActions < 1)
nNewActions = 1;
@@ -200,11 +191,6 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
}
if (which & XkbKeyBehaviorsMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))
- return BadMatch;
-
if (!map->behaviors) {
i = xkb->max_key_code + 1;
map->behaviors = _XkbTypedCalloc(i, struct xkb_behavior);
@@ -214,11 +200,6 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
}
if (which & XkbVirtualModMapMask) {
- if ((!XkbIsLegalKeycode(xkb->min_key_code)) ||
- (!XkbIsLegalKeycode(xkb->max_key_code)) ||
- (xkb->max_key_code < xkb->min_key_code))
- return BadMatch;
-
if (!map->vmodmap) {
i = xkb->max_key_code + 1;
map->vmodmap = _XkbTypedCalloc(i, uint32_t);
@@ -279,10 +260,11 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into)
}
uint32_t *
-XkbcResizeKeySyms(struct xkb_desc * xkb, int key, int needed)
+XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key,
+ unsigned int needed)
{
- int i, nSyms, nKeySyms;
- unsigned nOldSyms;
+ uint32_t i, nSyms, nKeySyms;
+ uint32_t nOldSyms;
uint32_t *newSyms;
if (needed == 0) {
@@ -291,10 +273,10 @@ XkbcResizeKeySyms(struct xkb_desc * xkb, int key, int needed)
}
nOldSyms = XkbKeyNumSyms(xkb, key);
- if (nOldSyms >= (unsigned)needed)
+ if (nOldSyms >= needed)
return XkbKeySymsPtr(xkb, key);
- if (xkb->map->size_syms - xkb->map->num_syms >= (unsigned)needed) {
+ if (xkb->map->size_syms - xkb->map->num_syms >= needed) {
if (nOldSyms > 0)
memcpy(&xkb->map->syms[xkb->map->num_syms],
XkbKeySymsPtr(xkb, key), nOldSyms * sizeof(uint32_t));
@@ -343,9 +325,9 @@ XkbcResizeKeySyms(struct xkb_desc * xkb, int key, int needed)
}
union xkb_action *
-XkbcResizeKeyActions(struct xkb_desc * xkb, int key, int needed)
+XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed)
{
- int i, nActs;
+ xkb_keycode_t i, nActs;
union xkb_action *newActs;
if (needed == 0) {
@@ -372,7 +354,7 @@ XkbcResizeKeyActions(struct xkb_desc * xkb, int key, int needed)
nActs = 1;
for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
- int nKeyActs, nCopy;
+ xkb_keycode_t nKeyActs, nCopy;
if ((xkb->server->key_acts[i] == 0) && (i != key))
continue;
diff --git a/src/xkballoc.h b/src/xkballoc.h
index 784b0ec..87762cb 100644
--- a/src/xkballoc.h
+++ b/src/xkballoc.h
@@ -62,10 +62,10 @@ extern int
XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type *into);
extern uint32_t *
-XkbcResizeKeySyms(struct xkb_desc * xkb, int key, int needed);
+XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed);
extern union xkb_action *
-XkbcResizeKeyActions(struct xkb_desc * xkb, int key, int needed);
+XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed);
extern void
XkbcFreeClientMap(struct xkb_desc * xkb, unsigned what, Bool freeMap);
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 0466dbe..0dbad1b 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -1038,6 +1038,7 @@ HandleRedirectKey(struct xkb_desc * xkb,
ExprResult rtrn;
struct xkb_redirect_key_action *act;
unsigned t1, t2;
+ xkb_keycode_t kc;
unsigned long tmp;
if (array_ndx != NULL)
@@ -1050,12 +1051,12 @@ HandleRedirectKey(struct xkb_desc * xkb,
if (!ExprResolveKeyName(value, &rtrn, NULL, NULL))
return ReportMismatch(action->type, field, "key name");
tmp = KeyNameToLong(rtrn.keyName.name);
- if (!FindNamedKey(xkb, tmp, &t1, True, CreateKeyNames(xkb), 0))
+ if (!FindNamedKey(xkb, tmp, &kc, True, CreateKeyNames(xkb), 0))
{
return ReportNotFound(action->type, field, "Key",
XkbcKeyNameText(rtrn.keyName.name));
}
- act->new_key = t1;
+ act->new_key = kc;
return True;
case F_ModsToClear:
case F_Modifiers:
diff --git a/src/xkbcomp/alias.c b/src/xkbcomp/alias.c
index e7f2fc1..79c1263 100644
--- a/src/xkbcomp/alias.c
+++ b/src/xkbcomp/alias.c
@@ -179,7 +179,7 @@ ApplyAliases(struct xkb_desc * xkb, Bool toGeom, AliasInfo ** info_in)
info = (AliasInfo *) info->def.next)
{
unsigned long lname;
- unsigned int kc;
+ xkb_keycode_t kc;
lname = KeyNameToLong(info->real);
if (!FindNamedKey(xkb, lname, &kc, False, CreateKeyNames(xkb), 0))
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 0900352..1d14341 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -486,6 +486,69 @@ ExprResolveFloat(ExprDef * expr,
}
int
+ExprResolveKeyCode(ExprDef * expr,
+ ExprResult * val_rtrn)
+{
+ ExprResult leftRtrn, rightRtrn;
+ ExprDef *left, *right;
+
+ switch (expr->op)
+ {
+ case ExprValue:
+ if (expr->type != TypeInt)
+ {
+ ERROR
+ ("Found constant of type %s where an int was expected\n",
+ exprTypeText(expr->type));
+ return False;
+ }
+ val_rtrn->uval = expr->value.uval;
+ return True;
+ case OpAdd:
+ case OpSubtract:
+ case OpMultiply:
+ case OpDivide:
+ left = expr->value.binary.left;
+ right = expr->value.binary.right;
+ if (ExprResolveKeyCode(left, &leftRtrn) &&
+ ExprResolveKeyCode(right, &rightRtrn))
+ {
+ switch (expr->op)
+ {
+ case OpAdd:
+ val_rtrn->uval = leftRtrn.uval + rightRtrn.uval;
+ break;
+ case OpSubtract:
+ val_rtrn->uval = leftRtrn.uval - rightRtrn.uval;
+ break;
+ case OpMultiply:
+ val_rtrn->uval = leftRtrn.uval * rightRtrn.uval;
+ break;
+ case OpDivide:
+ val_rtrn->uval = leftRtrn.uval / rightRtrn.uval;
+ break;
+ }
+ return True;
+ }
+ return False;
+ case OpNegate:
+ left = expr->value.child;
+ if (ExprResolveKeyCode(left, &leftRtrn))
+ {
+ val_rtrn->uval = ~leftRtrn.uval;
+ return True;
+ }
+ return False;
+ case OpUnaryPlus:
+ left = expr->value.child;
+ return ExprResolveKeyCode(left, val_rtrn);
+ default:
+ WSGO("Unknown operator %d in ResolveInteger\n", expr->op);
+ break;
+ }
+ return False;
+}
+int
ExprResolveInteger(ExprDef * expr,
ExprResult * val_rtrn,
IdentLookupFunc lookup, char * lookupPriv)
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index c93ac08..22509a7 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -105,6 +105,10 @@ extern int ExprResolveBoolean(ExprDef * /* expr */ ,
char * /* lookupPriv */
);
+extern int ExprResolveKeyCode(ExprDef * /* expr */ ,
+ ExprResult * /* val_rtrn */
+ );
+
extern int ExprResolveInteger(ExprDef * /* expr */ ,
ExprResult * /* val_rtrn */ ,
IdentLookupFunc /* lookup */ ,
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 9892024..be1e3b6 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -70,15 +70,14 @@ typedef struct _KeyNamesInfo
int errorCount;
unsigned fileID;
unsigned merge;
- int computedMin; /* lowest keycode stored */
- int computedMax; /* highest keycode stored */
- int explicitMin;
- int explicitMax;
- int effectiveMin;
- int effectiveMax;
- unsigned long names[XkbMaxLegalKeyCode + 1]; /* 4-letter name of key, keycode is the index */
- unsigned files[XkbMaxLegalKeyCode + 1];
- unsigned char has_alt_forms[XkbMaxLegalKeyCode + 1];
+ xkb_keycode_t computedMin; /* lowest keycode stored */
+ xkb_keycode_t computedMax; /* highest keycode stored */
+ xkb_keycode_t explicitMin;
+ xkb_keycode_t explicitMax;
+ xkb_keycode_t arraySize;
+ unsigned long *names;
+ unsigned *files;
+ unsigned char *has_alt_forms;
IndicatorNameInfo *leds;
AliasInfo *aliases;
} KeyNamesInfo;
@@ -88,6 +87,53 @@ static void HandleKeycodesFile(XkbFile * file,
unsigned merge,
KeyNamesInfo * info);
+static int
+ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
+{
+ void *tmp;
+ int i;
+
+ tmp = _XkbTypedRealloc(info->names, newMax + 1, unsigned long);
+ if (!tmp) {
+ ERROR
+ ("Couldn't reallocate for larger maximum keycode (%d)\n",
+ newMax);
+ ACTION("Maximum key value not changed\n");
+ return 0;
+ }
+ info->names = tmp;
+ for (i = info->arraySize + 1; i <= newMax; i++)
+ info->names[i] = 0;
+
+ tmp = _XkbTypedRealloc(info->files, newMax + 1, unsigned);
+ if (!tmp) {
+ ERROR
+ ("Couldn't reallocate for larger maximum keycode (%d)\n",
+ newMax);
+ ACTION("Maximum key value not changed\n");
+ return 0;
+ }
+ info->files = tmp;
+ for (i = info->arraySize + 1; i <= newMax; i++)
+ info->files[i] = 0;
+
+ tmp = _XkbTypedRealloc(info->has_alt_forms, newMax + 1, unsigned char);
+ if (!tmp) {
+ ERROR
+ ("Couldn't reallocate for larger maximum keycode (%d)\n",
+ newMax);
+ ACTION("Maximum key value not changed\n");
+ return 0;
+ }
+ info->has_alt_forms = tmp;
+ for (i = info->arraySize + 1; i <= newMax; i++)
+ info->has_alt_forms[i] = 0;
+
+ info->arraySize = newMax;
+
+ return 1;
+}
+
static void
InitIndicatorNameInfo(IndicatorNameInfo * ii, KeyNamesInfo * info)
{
@@ -278,13 +324,15 @@ ClearKeyNamesInfo(KeyNamesInfo * info)
if (info->name != NULL)
free(info->name);
info->name = NULL;
- info->computedMax = info->explicitMax = info->explicitMin = -1;
- info->computedMin = 256;
- info->effectiveMin = 8;
- info->effectiveMax = 255;
- bzero((char *) info->names, sizeof(info->names));
- bzero((char *) info->files, sizeof(info->files));
- bzero((char *) info->has_alt_forms, sizeof(info->has_alt_forms));
+ info->computedMax = info->explicitMax = info->explicitMin = 0;
+ info->computedMin = XKB_KEYCODE_MAX;
+ info->arraySize = 0;
+ free(info->names);
+ info->names = NULL;
+ free(info->files);
+ info->files = NULL;
+ free(info->has_alt_forms);
+ info->has_alt_forms = NULL;
if (info->leds)
ClearIndicatorNameInfo(info->leds, info);
if (info->aliases)
@@ -298,6 +346,9 @@ InitKeyNamesInfo(KeyNamesInfo * info)
info->name = NULL;
info->leds = NULL;
info->aliases = NULL;
+ info->names = NULL;
+ info->files = NULL;
+ info->has_alt_forms = NULL;
ClearKeyNamesInfo(info);
info->errorCount = 0;
return;
@@ -308,7 +359,7 @@ FindKeyByLong(KeyNamesInfo * info, unsigned long name)
{
register int i;
- for (i = info->effectiveMin; i <= info->effectiveMax; i++)
+ for (i = info->computedMin; i <= info->computedMax; i++)
{
if (info->names[i] == name)
return i;
@@ -323,17 +374,15 @@ FindKeyByLong(KeyNamesInfo * info, unsigned long name)
*/
static Bool
AddKeyName(KeyNamesInfo * info,
- int kc,
+ xkb_keycode_t kc,
char *name, unsigned merge, unsigned fileID, Bool reportCollisions)
{
int old;
unsigned long lval;
- if ((kc < info->effectiveMin) || (kc > info->effectiveMax))
- {
- ERROR("Illegal keycode %d for name <%s>\n", kc, name);
- ACTION("Must be in the range %d-%d inclusive\n",
- info->effectiveMin, info->effectiveMax);
+ if (kc > info->arraySize && !ResizeKeyNameArrays(info, kc)) {
+ ERROR("Couldn't resize KeyNames arrays for keycode %d\n", kc);
+ ACTION("Ignoring key %d\n", kc);
return False;
}
if (kc < info->computedMin)
@@ -444,6 +493,14 @@ MergeIncludedKeycodes(KeyNamesInfo * into, KeyNamesInfo * from,
into->name = from->name;
from->name = NULL;
}
+ if (from->computedMax > into->arraySize &&
+ !ResizeKeyNameArrays(into, from->computedMax)) {
+ ERROR("Couldn't resize KeyNames arrays for key %d\n",
+ from->computedMax);
+ ACTION("Ignoring include file %s\n", from->name);
+ into->errorCount += 10;
+ return;
+ }
for (i = from->computedMin; i <= from->computedMax; i++)
{
unsigned thisMerge;
@@ -472,17 +529,17 @@ MergeIncludedKeycodes(KeyNamesInfo * into, KeyNamesInfo * from,
}
if (!MergeAliases(&into->aliases, &from->aliases, merge))
into->errorCount++;
- if (from->explicitMin > 0)
+ if (from->explicitMin != 0)
{
if ((into->explicitMin < 0)
|| (into->explicitMin > from->explicitMin))
- into->effectiveMin = into->explicitMin = from->explicitMin;
+ into->explicitMin = from->explicitMin;
}
if (from->explicitMax > 0)
{
if ((into->explicitMax < 0)
|| (into->explicitMax < from->explicitMax))
- into->effectiveMax = into->explicitMax = from->explicitMax;
+ into->explicitMax = from->explicitMax;
}
return;
}
@@ -512,8 +569,8 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo *
else if (strcmp(stmt->file, "computed") == 0)
{
xkb->flags |= AutoKeyNames;
- info->explicitMin = XkbMinLegalKeyCode;
- info->explicitMax = XkbMaxLegalKeyCode;
+ info->explicitMin = 0;
+ info->explicitMax = XKB_KEYCODE_MAX;
return (info->errorCount == 0);
} /* parse file, store returned info in the xkb struct */
else if (ProcessIncludeFile(stmt, XkmKeyNamesIndex, &rtrn, &newMerge))
@@ -582,17 +639,19 @@ HandleKeycodeDef(KeycodeDef * stmt, unsigned merge, KeyNamesInfo * info)
int code;
ExprResult result;
- if (!ExprResolveInteger(stmt->value, &result, NULL, NULL))
+ if (!ExprResolveKeyCode(stmt->value, &result))
{
ACTION("No value keycode assigned to name <%s>\n", stmt->name);
return 0;
}
- code = result.ival;
- if ((code < info->effectiveMin) || (code > info->effectiveMax))
+ code = result.uval;
+ if ((info->explicitMin != 0 && code < info->explicitMin) ||
+ (info->explicitMax != 0 && code > info->explicitMax))
{
ERROR("Illegal keycode %d for name <%s>\n", code, stmt->name);
ACTION("Must be in the range %d-%d inclusive\n",
- info->effectiveMin, info->effectiveMax);
+ info->explicitMin,
+ info->explicitMax ? info->explicitMax : XKB_KEYCODE_MAX);
return 0;
}
if (stmt->merge != MergeDefault)
@@ -610,7 +669,7 @@ HandleKeycodeDef(KeycodeDef * stmt, unsigned merge, KeyNamesInfo * info)
/**
* Handle the minimum/maximum statement of the xkb file.
- * Sets explicitMin/Max and effectiveMin/Max of the info struct.
+ * Sets explicitMin/Max of the info struct.
*
* @return 1 on success, 0 otherwise.
*/
@@ -647,59 +706,57 @@ HandleKeyNameVar(VarDef * stmt, KeyNamesInfo * info)
return 0;
}
- if (ExprResolveInteger(stmt->value, &tmp, NULL, NULL) == 0)
+ if (ExprResolveKeyCode(stmt->value, &tmp) == 0)
{
ACTION("Assignment to field %s ignored\n", field.str);
return 0;
}
- if ((tmp.ival < XkbMinLegalKeyCode) || (tmp.ival > XkbMaxLegalKeyCode))
+ if (tmp.uval > XKB_KEYCODE_MAX)
{
ERROR
("Illegal keycode %d (must be in the range %d-%d inclusive)\n",
- tmp.ival, XkbMinLegalKeyCode, XkbMaxLegalKeyCode);
+ tmp.uval, 0, XKB_KEYCODE_MAX);
ACTION("Value of \"%s\" not changed\n", field.str);
return 0;
}
if (which == MIN_KEYCODE_DEF)
{
- if ((info->explicitMax > 0) && (info->explicitMax < tmp.ival))
+ if ((info->explicitMax > 0) && (info->explicitMax < tmp.uval))
{
ERROR
("Minimum key code (%d) must be <= maximum key code (%d)\n",
- tmp.ival, info->explicitMax);
+ tmp.uval, info->explicitMax);
ACTION("Minimum key code value not changed\n");
return 0;
}
- if ((info->computedMax > 0) && (info->computedMin < tmp.ival))
+ if ((info->computedMax > 0) && (info->computedMin < tmp.uval))
{
ERROR
("Minimum key code (%d) must be <= lowest defined key (%d)\n",
- tmp.ival, info->computedMin);
+ tmp.uval, info->computedMin);
ACTION("Minimum key code value not changed\n");
return 0;
}
- info->explicitMin = tmp.ival;
- info->effectiveMin = tmp.ival;
+ info->explicitMin = tmp.uval;
}
if (which == MAX_KEYCODE_DEF)
{
- if ((info->explicitMin > 0) && (info->explicitMin > tmp.ival))
+ if ((info->explicitMin > 0) && (info->explicitMin > tmp.uval))
{
ERROR("Maximum code (%d) must be >= minimum key code (%d)\n",
- tmp.ival, info->explicitMin);
+ tmp.uval, info->explicitMin);
ACTION("Maximum code value not changed\n");
return 0;
}
- if ((info->computedMax > 0) && (info->computedMax > tmp.ival))
+ if ((info->computedMax > 0) && (info->computedMax > tmp.uval))
{
ERROR
("Maximum code (%d) must be >= highest defined key (%d)\n",
- tmp.ival, info->computedMax);
+ tmp.uval, info->computedMax);
ACTION("Maximum code value not changed\n");
return 0;
}
- info->explicitMax = tmp.ival;
- info->effectiveMax = tmp.ival;
+ info->explicitMax = tmp.uval;
}
return 1;
}
@@ -834,11 +891,11 @@ CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
if (info.errorCount == 0)
{
if (info.explicitMin > 0) /* if "minimum" statement was present */
- xkb->min_key_code = info.effectiveMin;
+ xkb->min_key_code = info.explicitMin;
else
xkb->min_key_code = info.computedMin;
if (info.explicitMax > 0) /* if "maximum" statement was present */
- xkb->max_key_code = info.effectiveMax;
+ xkb->max_key_code = info.explicitMax;
else
xkb->max_key_code = info.computedMax;
if (XkbcAllocNames(xkb, XkbKeyNamesMask | XkbIndicatorNamesMask, 0, 0)
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 33412bc..e538bab 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -247,7 +247,7 @@ typedef struct _KeyNameDesc
Bool
FindNamedKey(struct xkb_desc * xkb,
unsigned long name,
- unsigned int *kc_rtrn,
+ xkb_keycode_t *kc_rtrn,
Bool use_aliases, Bool create, int start_from)
{
register unsigned n;
@@ -285,11 +285,6 @@ FindNamedKey(struct xkb_desc * xkb,
{
if ((!xkb->names) || (!xkb->names->keys))
{
- if (xkb->min_key_code < XkbMinLegalKeyCode)
- {
- xkb->min_key_code = XkbMinLegalKeyCode;
- xkb->max_key_code = XkbMaxLegalKeyCode;
- }
if (XkbcAllocNames(xkb, XkbKeyNamesMask, 0, 0) != Success)
{
if (warningLevel > 0)
diff --git a/src/xkbcomp/misc.h b/src/xkbcomp/misc.h
index 4314134..cdeb1f2 100644
--- a/src/xkbcomp/misc.h
+++ b/src/xkbcomp/misc.h
@@ -77,7 +77,7 @@ extern Bool ProcessIncludeFile(IncludeStmt * /* stmt */ ,
extern Bool FindNamedKey(struct xkb_desc * /* xkb */ ,
unsigned long /* name */ ,
- unsigned int * /* kc_rtrn */ ,
+ xkb_keycode_t * /* kc_rtrn */ ,
Bool /* use_aliases */ ,
Bool /* create */ ,
int /* start_from */
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 30005b9..72bd020 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1719,7 +1719,7 @@ HandleSymbolsFile(XkbFile * file,
}
static Bool
-FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, unsigned int *kc_rtrn)
+FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
{
register int i, j;
register Bool gotOne;
@@ -1952,7 +1952,8 @@ static Bool
CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
{
register int i;
- unsigned okc, kc, width, tmp, nGroups;
+ xkb_keycode_t okc, kc;
+ unsigned width, tmp, nGroups;
struct xkb_key_type * type;
Bool haveActions, autoType, useAlias;
uint32_t *outSyms;
@@ -2158,7 +2159,7 @@ CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
static Bool
CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
{
- unsigned kc;
+ xkb_keycode_t kc;
if ((!entry->haveSymbol)
&&
diff --git a/src/xkbcomp/xkbparse.y b/src/xkbcomp/xkbparse.y
index bc581db..4214e9c 100644
--- a/src/xkbcomp/xkbparse.y
+++ b/src/xkbcomp/xkbparse.y
@@ -135,7 +135,7 @@
}
%type <ival> Number Integer Float SignedNumber
%type <uval> XkbCompositeType FileType MergeMode OptMergeMode
-%type <uval> DoodadType Flag Flags OptFlags
+%type <uval> DoodadType Flag Flags OptFlags KeyCode
%type <str> KeyName MapName OptMapName KeySym
%type <sval> FieldSpec Ident Element String
%type <any> DeclList Decl
@@ -325,7 +325,7 @@ VarDecl : Lhs EQUALS Expr SEMI
{ $$= BoolVarCreate($2,0); }
;
-KeyNameDecl : KeyName EQUALS Expr SEMI
+KeyNameDecl : KeyName EQUALS KeyCode SEMI
{
KeycodeDef *def;
@@ -707,6 +707,13 @@ Terminal : String
free($1);
$$= expr;
}
+ | KeyCode
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprValue,TypeKeyCode);
+ expr->value.uval= $1;
+ $$= expr;
+ }
;
OptKeySymList : KeySymList { $$= $1; }
@@ -749,6 +756,9 @@ Float : FLOAT { $$= scanInt; }
Integer : INTEGER { $$= scanInt; }
;
+KeyCode : INTEGER { $$= scanULong; }
+ ;
+
KeyName : KEYNAME { $$= strdup(scanBuf); }
;
diff --git a/src/xkbcomp/xkbscan.l b/src/xkbcomp/xkbscan.l
index 0bb9681..d32cf39 100644
--- a/src/xkbcomp/xkbscan.l
+++ b/src/xkbcomp/xkbscan.l
@@ -39,6 +39,7 @@ char *scanFile = NULL;
int lineNum = 0;
int scanInt;
+unsigned long scanULong;
static char *s;
char scanBuf[1024];
@@ -145,6 +146,7 @@ alternate_group return ALTERNATE_GROUP;
[0-9]+ {
char *end;
scanInt = strtol(yytext, &end, 0);
+ scanULong = strtoul(yytext, &end, 0);
return INTEGER;
}
diff --git a/test/basic.xkb b/test/basic.xkb
index 047dbdc..4b06836 100644
--- a/test/basic.xkb
+++ b/test/basic.xkb
@@ -3,5 +3,4 @@ xkb_keymap {
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us" };
- xkb_geometry { include "pc(pc105)" };
};