1 /************************************************************
2 * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of Silicon Graphics not be
10 * used in advertising or publicity pertaining to distribution
11 * of the software without specific prior written permission.
12 * Silicon Graphics makes no representation about the suitability
13 * of this software for any purpose. It is provided "as is"
14 * without any express or implied warranty.
16 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
29 static bool actionsInitialized;
30 static ExprDef constTrue;
31 static ExprDef constFalse;
33 /***====================================================================***/
35 static const LookupEntry actionStrings[] = {
36 { "noaction", XkbSA_NoAction },
37 { "setmods", XkbSA_SetMods },
38 { "latchmods", XkbSA_LatchMods },
39 { "lockmods", XkbSA_LockMods },
40 { "setgroup", XkbSA_SetGroup },
41 { "latchgroup", XkbSA_LatchGroup },
42 { "lockgroup", XkbSA_LockGroup },
43 { "moveptr", XkbSA_MovePtr },
44 { "movepointer", XkbSA_MovePtr },
45 { "ptrbtn", XkbSA_PtrBtn },
46 { "pointerbutton", XkbSA_PtrBtn },
47 { "lockptrbtn", XkbSA_LockPtrBtn },
48 { "lockpointerbutton", XkbSA_LockPtrBtn },
49 { "lockptrbutton", XkbSA_LockPtrBtn },
50 { "lockpointerbtn", XkbSA_LockPtrBtn },
51 { "setptrdflt", XkbSA_SetPtrDflt },
52 { "setpointerdefault", XkbSA_SetPtrDflt },
53 { "isolock", XkbSA_ISOLock },
54 { "terminate", XkbSA_Terminate },
55 { "terminateserver", XkbSA_Terminate },
56 { "switchscreen", XkbSA_SwitchScreen },
57 { "setcontrols", XkbSA_SetControls },
58 { "lockcontrols", XkbSA_LockControls },
59 { "actionmessage", XkbSA_ActionMessage },
60 { "messageaction", XkbSA_ActionMessage },
61 { "message", XkbSA_ActionMessage },
62 { "redirect", XkbSA_RedirectKey },
63 { "redirectkey", XkbSA_RedirectKey },
64 { "devbtn", XkbSA_DeviceBtn },
65 { "devicebtn", XkbSA_DeviceBtn },
66 { "devbutton", XkbSA_DeviceBtn },
67 { "devicebutton", XkbSA_DeviceBtn },
68 { "lockdevbtn", XkbSA_DeviceBtn },
69 { "lockdevicebtn", XkbSA_LockDeviceBtn },
70 { "lockdevbutton", XkbSA_LockDeviceBtn },
71 { "lockdevicebutton", XkbSA_LockDeviceBtn },
72 { "devval", XkbSA_DeviceValuator },
73 { "deviceval", XkbSA_DeviceValuator },
74 { "devvaluator", XkbSA_DeviceValuator },
75 { "devicevaluator", XkbSA_DeviceValuator },
76 { "private", PrivateAction },
80 static const LookupEntry fieldStrings[] = {
81 { "clearLocks", F_ClearLocks },
82 { "latchToLock", F_LatchToLock },
83 { "genKeyEvent", F_GenKeyEvent },
84 { "generateKeyEvent", F_GenKeyEvent },
85 { "report", F_Report },
86 { "default", F_Default },
87 { "affect", F_Affect },
88 { "increment", F_Increment },
89 { "modifiers", F_Modifiers },
90 { "mods", F_Modifiers },
95 { "accelerate", F_Accel },
96 { "repeat", F_Accel },
97 { "button", F_Button },
99 { "controls", F_Controls },
100 { "ctrls", F_Controls },
102 { "count", F_Count },
103 { "screen", F_Screen },
105 { "sameServer", F_Same },
107 { "device", F_Device },
109 { "key", F_Keycode },
110 { "keycode", F_Keycode },
112 { "clearmods", F_ModsToClear },
113 { "clearmodifiers", F_ModsToClear },
118 stringToValue(const LookupEntry tab[], const char *string,
119 unsigned *value_rtrn)
121 const LookupEntry *entry;
126 for (entry = tab; entry->name != NULL; entry++) {
127 if (strcasecmp(entry->name, string) == 0) {
128 *value_rtrn = entry->result;
137 valueToString(const LookupEntry tab[], unsigned value)
139 const LookupEntry *entry;
141 for (entry = tab; entry->name != NULL; entry++)
142 if (entry->result == value)
149 stringToAction(const char *str, unsigned *type_rtrn)
151 return stringToValue(actionStrings, str, type_rtrn);
155 stringToField(const char *str, unsigned *field_rtrn)
157 return stringToValue(fieldStrings, str, field_rtrn);
161 fieldText(unsigned field)
163 return valueToString(fieldStrings, field);
166 /***====================================================================***/
169 ReportMismatch(unsigned action, unsigned field, const char *type)
171 ERROR("Value of %s field must be of type %s\n", fieldText(field), type);
172 ACTION("Action %s definition ignored\n", XkbcActionTypeText(action));
177 ReportIllegal(unsigned action, unsigned field)
179 ERROR("Field %s is not defined for an action of type %s\n",
180 fieldText(field), XkbcActionTypeText(action));
181 ACTION("Action definition ignored\n");
186 ReportActionNotArray(unsigned action, unsigned field)
188 ERROR("The %s field in the %s action is not an array\n",
189 fieldText(field), XkbcActionTypeText(action));
190 ACTION("Action definition ignored\n");
195 ReportNotFound(unsigned action, unsigned field, const char *what,
198 ERROR("%s named %s not found\n", what, bad);
199 ACTION("Ignoring the %s field of an %s action\n", fieldText(field),
200 XkbcActionTypeText(action));
205 HandleNoAction(struct xkb_keymap *keymap, struct xkb_any_action *action,
206 unsigned field, ExprDef *array_ndx, ExprDef *value)
208 return ReportIllegal(action->type, field);
212 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
213 unsigned field, ExprDef * value, unsigned *flags_inout)
218 if (field == F_ClearLocks)
219 tmp = XkbSA_ClearLocks;
220 else if (field == F_LatchToLock)
221 tmp = XkbSA_LatchToLock;
223 return false; /* WSGO! */
224 if (!ExprResolveBoolean(keymap->ctx, value, &result))
225 return ReportMismatch(action, field, "boolean");
229 *flags_inout &= ~tmp;
234 CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
235 unsigned *flags_inout, unsigned *mods_rtrn)
239 if (value->op == ExprIdent) {
241 valStr = xkb_atom_text(keymap->ctx, value->value.str);
242 if (valStr && ((strcasecmp(valStr, "usemodmapmods") == 0) ||
243 (strcasecmp(valStr, "modmapmods") == 0))) {
246 *flags_inout |= XkbSA_UseModMapMods;
250 if (!ExprResolveVModMask(value, &rtrn, keymap))
251 return ReportMismatch(action, F_Modifiers, "modifier mask");
252 *mods_rtrn = rtrn.uval;
253 *flags_inout &= ~XkbSA_UseModMapMods;
258 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
259 unsigned field, ExprDef *array_ndx, ExprDef *value)
261 struct xkb_mod_action *act;
265 act = (struct xkb_mod_action *) action;
266 if (array_ndx != NULL) {
271 return ReportActionNotArray(action->type, field);
278 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
286 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
288 act->real_mods = act->mask = (t2 & 0xff);
289 act->vmods = (t2 >> 8) & 0xffff;
294 return ReportIllegal(action->type, field);
298 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
299 unsigned field, ExprDef *array_ndx, ExprDef *value)
301 struct xkb_mod_action *act;
304 act = (struct xkb_mod_action *) action;
305 if ((array_ndx != NULL) && (field == F_Modifiers))
306 return ReportActionNotArray(action->type, field);
310 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
312 act->real_mods = act->mask = (t2 & 0xff);
313 act->vmods = (t2 >> 8) & 0xffff;
318 return ReportIllegal(action->type, field);
322 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
323 ExprDef * value, unsigned *flags_inout, int *grp_rtrn)
328 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
329 *flags_inout &= ~XkbSA_GroupAbsolute;
330 spec = value->value.child;
333 *flags_inout |= XkbSA_GroupAbsolute;
337 if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
338 return ReportMismatch(action, F_Group, "integer (range 1..8)");
339 if (value->op == OpNegate)
340 *grp_rtrn = -rtrn.ival;
341 else if (value->op == OpUnaryPlus)
342 *grp_rtrn = rtrn.ival;
344 *grp_rtrn = rtrn.ival - 1;
349 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
350 unsigned field, ExprDef *array_ndx, ExprDef *value)
352 struct xkb_group_action *act;
357 act = (struct xkb_group_action *) action;
358 if (array_ndx != NULL) {
363 return ReportActionNotArray(action->type, field);
370 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
378 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
385 return ReportIllegal(action->type, field);
389 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
390 unsigned field, ExprDef *array_ndx, ExprDef *value)
392 struct xkb_group_action *act;
396 act = (struct xkb_group_action *) action;
397 if ((array_ndx != NULL) && (field == F_Group))
398 return ReportActionNotArray(action->type, field);
399 if (field == F_Group) {
401 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
408 return ReportIllegal(action->type, field);
412 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
413 unsigned field, ExprDef *array_ndx, ExprDef *value)
416 struct xkb_pointer_action *act;
419 act = (struct xkb_pointer_action *) action;
420 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
421 return ReportActionNotArray(action->type, field);
423 if ((field == F_X) || (field == F_Y)) {
424 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
428 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
429 return ReportMismatch(action->type, field, "integer");
432 act->flags |= XkbSA_MoveAbsoluteX;
437 act->flags |= XkbSA_MoveAbsoluteY;
442 else if (field == F_Accel) {
443 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
444 return ReportMismatch(action->type, field, "boolean");
446 act->flags &= ~XkbSA_NoAcceleration;
448 act->flags |= XkbSA_NoAcceleration;
450 return ReportIllegal(action->type, field);
453 static const LookupEntry lockWhich[] = {
455 { "lock", XkbSA_LockNoUnlock },
456 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
457 { "unlock", XkbSA_LockNoLock },
462 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
463 unsigned field, ExprDef *array_ndx, ExprDef *value)
466 struct xkb_pointer_button_action *act;
468 act = (struct xkb_pointer_button_action *) action;
469 if (field == F_Button) {
470 if (array_ndx != NULL)
471 return ReportActionNotArray(action->type, field);
472 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
473 return ReportMismatch(action->type, field,
474 "integer (range 1..5)");
475 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
476 ERROR("Button must specify default or be in the range 1..5\n");
477 ACTION("Illegal button value %d ignored\n", rtrn.ival);
480 act->button = rtrn.ival;
483 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
484 if (array_ndx != NULL)
485 return ReportActionNotArray(action->type, field);
486 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
487 return ReportMismatch(action->type, field, "lock or unlock");
488 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
489 act->flags |= rtrn.ival;
492 else if (field == F_Count) {
493 if (array_ndx != NULL)
494 return ReportActionNotArray(action->type, field);
495 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
496 return ReportMismatch(action->type, field, "integer");
497 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
498 ERROR("The count field must have a value in the range 0..255\n");
499 ACTION("Illegal count %d ignored\n", rtrn.ival);
502 act->count = rtrn.ival;
505 return ReportIllegal(action->type, field);
508 static const LookupEntry ptrDflts[] = {
509 { "dfltbtn", XkbSA_AffectDfltBtn },
510 { "defaultbutton", XkbSA_AffectDfltBtn },
511 { "button", XkbSA_AffectDfltBtn },
516 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
517 unsigned field, ExprDef *array_ndx, ExprDef *value)
520 struct xkb_pointer_default_action *act;
522 act = (struct xkb_pointer_default_action *) action;
523 if (field == F_Affect) {
524 if (array_ndx != NULL)
525 return ReportActionNotArray(action->type, field);
526 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
527 return ReportMismatch(action->type, field, "pointer component");
528 act->affect = rtrn.uval;
531 else if ((field == F_Button) || (field == F_Value)) {
533 if (array_ndx != NULL)
534 return ReportActionNotArray(action->type, field);
535 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
536 act->flags &= ~XkbSA_DfltBtnAbsolute;
537 btn = value->value.child;
540 act->flags |= XkbSA_DfltBtnAbsolute;
544 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
545 return ReportMismatch(action->type, field,
546 "integer (range 1..5)");
547 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
548 ERROR("New default button value must be in the range 1..5\n");
549 ACTION("Illegal default button value %d ignored\n", rtrn.ival);
552 if (rtrn.ival == 0) {
553 ERROR("Cannot set default pointer button to \"default\"\n");
554 ACTION("Illegal default button setting ignored\n");
557 if (value->op == OpNegate)
558 act->value = -rtrn.ival;
560 act->value = rtrn.ival;
563 return ReportIllegal(action->type, field);
566 static const LookupEntry isoNames[] = {
567 { "mods", XkbSA_ISONoAffectMods },
568 { "modifiers", XkbSA_ISONoAffectMods },
569 { "group", XkbSA_ISONoAffectGroup },
570 { "groups", XkbSA_ISONoAffectGroup },
571 { "ptr", XkbSA_ISONoAffectPtr },
572 { "pointer", XkbSA_ISONoAffectPtr },
573 { "ctrls", XkbSA_ISONoAffectCtrls },
574 { "controls", XkbSA_ISONoAffectCtrls },
575 { "all", ~((unsigned) 0) },
581 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
582 unsigned field, ExprDef *array_ndx, ExprDef *value)
585 struct xkb_iso_action *act;
586 unsigned flags, mods;
589 act = (struct xkb_iso_action *) action;
592 if (array_ndx != NULL)
593 return ReportActionNotArray(action->type, field);
595 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
596 act->flags = flags & (~XkbSA_ISODfltIsGroup);
597 act->real_mods = mods & 0xff;
598 act->vmods = (mods >> 8) & 0xff;
604 if (array_ndx != NULL)
605 return ReportActionNotArray(action->type, field);
607 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
608 act->flags = flags | XkbSA_ISODfltIsGroup;
615 if (array_ndx != NULL)
616 return ReportActionNotArray(action->type, field);
617 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
618 return ReportMismatch(action->type, field, "keyboard component");
619 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
622 return ReportIllegal(action->type, field);
626 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
627 unsigned field, ExprDef *array_ndx, ExprDef *value)
630 struct xkb_switch_screen_action *act;
632 act = (struct xkb_switch_screen_action *) action;
633 if (field == F_Screen) {
635 if (array_ndx != NULL)
636 return ReportActionNotArray(action->type, field);
637 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
638 act->flags &= ~XkbSA_SwitchAbsolute;
639 scrn = value->value.child;
642 act->flags |= XkbSA_SwitchAbsolute;
646 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
647 return ReportMismatch(action->type, field, "integer (0..255)");
648 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
649 ERROR("Screen index must be in the range 1..255\n");
650 ACTION("Illegal screen value %d ignored\n", rtrn.ival);
653 if (value->op == OpNegate)
654 act->screen = -rtrn.ival;
656 act->screen = rtrn.ival;
659 else if (field == F_Same) {
660 if (array_ndx != NULL)
661 return ReportActionNotArray(action->type, field);
662 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
663 return ReportMismatch(action->type, field, "boolean");
665 act->flags &= ~XkbSA_SwitchApplication;
667 act->flags |= XkbSA_SwitchApplication;
670 return ReportIllegal(action->type, field);
673 const LookupEntry ctrlNames[] = {
674 { "repeatkeys", XkbRepeatKeysMask },
675 { "repeat", XkbRepeatKeysMask },
676 { "autorepeat", XkbRepeatKeysMask },
677 { "slowkeys", XkbSlowKeysMask },
678 { "bouncekeys", XkbBounceKeysMask },
679 { "stickykeys", XkbStickyKeysMask },
680 { "mousekeys", XkbMouseKeysMask },
681 { "mousekeysaccel", XkbMouseKeysAccelMask },
682 { "accessxkeys", XkbAccessXKeysMask },
683 { "accessxtimeout", XkbAccessXTimeoutMask },
684 { "accessxfeedback", XkbAccessXFeedbackMask },
685 { "audiblebell", XkbAudibleBellMask },
686 { "ignoregrouplock", XkbIgnoreGroupLockMask },
687 { "all", XkbAllBooleanCtrlsMask },
695 HandleSetLockControls(struct xkb_keymap *keymap,
696 struct xkb_any_action *action,
697 unsigned field, ExprDef *array_ndx,
701 struct xkb_controls_action *act;
703 act = (struct xkb_controls_action *) action;
704 if (field == F_Controls) {
705 if (array_ndx != NULL)
706 return ReportActionNotArray(action->type, field);
707 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
708 return ReportMismatch(action->type, field, "controls mask");
709 act->ctrls = rtrn.uval;
712 return ReportIllegal(action->type, field);
715 static const LookupEntry evNames[] = {
716 { "press", XkbSA_MessageOnPress },
717 { "keypress", XkbSA_MessageOnPress },
718 { "release", XkbSA_MessageOnRelease },
719 { "keyrelease", XkbSA_MessageOnRelease },
720 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
726 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
727 unsigned field, ExprDef *array_ndx, ExprDef *value)
730 struct xkb_message_action *act;
732 act = (struct xkb_message_action *) action;
735 if (array_ndx != NULL)
736 return ReportActionNotArray(action->type, field);
737 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
738 return ReportMismatch(action->type, field, "key event mask");
739 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
741 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
745 if (array_ndx != NULL)
746 return ReportActionNotArray(action->type, field);
747 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
748 return ReportMismatch(action->type, field, "boolean");
750 act->flags |= XkbSA_MessageGenKeyEvent;
752 act->flags &= ~XkbSA_MessageGenKeyEvent;
756 if (array_ndx == NULL) {
757 if (!ExprResolveString(keymap->ctx, value, &rtrn))
758 return ReportMismatch(action->type, field, "string");
760 int len = strlen(rtrn.str);
761 if ((len < 1) || (len > 6)) {
762 WARN("An action message can hold only 6 bytes\n");
763 ACTION("Extra %d bytes ignored\n", len - 6);
765 strncpy((char *) act->message, rtrn.str, 6);
771 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
772 ERROR("Array subscript must be integer\n");
773 ACTION("Illegal subscript ignored\n");
778 ERROR("An action message is at most 6 bytes long\n");
779 ACTION("Attempt to use data[%d] ignored\n", ndx);
782 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
783 return ReportMismatch(action->type, field, "integer");
784 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
785 ERROR("Message data must be in the range 0..255\n");
786 ACTION("Illegal datum %d ignored\n", rtrn.ival);
789 act->message[ndx] = rtrn.uval;
793 return ReportIllegal(action->type, field);
797 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
798 unsigned field, ExprDef *array_ndx, ExprDef *value)
802 struct xkb_redirect_key_action *act;
806 if (array_ndx != NULL)
807 return ReportActionNotArray(action->type, field);
809 act = (struct xkb_redirect_key_action *) action;
812 if (!ExprResolveKeyName(keymap->ctx, value, &rtrn))
813 return ReportMismatch(action->type, field, "key name");
815 tmp = KeyNameToLong(rtrn.name);
816 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
818 return ReportNotFound(action->type, field, "Key",
819 XkbcKeyNameText(rtrn.name));
820 act->new_kc = XkbKeyGetKeycode(keymap, key);
826 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
827 act->mods_mask |= (t2 & 0xff);
828 if (field == F_Modifiers)
829 act->mods |= (t2 & 0xff);
831 act->mods &= ~(t2 & 0xff);
833 t2 = (t2 >> 8) & 0xffff;
834 act->vmods_mask |= t2;
835 if (field == F_Modifiers)
843 return ReportIllegal(action->type, field);
847 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
848 unsigned field, ExprDef *array_ndx, ExprDef *value)
851 struct xkb_device_button_action *act;
853 act = (struct xkb_device_button_action *) action;
854 if (field == F_Button) {
855 if (array_ndx != NULL)
856 return ReportActionNotArray(action->type, field);
857 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
858 return ReportMismatch(action->type, field,
859 "integer (range 1..255)");
860 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
861 ERROR("Button must specify default or be in the range 1..255\n");
862 ACTION("Illegal button value %d ignored\n", rtrn.ival);
865 act->button = rtrn.ival;
868 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
869 if (array_ndx != NULL)
870 return ReportActionNotArray(action->type, field);
871 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
872 return ReportMismatch(action->type, field, "lock or unlock");
873 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
874 act->flags |= rtrn.ival;
877 else if (field == F_Count) {
878 if (array_ndx != NULL)
879 return ReportActionNotArray(action->type, field);
880 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
881 return ReportMismatch(action->type, field, "integer");
882 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
883 ERROR("The count field must have a value in the range 0..255\n");
884 ACTION("Illegal count %d ignored\n", rtrn.ival);
887 act->count = rtrn.ival;
890 else if (field == F_Device) {
891 if (array_ndx != NULL)
892 return ReportActionNotArray(action->type, field);
893 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
894 return ReportMismatch(action->type, field,
895 "integer (range 1..255)");
896 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
897 ERROR("Device must specify default or be in the range 1..255\n");
898 ACTION("Illegal device value %d ignored\n", rtrn.ival);
901 act->device = rtrn.ival;
904 return ReportIllegal(action->type, field);
908 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
909 unsigned field, ExprDef *array_ndx, ExprDef *value)
913 struct xkb_device_valuator_action *act;
915 act = (struct xkb_device_valuator_action *) action;
916 /* XXX - Not yet implemented */
922 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
923 unsigned field, ExprDef *array_ndx, ExprDef *value)
929 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
930 return ReportMismatch(PrivateAction, field, "integer");
931 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
932 ERROR("Private action type must be in the range 0..255\n");
933 ACTION("Illegal type %d ignored\n", rtrn.ival);
936 action->type = rtrn.uval;
940 if (array_ndx == NULL) {
941 if (!ExprResolveString(keymap->ctx, value, &rtrn))
942 return ReportMismatch(action->type, field, "string");
944 int len = strlen(rtrn.str);
945 if ((len < 1) || (len > 7)) {
946 WARN("A private action has 7 data bytes\n");
947 ACTION("Extra %d bytes ignored\n", len - 6);
950 strncpy((char *) action->data, rtrn.str, sizeof action->data);
957 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
958 ERROR("Array subscript must be integer\n");
959 ACTION("Illegal subscript ignored\n");
963 if (ndx >= sizeof action->data) {
964 ERROR("The data for a private action is 18 bytes long\n");
965 ACTION("Attempt to use data[%d] ignored\n", ndx);
968 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
969 return ReportMismatch(action->type, field, "integer");
970 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
971 ERROR("All data for a private action must be 0..255\n");
972 ACTION("Illegal datum %d ignored\n", rtrn.ival);
975 action->data[ndx] = rtrn.uval;
979 return ReportIllegal(PrivateAction, field);
982 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
983 struct xkb_any_action *action, unsigned field,
984 ExprDef *array_ndx, ExprDef *value);
986 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
987 [XkbSA_NoAction] = HandleNoAction,
988 [XkbSA_SetMods] = HandleSetLatchMods,
989 [XkbSA_LatchMods] = HandleSetLatchMods,
990 [XkbSA_LockMods] = HandleLockMods,
991 [XkbSA_SetGroup] = HandleSetLatchGroup,
992 [XkbSA_LatchGroup] = HandleSetLatchGroup,
993 [XkbSA_LockGroup] = HandleLockGroup,
994 [XkbSA_MovePtr] = HandleMovePtr,
995 [XkbSA_PtrBtn] = HandlePtrBtn,
996 [XkbSA_LockPtrBtn] = HandlePtrBtn,
997 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
998 [XkbSA_ISOLock] = HandleISOLock,
999 [XkbSA_Terminate] = HandleNoAction,
1000 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1001 [XkbSA_SetControls] = HandleSetLockControls,
1002 [XkbSA_LockControls] = HandleSetLockControls,
1003 [XkbSA_ActionMessage] = HandleActionMessage,
1004 [XkbSA_RedirectKey] = HandleRedirectKey,
1005 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1006 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1007 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1008 [PrivateAction] = HandlePrivate,
1011 /***====================================================================***/
1014 ApplyActionFactoryDefaults(union xkb_action * action)
1016 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1017 action->dflt.affect = XkbSA_AffectDfltBtn;
1018 action->dflt.flags = 0;
1019 action->dflt.value = 1;
1021 else if (action->type == XkbSA_ISOLock) {
1022 action->iso.real_mods = LockMask;
1027 ActionsInit(struct xkb_context *ctx);
1030 HandleActionDef(ExprDef * def,
1031 struct xkb_keymap *keymap,
1032 struct xkb_any_action *action, ActionInfo *info)
1036 unsigned tmp, hndlrType;
1038 if (!actionsInitialized)
1039 ActionsInit(keymap->ctx);
1041 if (def->op != ExprActionDecl) {
1042 ERROR("Expected an action definition, found %s\n",
1043 exprOpText(def->op));
1046 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1048 WSGO("Missing name in action definition!!\n");
1051 if (!stringToAction(str, &tmp)) {
1052 ERROR("Unknown action %s\n", str);
1055 action->type = hndlrType = tmp;
1056 if (action->type != XkbSA_NoAction) {
1057 ApplyActionFactoryDefaults((union xkb_action *) action);
1060 if ((info->action == XkbSA_NoAction)
1061 || (info->action == hndlrType)) {
1062 if (!(*handleAction[hndlrType])(keymap, action,
1072 for (arg = def->value.action.args; arg != NULL;
1073 arg = (ExprDef *) arg->common.next) {
1074 ExprDef *field, *value, *arrayRtrn;
1075 ExprResult elemRtrn, fieldRtrn;
1078 if (arg->op == OpAssign) {
1079 field = arg->value.binary.left;
1080 value = arg->value.binary.right;
1083 if ((arg->op == OpNot) || (arg->op == OpInvert)) {
1084 field = arg->value.child;
1085 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1086 value = &constFalse;
1090 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1094 if (!ExprResolveLhs(keymap, field, &elemRtrn, &fieldRtrn, &arrayRtrn))
1095 return false; /* internal error -- already reported */
1097 if (elemRtrn.str != NULL) {
1098 ERROR("Cannot change defaults in an action definition\n");
1099 ACTION("Ignoring attempt to change %s.%s\n", elemRtrn.str,
1102 free(fieldRtrn.str);
1105 if (!stringToField(fieldRtrn.str, &fieldNdx)) {
1106 ERROR("Unknown field name %s\n", uStringText(fieldRtrn.str));
1108 free(fieldRtrn.str);
1112 free(fieldRtrn.str);
1113 if (!(*handleAction[hndlrType])(keymap, action, fieldNdx, arrayRtrn,
1120 /***====================================================================***/
1123 SetActionField(struct xkb_keymap *keymap,
1126 ExprDef * array_ndx, ExprDef * value, ActionInfo ** info_rtrn)
1128 ActionInfo *new, *old;
1130 if (!actionsInitialized)
1131 ActionsInit(keymap->ctx);
1133 new = uTypedAlloc(ActionInfo);
1135 WSGO("Couldn't allocate space for action default\n");
1138 if (strcasecmp(elem, "action") == 0)
1139 new->action = XkbSA_NoAction;
1141 if (!stringToAction(elem, &new->action)) {
1145 if (new->action == XkbSA_NoAction) {
1146 ERROR("\"%s\" is not a valid field in a NoAction action\n",
1152 if (!stringToField(field, &new->field)) {
1153 ERROR("\"%s\" is not a legal field name\n", field);
1157 new->array_ndx = array_ndx;
1161 while ((old) && (old->next))
1170 /***====================================================================***/
1173 ActionsInit(struct xkb_context *ctx)
1175 if (!actionsInitialized) {
1176 memset(&constTrue, 0, sizeof(constTrue));
1177 memset(&constFalse, 0, sizeof(constFalse));
1178 constTrue.common.stmtType = StmtExpr;
1179 constTrue.common.next = NULL;
1180 constTrue.op = ExprIdent;
1181 constTrue.type = TypeBoolean;
1182 constTrue.value.str = xkb_atom_intern(ctx, "true");
1183 constFalse.common.stmtType = StmtExpr;
1184 constFalse.common.next = NULL;
1185 constFalse.op = ExprIdent;
1186 constFalse.type = TypeBoolean;
1187 constFalse.value.str = xkb_atom_intern(ctx, "false");
1188 actionsInitialized = 1;