Hash :
ef88c7ef
Author :
Date :
2012-04-03T15:14:16
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 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
/************************************************************
Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be
used in advertising or publicity pertaining to distribution
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability
of this software for any purpose. It is provided "as is"
without any express or implied warranty.
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
#include <X11/X.h>
#include "xkbcomp.h"
#include "xkbmisc.h"
#include "expr.h"
#include "keycodes.h"
#include "vmod.h"
#include "misc.h"
#include "action.h"
#include "misc.h"
static Bool actionsInitialized;
static ExprDef constTrue;
static ExprDef constFalse;
/***====================================================================***/
static const LookupEntry actionStrings[] = {
{ "noaction", XkbSA_NoAction },
{ "setmods", XkbSA_SetMods },
{ "latchmods", XkbSA_LatchMods },
{ "lockmods", XkbSA_LockMods },
{ "setgroup", XkbSA_SetGroup },
{ "latchgroup", XkbSA_LatchGroup },
{ "lockgroup", XkbSA_LockGroup },
{ "moveptr", XkbSA_MovePtr },
{ "movepointer", XkbSA_MovePtr },
{ "ptrbtn", XkbSA_PtrBtn },
{ "pointerbutton", XkbSA_PtrBtn },
{ "lockptrbtn", XkbSA_LockPtrBtn },
{ "lockpointerbutton", XkbSA_LockPtrBtn },
{ "lockptrbutton", XkbSA_LockPtrBtn },
{ "lockpointerbtn", XkbSA_LockPtrBtn },
{ "setptrdflt", XkbSA_SetPtrDflt },
{ "setpointerdefault", XkbSA_SetPtrDflt },
{ "isolock", XkbSA_ISOLock },
{ "terminate", XkbSA_Terminate },
{ "terminateserver", XkbSA_Terminate },
{ "switchscreen", XkbSA_SwitchScreen },
{ "setcontrols", XkbSA_SetControls },
{ "lockcontrols", XkbSA_LockControls },
{ "actionmessage", XkbSA_ActionMessage },
{ "messageaction", XkbSA_ActionMessage },
{ "message", XkbSA_ActionMessage },
{ "redirect", XkbSA_RedirectKey },
{ "redirectkey", XkbSA_RedirectKey },
{ "devbtn", XkbSA_DeviceBtn },
{ "devicebtn", XkbSA_DeviceBtn },
{ "devbutton", XkbSA_DeviceBtn },
{ "devicebutton", XkbSA_DeviceBtn },
{ "lockdevbtn", XkbSA_DeviceBtn },
{ "lockdevicebtn", XkbSA_LockDeviceBtn },
{ "lockdevbutton", XkbSA_LockDeviceBtn },
{ "lockdevicebutton", XkbSA_LockDeviceBtn },
{ "devval", XkbSA_DeviceValuator },
{ "deviceval", XkbSA_DeviceValuator },
{ "devvaluator", XkbSA_DeviceValuator },
{ "devicevaluator", XkbSA_DeviceValuator },
{ "private", PrivateAction },
{ NULL, 0 }
};
static const LookupEntry fieldStrings[] = {
{ "clearLocks", F_ClearLocks },
{ "latchToLock", F_LatchToLock },
{ "genKeyEvent", F_GenKeyEvent },
{ "generateKeyEvent", F_GenKeyEvent },
{ "report", F_Report },
{ "default", F_Default },
{ "affect", F_Affect },
{ "increment", F_Increment },
{ "modifiers", F_Modifiers },
{ "mods", F_Modifiers },
{ "group", F_Group },
{ "x", F_X },
{ "y", F_Y },
{ "accel", F_Accel },
{ "accelerate", F_Accel },
{ "repeat", F_Accel },
{ "button", F_Button },
{ "value", F_Value },
{ "controls", F_Controls },
{ "ctrls", F_Controls },
{ "type", F_Type },
{ "count", F_Count },
{ "screen", F_Screen },
{ "same", F_Same },
{ "sameServer", F_Same },
{ "data", F_Data },
{ "device", F_Device },
{ "dev", F_Device },
{ "key", F_Keycode },
{ "keycode", F_Keycode },
{ "kc", F_Keycode },
{ "clearmods", F_ModsToClear },
{ "clearmodifiers", F_ModsToClear },
{ NULL, 0 }
};
static Bool
stringToValue(const LookupEntry tab[], const char *string,
unsigned *value_rtrn)
{
const LookupEntry *entry;
if (!string)
return False;
for (entry = tab; entry->name != NULL; entry++) {
if (strcasecmp(entry->name, string) == 0) {
*value_rtrn = entry->result;
return True;
}
}
return False;
}
static const char *
valueToString(const LookupEntry tab[], unsigned value)
{
const LookupEntry *entry;
for (entry = tab; entry->name != NULL; entry++)
if (entry->result == value)
return entry->name;
return "unknown";
}
static Bool
stringToAction(const char *str, unsigned *type_rtrn)
{
return stringToValue(actionStrings, str, type_rtrn);
}
static Bool
stringToField(const char *str, unsigned *field_rtrn)
{
return stringToValue(fieldStrings, str, field_rtrn);
}
static const char *
fieldText(unsigned field)
{
return valueToString(fieldStrings, field);
}
/***====================================================================***/
static Bool
ReportMismatch(unsigned action, unsigned field, const char *type)
{
ERROR("Value of %s field must be of type %s\n", fieldText(field), type);
ACTION("Action %s definition ignored\n", XkbcActionTypeText(action));
return False;
}
static Bool
ReportIllegal(unsigned action, unsigned field)
{
ERROR("Field %s is not defined for an action of type %s\n",
fieldText(field), XkbcActionTypeText(action));
ACTION("Action definition ignored\n");
return False;
}
static Bool
ReportActionNotArray(unsigned action, unsigned field)
{
ERROR("The %s field in the %s action is not an array\n",
fieldText(field), XkbcActionTypeText(action));
ACTION("Action definition ignored\n");
return False;
}
static Bool
ReportNotFound(unsigned action, unsigned field, const char *what,
const char *bad)
{
ERROR("%s named %s not found\n", what, bad);
ACTION("Ignoring the %s field of an %s action\n", fieldText(field),
XkbcActionTypeText(action));
return False;
}
static Bool
HandleNoAction(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
return ReportIllegal(action->type, field);
}
static Bool
CheckLatchLockFlags(unsigned action,
unsigned field, ExprDef * value, unsigned *flags_inout)
{
unsigned tmp;
ExprResult result;
if (field == F_ClearLocks)
tmp = XkbSA_ClearLocks;
else if (field == F_LatchToLock)
tmp = XkbSA_LatchToLock;
else
return False; /* WSGO! */
if (!ExprResolveBoolean(value, &result))
return ReportMismatch(action, field, "boolean");
if (result.uval)
*flags_inout |= tmp;
else
*flags_inout &= ~tmp;
return True;
}
static Bool
CheckModifierField(struct xkb_keymap * xkb,
unsigned action,
ExprDef * value,
unsigned *flags_inout, unsigned *mods_rtrn)
{
ExprResult rtrn;
if (value->op == ExprIdent)
{
const char *valStr;
valStr = XkbcAtomText(value->value.str);
if (valStr && ((strcasecmp(valStr, "usemodmapmods") == 0) ||
(strcasecmp(valStr, "modmapmods") == 0)))
{
*mods_rtrn = 0;
*flags_inout |= XkbSA_UseModMapMods;
return True;
}
}
if (!ExprResolveVModMask(value, &rtrn, xkb))
return ReportMismatch(action, F_Modifiers, "modifier mask");
*mods_rtrn = rtrn.uval;
*flags_inout &= ~XkbSA_UseModMapMods;
return True;
}
static Bool
HandleSetLatchMods(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
struct xkb_mod_action *act;
unsigned rtrn;
unsigned t1, t2;
act = (struct xkb_mod_action *) action;
if (array_ndx != NULL)
{
switch (field)
{
case F_ClearLocks:
case F_LatchToLock:
case F_Modifiers:
return ReportActionNotArray(action->type, field);
}
}
switch (field)
{
case F_ClearLocks:
case F_LatchToLock:
rtrn = act->flags;
if (CheckLatchLockFlags(action->type, field, value, &rtrn))
{
act->flags = rtrn;
return True;
}
return False;
case F_Modifiers:
t1 = act->flags;
if (CheckModifierField(xkb, action->type, value, &t1, &t2))
{
act->flags = t1;
act->real_mods = act->mask = (t2 & 0xff);
act->vmods = (t2 >> 8) & 0xffff;
return True;
}
return False;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleLockMods(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
struct xkb_mod_action *act;
unsigned t1, t2;
act = (struct xkb_mod_action *) action;
if ((array_ndx != NULL) && (field == F_Modifiers))
return ReportActionNotArray(action->type, field);
switch (field)
{
case F_Modifiers:
t1 = act->flags;
if (CheckModifierField(xkb, action->type, value, &t1, &t2))
{
act->flags = t1;
act->real_mods = act->mask = (t2 & 0xff);
act->vmods = (t2 >> 8) & 0xffff;
return True;
}
return False;
}
return ReportIllegal(action->type, field);
}
static Bool
CheckGroupField(unsigned action,
ExprDef * value, unsigned *flags_inout, int *grp_rtrn)
{
ExprDef *spec;
ExprResult rtrn;
if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
{
*flags_inout &= ~XkbSA_GroupAbsolute;
spec = value->value.child;
}
else
{
*flags_inout |= XkbSA_GroupAbsolute;
spec = value;
}
if (!ExprResolveGroup(spec, &rtrn))
return ReportMismatch(action, F_Group, "integer (range 1..8)");
if (value->op == OpNegate)
*grp_rtrn = -rtrn.ival;
else if (value->op == OpUnaryPlus)
*grp_rtrn = rtrn.ival;
else
*grp_rtrn = rtrn.ival - 1;
return True;
}
static Bool
HandleSetLatchGroup(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
struct xkb_group_action *act;
unsigned rtrn;
unsigned t1;
int t2;
act = (struct xkb_group_action *) action;
if (array_ndx != NULL)
{
switch (field)
{
case F_ClearLocks:
case F_LatchToLock:
case F_Group:
return ReportActionNotArray(action->type, field);
}
}
switch (field)
{
case F_ClearLocks:
case F_LatchToLock:
rtrn = act->flags;
if (CheckLatchLockFlags(action->type, field, value, &rtrn))
{
act->flags = rtrn;
return True;
}
return False;
case F_Group:
t1 = act->flags;
if (CheckGroupField(action->type, value, &t1, &t2))
{
act->flags = t1;
act->group = t2;
return True;
}
return False;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleLockGroup(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
struct xkb_group_action *act;
unsigned t1;
int t2;
act = (struct xkb_group_action *) action;
if ((array_ndx != NULL) && (field == F_Group))
return ReportActionNotArray(action->type, field);
if (field == F_Group)
{
t1 = act->flags;
if (CheckGroupField(action->type, value, &t1, &t2))
{
act->flags = t1;
act->group = t2;
return True;
}
return False;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleMovePtr(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_pointer_action *act;
Bool absolute;
act = (struct xkb_pointer_action *) action;
if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
return ReportActionNotArray(action->type, field);
if ((field == F_X) || (field == F_Y))
{
if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
absolute = False;
else
absolute = True;
if (!ExprResolveInteger(value, &rtrn))
return ReportMismatch(action->type, field, "integer");
if (field == F_X)
{
if (absolute)
act->flags |= XkbSA_MoveAbsoluteX;
act->x = rtrn.ival;
}
else
{
if (absolute)
act->flags |= XkbSA_MoveAbsoluteY;
act->y = rtrn.ival;
}
return True;
}
else if (field == F_Accel)
{
if (!ExprResolveBoolean(value, &rtrn))
return ReportMismatch(action->type, field, "boolean");
if (rtrn.uval)
act->flags &= ~XkbSA_NoAcceleration;
else
act->flags |= XkbSA_NoAcceleration;
}
return ReportIllegal(action->type, field);
}
static const LookupEntry lockWhich[] = {
{"both", 0},
{"lock", XkbSA_LockNoUnlock},
{"neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock)},
{"unlock", XkbSA_LockNoLock},
{NULL, 0}
};
static Bool
HandlePtrBtn(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_pointer_button_action *act;
act = (struct xkb_pointer_button_action *) action;
if (field == F_Button)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveButton(value, &rtrn))
return ReportMismatch(action->type, field,
"integer (range 1..5)");
if ((rtrn.ival < 0) || (rtrn.ival > 5))
{
ERROR("Button must specify default or be in the range 1..5\n");
ACTION("Illegal button value %d ignored\n", rtrn.ival);
return False;
}
act->button = rtrn.ival;
return True;
}
else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect))
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveEnum(value, &rtrn, lockWhich))
return ReportMismatch(action->type, field, "lock or unlock");
act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
act->flags |= rtrn.ival;
return True;
}
else if (field == F_Count)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveButton(value, &rtrn))
return ReportMismatch(action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("The count field must have a value in the range 0..255\n");
ACTION("Illegal count %d ignored\n", rtrn.ival);
return False;
}
act->count = rtrn.ival;
return True;
}
return ReportIllegal(action->type, field);
}
static const LookupEntry ptrDflts[] = {
{"dfltbtn", XkbSA_AffectDfltBtn},
{"defaultbutton", XkbSA_AffectDfltBtn},
{"button", XkbSA_AffectDfltBtn},
{NULL, 0}
};
static Bool
HandleSetPtrDflt(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_pointer_default_action *act;
act = (struct xkb_pointer_default_action *) action;
if (field == F_Affect)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveEnum(value, &rtrn, ptrDflts))
return ReportMismatch(action->type, field, "pointer component");
act->affect = rtrn.uval;
return True;
}
else if ((field == F_Button) || (field == F_Value))
{
ExprDef *btn;
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
{
act->flags &= ~XkbSA_DfltBtnAbsolute;
btn = value->value.child;
}
else
{
act->flags |= XkbSA_DfltBtnAbsolute;
btn = value;
}
if (!ExprResolveButton(btn, &rtrn))
return ReportMismatch(action->type, field,
"integer (range 1..5)");
if ((rtrn.ival < 0) || (rtrn.ival > 5))
{
ERROR("New default button value must be in the range 1..5\n");
ACTION("Illegal default button value %d ignored\n", rtrn.ival);
return False;
}
if (rtrn.ival == 0)
{
ERROR("Cannot set default pointer button to \"default\"\n");
ACTION("Illegal default button setting ignored\n");
return False;
}
if (value->op == OpNegate)
act->value = -rtrn.ival;
else
act->value = rtrn.ival;
return True;
}
return ReportIllegal(action->type, field);
}
static const LookupEntry isoNames[] = {
{"mods", XkbSA_ISONoAffectMods},
{"modifiers", XkbSA_ISONoAffectMods},
{"group", XkbSA_ISONoAffectGroup},
{"groups", XkbSA_ISONoAffectGroup},
{"ptr", XkbSA_ISONoAffectPtr},
{"pointer", XkbSA_ISONoAffectPtr},
{"ctrls", XkbSA_ISONoAffectCtrls},
{"controls", XkbSA_ISONoAffectCtrls},
{"all", ~((unsigned) 0)},
{"none", 0},
{NULL, 0},
};
static Bool
HandleISOLock(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_iso_action *act;
unsigned flags, mods;
int group;
act = (struct xkb_iso_action *) action;
switch (field)
{
case F_Modifiers:
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
flags = act->flags;
if (CheckModifierField(xkb, action->type, value, &flags, &mods))
{
act->flags = flags & (~XkbSA_ISODfltIsGroup);
act->real_mods = mods & 0xff;
act->vmods = (mods >> 8) & 0xff;
return True;
}
return False;
case F_Group:
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
flags = act->flags;
if (CheckGroupField(action->type, value, &flags, &group))
{
act->flags = flags | XkbSA_ISODfltIsGroup;
act->group = group;
return True;
}
return False;
case F_Affect:
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveMask(value, &rtrn, isoNames))
return ReportMismatch(action->type, field, "keyboard component");
act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
return True;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleSwitchScreen(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_switch_screen_action *act;
act = (struct xkb_switch_screen_action *) action;
if (field == F_Screen)
{
ExprDef *scrn;
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
{
act->flags &= ~XkbSA_SwitchAbsolute;
scrn = value->value.child;
}
else
{
act->flags |= XkbSA_SwitchAbsolute;
scrn = value;
}
if (!ExprResolveInteger(scrn, &rtrn))
return ReportMismatch(action->type, field, "integer (0..255)");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("Screen index must be in the range 1..255\n");
ACTION("Illegal screen value %d ignored\n", rtrn.ival);
return False;
}
if (value->op == OpNegate)
act->screen = -rtrn.ival;
else
act->screen = rtrn.ival;
return True;
}
else if (field == F_Same)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveBoolean(value, &rtrn))
return ReportMismatch(action->type, field, "boolean");
if (rtrn.uval)
act->flags &= ~XkbSA_SwitchApplication;
else
act->flags |= XkbSA_SwitchApplication;
return True;
}
return ReportIllegal(action->type, field);
}
const LookupEntry ctrlNames[] = {
{"repeatkeys", XkbRepeatKeysMask},
{"repeat", XkbRepeatKeysMask},
{"autorepeat", XkbRepeatKeysMask},
{"slowkeys", XkbSlowKeysMask},
{"bouncekeys", XkbBounceKeysMask},
{"stickykeys", XkbStickyKeysMask},
{"mousekeys", XkbMouseKeysMask},
{"mousekeysaccel", XkbMouseKeysAccelMask},
{"accessxkeys", XkbAccessXKeysMask},
{"accessxtimeout", XkbAccessXTimeoutMask},
{"accessxfeedback", XkbAccessXFeedbackMask},
{"audiblebell", XkbAudibleBellMask},
{"ignoregrouplock", XkbIgnoreGroupLockMask},
{"all", XkbAllBooleanCtrlsMask},
{"overlay1", 0},
{"overlay2", 0},
{"none", 0},
{NULL, 0}
};
static Bool
HandleSetLockControls(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_controls_action *act;
act = (struct xkb_controls_action *) action;
if (field == F_Controls)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveMask(value, &rtrn, ctrlNames))
return ReportMismatch(action->type, field, "controls mask");
act->ctrls = rtrn.uval;
return True;
}
return ReportIllegal(action->type, field);
}
static const LookupEntry evNames[] = {
{"press", XkbSA_MessageOnPress},
{"keypress", XkbSA_MessageOnPress},
{"release", XkbSA_MessageOnRelease},
{"keyrelease", XkbSA_MessageOnRelease},
{"all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease},
{"none", 0},
{NULL, 0}
};
static Bool
HandleActionMessage(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_message_action *act;
act = (struct xkb_message_action *) action;
switch (field)
{
case F_Report:
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveMask(value, &rtrn, evNames))
return ReportMismatch(action->type, field, "key event mask");
act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
act->flags =
rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
return True;
case F_GenKeyEvent:
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveBoolean(value, &rtrn))
return ReportMismatch(action->type, field, "boolean");
if (rtrn.uval)
act->flags |= XkbSA_MessageGenKeyEvent;
else
act->flags &= ~XkbSA_MessageGenKeyEvent;
return True;
case F_Data:
if (array_ndx == NULL)
{
if (!ExprResolveString(value, &rtrn))
return ReportMismatch(action->type, field, "string");
else
{
int len = strlen(rtrn.str);
if ((len < 1) || (len > 6))
{
WARN("An action message can hold only 6 bytes\n");
ACTION("Extra %d bytes ignored\n", len - 6);
}
strncpy((char *) act->message, rtrn.str, 6);
}
return True;
}
else
{
unsigned ndx;
if (!ExprResolveInteger(array_ndx, &rtrn))
{
ERROR("Array subscript must be integer\n");
ACTION("Illegal subscript ignored\n");
return False;
}
ndx = rtrn.uval;
if (ndx > 5)
{
ERROR("An action message is at most 6 bytes long\n");
ACTION("Attempt to use data[%d] ignored\n", ndx);
return False;
}
if (!ExprResolveInteger(value, &rtrn))
return ReportMismatch(action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("Message data must be in the range 0..255\n");
ACTION("Illegal datum %d ignored\n", rtrn.ival);
return False;
}
act->message[ndx] = rtrn.uval;
}
return True;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleRedirectKey(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_redirect_key_action *act;
unsigned t1, t2;
xkb_keycode_t kc;
unsigned long tmp;
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
act = (struct xkb_redirect_key_action *) action;
switch (field)
{
case F_Keycode:
if (!ExprResolveKeyName(value, &rtrn))
return ReportMismatch(action->type, field, "key name");
tmp = KeyNameToLong(rtrn.keyName.name);
if (!FindNamedKey(xkb, tmp, &kc, True, CreateKeyNames(xkb), 0))
{
return ReportNotFound(action->type, field, "Key",
XkbcKeyNameText(rtrn.keyName.name));
}
act->new_key = kc;
return True;
case F_ModsToClear:
case F_Modifiers:
t1 = 0;
if (CheckModifierField(xkb, action->type, value, &t1, &t2))
{
act->mods_mask |= (t2 & 0xff);
if (field == F_Modifiers)
act->mods |= (t2 & 0xff);
else
act->mods &= ~(t2 & 0xff);
t2 = (t2 >> 8) & 0xffff;
act->vmods_mask |= t2;
if (field == F_Modifiers)
act->vmods |= t2;
else
act->vmods &= ~t2;
return True;
}
return True;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleDeviceBtn(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
struct xkb_device_button_action *act;
act = (struct xkb_device_button_action *) action;
if (field == F_Button)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveInteger(value, &rtrn))
return ReportMismatch(action->type, field,
"integer (range 1..255)");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("Button must specify default or be in the range 1..255\n");
ACTION("Illegal button value %d ignored\n", rtrn.ival);
return False;
}
act->button = rtrn.ival;
return True;
}
else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect))
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveEnum(value, &rtrn, lockWhich))
return ReportMismatch(action->type, field, "lock or unlock");
act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
act->flags |= rtrn.ival;
return True;
}
else if (field == F_Count)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveButton(value, &rtrn))
return ReportMismatch(action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("The count field must have a value in the range 0..255\n");
ACTION("Illegal count %d ignored\n", rtrn.ival);
return False;
}
act->count = rtrn.ival;
return True;
}
else if (field == F_Device)
{
if (array_ndx != NULL)
return ReportActionNotArray(action->type, field);
if (!ExprResolveInteger(value, &rtrn))
return ReportMismatch(action->type, field,
"integer (range 1..255)");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("Device must specify default or be in the range 1..255\n");
ACTION("Illegal device value %d ignored\n", rtrn.ival);
return False;
}
act->device = rtrn.ival;
return True;
}
return ReportIllegal(action->type, field);
}
static Bool
HandleDeviceValuator(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
#if 0
ExprResult rtrn;
struct xkb_device_valuator_action *act;
act = (struct xkb_device_valuator_action *) action;
/* XXX - Not yet implemented */
#endif
return False;
}
static Bool
HandlePrivate(struct xkb_keymap * xkb,
struct xkb_any_action * action,
unsigned field, ExprDef * array_ndx, ExprDef * value)
{
ExprResult rtrn;
switch (field)
{
case F_Type:
if (!ExprResolveInteger(value, &rtrn))
return ReportMismatch(PrivateAction, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("Private action type must be in the range 0..255\n");
ACTION("Illegal type %d ignored\n", rtrn.ival);
return False;
}
action->type = rtrn.uval;
return True;
case F_Data:
if (array_ndx == NULL)
{
if (!ExprResolveString(value, &rtrn))
return ReportMismatch(action->type, field, "string");
else
{
int len = strlen(rtrn.str);
if ((len < 1) || (len > 7))
{
WARN("A private action has 7 data bytes\n");
ACTION("Extra %d bytes ignored\n", len - 6);
return False;
}
strncpy((char *) action->data, rtrn.str, sizeof action->data);
}
free(rtrn.str);
return True;
}
else
{
unsigned ndx;
if (!ExprResolveInteger(array_ndx, &rtrn))
{
ERROR("Array subscript must be integer\n");
ACTION("Illegal subscript ignored\n");
return False;
}
ndx = rtrn.uval;
if (ndx >= sizeof action->data)
{
ERROR("The data for a private action is 18 bytes long\n");
ACTION("Attempt to use data[%d] ignored\n", ndx);
return False;
}
if (!ExprResolveInteger(value, &rtrn))
return ReportMismatch(action->type, field, "integer");
if ((rtrn.ival < 0) || (rtrn.ival > 255))
{
ERROR("All data for a private action must be 0..255\n");
ACTION("Illegal datum %d ignored\n", rtrn.ival);
return False;
}
action->data[ndx] = rtrn.uval;
return True;
}
}
return ReportIllegal(PrivateAction, field);
}
typedef Bool(*actionHandler) (struct xkb_keymap * /* xkb */ ,
struct xkb_any_action * /* action */ ,
unsigned /* field */ ,
ExprDef * /* array_ndx */ ,
ExprDef * /* value */
);
static const actionHandler handleAction[XkbSA_NumActions + 1] = {
HandleNoAction /* NoAction */ ,
HandleSetLatchMods /* SetMods */ ,
HandleSetLatchMods /* LatchMods */ ,
HandleLockMods /* LockMods */ ,
HandleSetLatchGroup /* SetGroup */ ,
HandleSetLatchGroup /* LatchGroup */ ,
HandleLockGroup /* LockGroup */ ,
HandleMovePtr /* MovePtr */ ,
HandlePtrBtn /* PtrBtn */ ,
HandlePtrBtn /* LockPtrBtn */ ,
HandleSetPtrDflt /* SetPtrDflt */ ,
HandleISOLock /* ISOLock */ ,
HandleNoAction /* Terminate */ ,
HandleSwitchScreen /* SwitchScreen */ ,
HandleSetLockControls /* SetControls */ ,
HandleSetLockControls /* LockControls */ ,
HandleActionMessage /* ActionMessage */ ,
HandleRedirectKey /* RedirectKey */ ,
HandleDeviceBtn /* DeviceBtn */ ,
HandleDeviceBtn /* LockDeviceBtn */ ,
HandleDeviceValuator /* DeviceValuatr */ ,
HandlePrivate /* Private */
};
/***====================================================================***/
static void
ApplyActionFactoryDefaults(union xkb_action * action)
{
if (action->type == XkbSA_SetPtrDflt)
{ /* increment default button */
action->dflt.affect = XkbSA_AffectDfltBtn;
action->dflt.flags = 0;
action->dflt.value = 1;
}
else if (action->type == XkbSA_ISOLock)
{
action->iso.real_mods = LockMask;
}
}
static void
ActionsInit(void);
int
HandleActionDef(ExprDef * def,
struct xkb_keymap * xkb,
struct xkb_any_action * action, unsigned mergeMode, ActionInfo * info)
{
ExprDef *arg;
const char *str;
unsigned tmp, hndlrType;
if (!actionsInitialized)
ActionsInit();
if (def->op != ExprActionDecl)
{
ERROR("Expected an action definition, found %s\n",
exprOpText(def->op));
return False;
}
str = XkbcAtomText(def->value.action.name);
if (!str)
{
WSGO("Missing name in action definition!!\n");
return False;
}
if (!stringToAction(str, &tmp))
{
ERROR("Unknown action %s\n", str);
return False;
}
action->type = hndlrType = tmp;
if (action->type != XkbSA_NoAction)
{
ApplyActionFactoryDefaults((union xkb_action *) action);
while (info)
{
if ((info->action == XkbSA_NoAction)
|| (info->action == hndlrType))
{
if (!(*handleAction[hndlrType]) (xkb, action,
info->field,
info->array_ndx,
info->value))
{
return False;
}
}
info = info->next;
}
}
for (arg = def->value.action.args; arg != NULL;
arg = (ExprDef *) arg->common.next)
{
ExprDef *field, *value, *arrayRtrn;
ExprResult elemRtrn, fieldRtrn;
unsigned fieldNdx;
if (arg->op == OpAssign)
{
field = arg->value.binary.left;
value = arg->value.binary.right;
}
else
{
if ((arg->op == OpNot) || (arg->op == OpInvert))
{
field = arg->value.child;
constFalse.value.str = xkb_intern_atom("false");
value = &constFalse;
}
else
{
field = arg;
constTrue.value.str = xkb_intern_atom("true");
value = &constTrue;
}
}
if (!ExprResolveLhs(field, &elemRtrn, &fieldRtrn, &arrayRtrn))
return False; /* internal error -- already reported */
if (elemRtrn.str != NULL)
{
ERROR("Cannot change defaults in an action definition\n");
ACTION("Ignoring attempt to change %s.%s\n", elemRtrn.str,
fieldRtrn.str);
free(elemRtrn.str);
free(fieldRtrn.str);
return False;
}
if (!stringToField(fieldRtrn.str, &fieldNdx))
{
ERROR("Unknown field name %s\n", uStringText(fieldRtrn.str));
free(elemRtrn.str);
free(fieldRtrn.str);
return False;
}
free(elemRtrn.str);
free(fieldRtrn.str);
if (!(*handleAction[hndlrType])
(xkb, action, fieldNdx, arrayRtrn, value))
{
return False;
}
}
return True;
}
/***====================================================================***/
int
SetActionField(struct xkb_keymap * xkb,
char *elem,
char *field,
ExprDef * array_ndx, ExprDef * value, ActionInfo ** info_rtrn)
{
ActionInfo *new, *old;
if (!actionsInitialized)
ActionsInit();
new = uTypedAlloc(ActionInfo);
if (new == NULL)
{
WSGO("Couldn't allocate space for action default\n");
return False;
}
if (strcasecmp(elem, "action") == 0)
new->action = XkbSA_NoAction;
else
{
if (!stringToAction(elem, &new->action))
{
free(new);
return False;
}
if (new->action == XkbSA_NoAction)
{
ERROR("\"%s\" is not a valid field in a NoAction action\n",
field);
free(new);
return False;
}
}
if (!stringToField(field, &new->field))
{
ERROR("\"%s\" is not a legal field name\n", field);
free(new);
return False;
}
new->array_ndx = array_ndx;
new->value = value;
new->next = NULL;
old = *info_rtrn;
while ((old) && (old->next))
old = old->next;
if (old == NULL)
*info_rtrn = new;
else
old->next = new;
return True;
}
/***====================================================================***/
static void
ActionsInit(void)
{
if (!actionsInitialized)
{
memset(&constTrue, 0, sizeof(constTrue));
memset(&constFalse, 0, sizeof(constFalse));
constTrue.common.stmtType = StmtExpr;
constTrue.common.next = NULL;
constTrue.op = ExprIdent;
constTrue.type = TypeBoolean;
constTrue.value.str = xkb_intern_atom("true");
constFalse.common.stmtType = StmtExpr;
constFalse.common.next = NULL;
constFalse.op = ExprIdent;
constFalse.type = TypeBoolean;
constFalse.value.str = xkb_intern_atom("false");
actionsInitialized = 1;
}
}