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 const ExprDef constTrue = {
30 .common = { .type = STMT_EXPR, .next = NULL },
32 .value_type = EXPR_TYPE_BOOLEAN,
33 .value = { .ival = 1 },
36 static const ExprDef constFalse = {
37 .common = { .type = STMT_EXPR, .next = NULL },
39 .value_type = EXPR_TYPE_BOOLEAN,
40 .value = { .ival = 0 },
43 /***====================================================================***/
45 static const LookupEntry actionStrings[] = {
46 { "noaction", XkbSA_NoAction },
47 { "setmods", XkbSA_SetMods },
48 { "latchmods", XkbSA_LatchMods },
49 { "lockmods", XkbSA_LockMods },
50 { "setgroup", XkbSA_SetGroup },
51 { "latchgroup", XkbSA_LatchGroup },
52 { "lockgroup", XkbSA_LockGroup },
53 { "moveptr", XkbSA_MovePtr },
54 { "movepointer", XkbSA_MovePtr },
55 { "ptrbtn", XkbSA_PtrBtn },
56 { "pointerbutton", XkbSA_PtrBtn },
57 { "lockptrbtn", XkbSA_LockPtrBtn },
58 { "lockpointerbutton", XkbSA_LockPtrBtn },
59 { "lockptrbutton", XkbSA_LockPtrBtn },
60 { "lockpointerbtn", XkbSA_LockPtrBtn },
61 { "setptrdflt", XkbSA_SetPtrDflt },
62 { "setpointerdefault", XkbSA_SetPtrDflt },
63 { "isolock", XkbSA_ISOLock },
64 { "terminate", XkbSA_Terminate },
65 { "terminateserver", XkbSA_Terminate },
66 { "switchscreen", XkbSA_SwitchScreen },
67 { "setcontrols", XkbSA_SetControls },
68 { "lockcontrols", XkbSA_LockControls },
69 { "actionmessage", XkbSA_ActionMessage },
70 { "messageaction", XkbSA_ActionMessage },
71 { "message", XkbSA_ActionMessage },
72 { "redirect", XkbSA_RedirectKey },
73 { "redirectkey", XkbSA_RedirectKey },
74 { "devbtn", XkbSA_DeviceBtn },
75 { "devicebtn", XkbSA_DeviceBtn },
76 { "devbutton", XkbSA_DeviceBtn },
77 { "devicebutton", XkbSA_DeviceBtn },
78 { "lockdevbtn", XkbSA_DeviceBtn },
79 { "lockdevicebtn", XkbSA_LockDeviceBtn },
80 { "lockdevbutton", XkbSA_LockDeviceBtn },
81 { "lockdevicebutton", XkbSA_LockDeviceBtn },
82 { "devval", XkbSA_DeviceValuator },
83 { "deviceval", XkbSA_DeviceValuator },
84 { "devvaluator", XkbSA_DeviceValuator },
85 { "devicevaluator", XkbSA_DeviceValuator },
86 { "private", PrivateAction },
90 static const LookupEntry fieldStrings[] = {
91 { "clearLocks", F_ClearLocks },
92 { "latchToLock", F_LatchToLock },
93 { "genKeyEvent", F_GenKeyEvent },
94 { "generateKeyEvent", F_GenKeyEvent },
95 { "report", F_Report },
96 { "default", F_Default },
97 { "affect", F_Affect },
98 { "increment", F_Increment },
99 { "modifiers", F_Modifiers },
100 { "mods", F_Modifiers },
101 { "group", F_Group },
104 { "accel", F_Accel },
105 { "accelerate", F_Accel },
106 { "repeat", F_Accel },
107 { "button", F_Button },
108 { "value", F_Value },
109 { "controls", F_Controls },
110 { "ctrls", F_Controls },
112 { "count", F_Count },
113 { "screen", F_Screen },
115 { "sameServer", F_Same },
117 { "device", F_Device },
119 { "key", F_Keycode },
120 { "keycode", F_Keycode },
122 { "clearmods", F_ModsToClear },
123 { "clearmodifiers", F_ModsToClear },
128 stringToValue(const LookupEntry tab[], const char *string,
129 unsigned int *value_rtrn)
131 const LookupEntry *entry;
136 for (entry = tab; entry->name; entry++) {
137 if (istreq(entry->name, string)) {
138 *value_rtrn = entry->value;
147 valueToString(const LookupEntry tab[], unsigned int value)
149 const LookupEntry *entry;
151 for (entry = tab; entry->name; entry++)
152 if (entry->value == value)
159 stringToAction(const char *str, unsigned *type_rtrn)
161 return stringToValue(actionStrings, str, type_rtrn);
165 stringToField(const char *str, unsigned *field_rtrn)
167 return stringToValue(fieldStrings, str, field_rtrn);
171 fieldText(unsigned field)
173 return valueToString(fieldStrings, field);
176 /***====================================================================***/
179 ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
183 "Value of %s field must be of type %s; "
184 "Action %s definition ignored\n",
185 fieldText(field), type, ActionTypeText(action));
190 ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
193 "Field %s is not defined for an action of type %s; "
194 "Action definition ignored\n",
195 fieldText(field), ActionTypeText(action));
200 ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
204 "The %s field in the %s action is not an array; "
205 "Action definition ignored\n",
206 fieldText(field), ActionTypeText(action));
211 ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
212 const char *what, const char *bad)
215 "%s named %s not found; "
216 "Ignoring the %s field of an %s action\n",
217 what, bad, fieldText(field), ActionTypeText(action));
222 HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
223 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
226 return ReportIllegal(keymap, action->type, field);
230 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
231 unsigned field, const ExprDef * value,
232 unsigned *flags_inout)
237 if (field == F_ClearLocks)
238 tmp = XkbSA_ClearLocks;
239 else if (field == F_LatchToLock)
240 tmp = XkbSA_LatchToLock;
242 return false; /* WSGO! */
244 if (!ExprResolveBoolean(keymap->ctx, value, &result))
245 return ReportMismatch(keymap, action, field, "boolean");
250 *flags_inout &= ~tmp;
256 CheckModifierField(struct xkb_keymap *keymap, unsigned action,
257 const ExprDef *value, unsigned *flags_inout,
258 xkb_mod_mask_t *mods_rtrn)
260 if (value->op == EXPR_IDENT) {
262 valStr = xkb_atom_text(keymap->ctx, value->value.str);
263 if (valStr && (istreq(valStr, "usemodmapmods") ||
264 istreq(valStr, "modmapmods"))) {
267 *flags_inout |= XkbSA_UseModMapMods;
272 if (!ExprResolveVModMask(keymap, value, mods_rtrn))
273 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
275 *flags_inout &= ~XkbSA_UseModMapMods;
280 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
281 unsigned field, const ExprDef *array_ndx,
282 const ExprDef *value)
284 struct xkb_mod_action *act = &action->mods;
289 if (array_ndx != NULL) {
294 return ReportActionNotArray(keymap, action->type, field);
301 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
309 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
316 return ReportIllegal(keymap, action->type, field);
320 HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
321 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
323 struct xkb_mod_action *act = &action->mods;
327 if ((array_ndx != NULL) && (field == F_Modifiers))
328 return ReportActionNotArray(keymap, action->type, field);
332 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
339 return ReportIllegal(keymap, action->type, field);
343 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
344 const ExprDef *value, unsigned *flags_inout,
345 xkb_group_index_t *grp_rtrn)
349 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
350 *flags_inout &= ~XkbSA_GroupAbsolute;
351 spec = value->value.child;
354 *flags_inout |= XkbSA_GroupAbsolute;
358 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
359 return ReportMismatch(keymap, action, F_Group,
360 "integer (range 1..8)");
362 if (value->op == EXPR_NEGATE)
363 *grp_rtrn = -*grp_rtrn;
364 else if (value->op != EXPR_UNARY_PLUS)
371 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
372 unsigned field, const ExprDef *array_ndx,
373 const ExprDef *value)
375 struct xkb_group_action *act = &action->group;
378 xkb_group_index_t t2;
380 if (array_ndx != NULL) {
385 return ReportActionNotArray(keymap, action->type, field);
392 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
400 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
407 return ReportIllegal(keymap, action->type, field);
411 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
412 unsigned field, const ExprDef *array_ndx,
413 const ExprDef *value)
415 struct xkb_group_action *act = &action->group;
417 xkb_group_index_t t2;
419 if ((array_ndx != NULL) && (field == F_Group))
420 return ReportActionNotArray(keymap, action->type, field);
421 if (field == F_Group) {
423 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
430 return ReportIllegal(keymap, action->type, field);
434 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
435 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
437 struct xkb_pointer_action *act = &action->ptr;
440 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
441 return ReportActionNotArray(keymap, action->type, field);
443 if (field == F_X || field == F_Y) {
446 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
451 if (!ExprResolveInteger(keymap->ctx, value, &val))
452 return ReportMismatch(keymap, action->type, field, "integer");
456 act->flags |= XkbSA_MoveAbsoluteX;
461 act->flags |= XkbSA_MoveAbsoluteY;
467 else if (field == F_Accel) {
470 if (!ExprResolveBoolean(keymap->ctx, value, &set))
471 return ReportMismatch(keymap, action->type, field, "boolean");
474 act->flags &= ~XkbSA_NoAcceleration;
476 act->flags |= XkbSA_NoAcceleration;
479 return ReportIllegal(keymap, action->type, field);
482 static const LookupEntry lockWhich[] = {
484 { "lock", XkbSA_LockNoUnlock },
485 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
486 { "unlock", XkbSA_LockNoLock },
491 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
492 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
494 struct xkb_pointer_button_action *act = &action->btn;
496 if (field == F_Button) {
500 return ReportActionNotArray(keymap, action->type, field);
502 if (!ExprResolveButton(keymap->ctx, value, &btn))
503 return ReportMismatch(keymap, action->type, field,
504 "integer (range 1..5)");
506 if (btn < 0 || btn > 5) {
508 "Button must specify default or be in the range 1..5; "
509 "Illegal button value %d ignored\n", btn);
516 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
520 return ReportActionNotArray(keymap, action->type, field);
522 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
523 return ReportMismatch(keymap, action->type, field,
526 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
530 else if (field == F_Count) {
534 return ReportActionNotArray(keymap, action->type, field);
536 /* XXX: Should this actually be ResolveButton? */
537 if (!ExprResolveButton(keymap->ctx, value, &btn))
538 return ReportMismatch(keymap, action->type, field, "integer");
540 if (btn < 0 || btn > 255) {
542 "The count field must have a value in the range 0..255; "
543 "Illegal count %d ignored\n", btn);
550 return ReportIllegal(keymap, action->type, field);
553 static const LookupEntry ptrDflts[] = {
554 { "dfltbtn", XkbSA_AffectDfltBtn },
555 { "defaultbutton", XkbSA_AffectDfltBtn },
556 { "button", XkbSA_AffectDfltBtn },
561 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
562 unsigned field, const ExprDef *array_ndx,
563 const ExprDef *value)
565 struct xkb_pointer_default_action *act = &action->dflt;
567 if (field == F_Affect) {
571 return ReportActionNotArray(keymap, action->type, field);
573 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
574 return ReportMismatch(keymap, action->type, field,
575 "pointer component");
579 else if ((field == F_Button) || (field == F_Value)) {
580 const ExprDef *button;
584 return ReportActionNotArray(keymap, action->type, field);
586 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
587 act->flags &= ~XkbSA_DfltBtnAbsolute;
588 button = value->value.child;
591 act->flags |= XkbSA_DfltBtnAbsolute;
595 if (!ExprResolveButton(keymap->ctx, button, &btn))
596 return ReportMismatch(keymap, action->type, field,
597 "integer (range 1..5)");
599 if (btn < 0 || btn > 5) {
601 "New default button value must be in the range 1..5; "
602 "Illegal default button value %d ignored\n", btn);
607 "Cannot set default pointer button to \"default\"; "
608 "Illegal default button setting ignored\n");
612 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
616 return ReportIllegal(keymap, action->type, field);
619 static const LookupEntry isoNames[] = {
620 { "mods", XkbSA_ISONoAffectMods },
621 { "modifiers", XkbSA_ISONoAffectMods },
622 { "group", XkbSA_ISONoAffectGroup },
623 { "groups", XkbSA_ISONoAffectGroup },
624 { "ptr", XkbSA_ISONoAffectPtr },
625 { "pointer", XkbSA_ISONoAffectPtr },
626 { "ctrls", XkbSA_ISONoAffectCtrls },
627 { "controls", XkbSA_ISONoAffectCtrls },
628 { "all", ~((unsigned) 0) },
634 HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
635 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
637 struct xkb_iso_action *act = &action->iso;
639 if (field == F_Modifiers) {
644 return ReportActionNotArray(keymap, action->type, field);
647 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
650 act->flags = flags & (~XkbSA_ISODfltIsGroup);
651 act->mods.mods = mods;
654 else if (field == F_Group) {
655 xkb_group_index_t group;
659 return ReportActionNotArray(keymap, action->type, field);
662 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
665 act->flags = flags | XkbSA_ISODfltIsGroup;
668 } else if (F_Affect) {
672 return ReportActionNotArray(keymap, action->type, field);
674 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
675 return ReportMismatch(keymap, action->type, field,
676 "keyboard component");
678 act->affect = (~mask) & XkbSA_ISOAffectMask;
682 return ReportIllegal(keymap, action->type, field);
686 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
687 unsigned field, const ExprDef *array_ndx,
688 const ExprDef *value)
690 struct xkb_switch_screen_action *act = &action->screen;
692 if (field == F_Screen) {
697 return ReportActionNotArray(keymap, action->type, field);
699 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
700 act->flags &= ~XkbSA_SwitchAbsolute;
701 scrn = value->value.child;
704 act->flags |= XkbSA_SwitchAbsolute;
708 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
709 return ReportMismatch(keymap, action->type, field,
712 if (val < 0 || val > 255) {
714 "Screen index must be in the range 1..255; "
715 "Illegal screen value %d ignored\n", val);
719 act->screen = (value->op == EXPR_NEGATE ? -val : val);
722 else if (field == F_Same) {
726 return ReportActionNotArray(keymap, action->type, field);
728 if (!ExprResolveBoolean(keymap->ctx, value, &set))
729 return ReportMismatch(keymap, action->type, field, "boolean");
732 act->flags &= ~XkbSA_SwitchApplication;
734 act->flags |= XkbSA_SwitchApplication;
739 return ReportIllegal(keymap, action->type, field);
742 const LookupEntry ctrlNames[] = {
743 { "repeatkeys", XkbRepeatKeysMask },
744 { "repeat", XkbRepeatKeysMask },
745 { "autorepeat", XkbRepeatKeysMask },
746 { "slowkeys", XkbSlowKeysMask },
747 { "bouncekeys", XkbBounceKeysMask },
748 { "stickykeys", XkbStickyKeysMask },
749 { "mousekeys", XkbMouseKeysMask },
750 { "mousekeysaccel", XkbMouseKeysAccelMask },
751 { "accessxkeys", XkbAccessXKeysMask },
752 { "accessxtimeout", XkbAccessXTimeoutMask },
753 { "accessxfeedback", XkbAccessXFeedbackMask },
754 { "audiblebell", XkbAudibleBellMask },
755 { "ignoregrouplock", XkbIgnoreGroupLockMask },
756 { "all", XkbAllBooleanCtrlsMask },
764 HandleSetLockControls(struct xkb_keymap *keymap,
765 union xkb_action *action,
766 unsigned field, const ExprDef *array_ndx,
767 const ExprDef *value)
769 struct xkb_controls_action *act = &action->ctrls;
771 if (field == F_Controls) {
775 return ReportActionNotArray(keymap, action->type, field);
777 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
778 return ReportMismatch(keymap, action->type, field,
785 return ReportIllegal(keymap, action->type, field);
788 static const LookupEntry evNames[] = {
789 { "press", XkbSA_MessageOnPress },
790 { "keypress", XkbSA_MessageOnPress },
791 { "release", XkbSA_MessageOnRelease },
792 { "keyrelease", XkbSA_MessageOnRelease },
793 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
799 HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
800 unsigned field, const ExprDef *array_ndx,
801 const ExprDef *value)
803 struct xkb_message_action *act = &action->msg;
805 if (field == F_Report) {
809 return ReportActionNotArray(keymap, action->type, field);
811 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
812 return ReportMismatch(keymap, action->type, field,
815 /* FIXME: Something seems wrong here... */
816 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
817 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
820 else if (field == F_GenKeyEvent) {
824 return ReportActionNotArray(keymap, action->type, field);
826 if (!ExprResolveBoolean(keymap->ctx, value, &set))
827 return ReportMismatch(keymap, action->type, field, "boolean");
830 act->flags |= XkbSA_MessageGenKeyEvent;
832 act->flags &= ~XkbSA_MessageGenKeyEvent;
836 else if (field == F_Data && !array_ndx) {
840 if (!ExprResolveString(keymap->ctx, value, &str))
841 return ReportMismatch(keymap, action->type, field, "string");
844 if (len < 1 || len > 6) {
845 log_warn(keymap->ctx,
846 "An action message can hold only 6 bytes; "
847 "Extra %d bytes ignored\n", len - 6);
850 strncpy((char *) act->message, str, 6);
853 else if (field == F_Data && array_ndx) {
856 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
858 "Array subscript must be integer; "
859 "Illegal subscript ignored\n");
863 if (ndx < 0 || ndx > 5) {
865 "An action message is at most 6 bytes long; "
866 "Attempt to use data[%d] ignored\n", ndx);
870 if (!ExprResolveInteger(keymap->ctx, value, &datum))
871 return ReportMismatch(keymap, action->type, field, "integer");
873 if (datum < 0 || datum > 255) {
875 "Message data must be in the range 0..255; "
876 "Illegal datum %d ignored\n", datum);
880 act->message[ndx] = (uint8_t) datum;
884 return ReportIllegal(keymap, action->type, field);
888 HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
889 unsigned field, const ExprDef *array_ndx,
890 const ExprDef *value)
893 struct xkb_redirect_key_action *act = &action->redirect;
897 char key_name[XkbKeyNameLength];
899 if (array_ndx != NULL)
900 return ReportActionNotArray(keymap, action->type, field);
904 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
905 return ReportMismatch(keymap, action->type, field, "key name");
907 tmp = KeyNameToLong(key_name);
908 key = FindNamedKey(keymap, tmp, true, 0);
910 return ReportNotFound(keymap, action->type, field, "Key",
911 KeyNameText(key_name));
912 act->new_kc = XkbKeyGetKeycode(keymap, key);
918 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
919 act->mods_mask |= (t2 & 0xff);
920 if (field == F_Modifiers)
921 act->mods |= (t2 & 0xff);
923 act->mods &= ~(t2 & 0xff);
925 t2 = (t2 >> XkbNumModifiers) & 0xffff;
926 act->vmods_mask |= t2;
927 if (field == F_Modifiers)
935 return ReportIllegal(keymap, action->type, field);
939 HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
940 unsigned field, const ExprDef *array_ndx,
941 const ExprDef *value)
943 struct xkb_device_button_action *act = &action->devbtn;
945 if (field == F_Button) {
949 return ReportActionNotArray(keymap, action->type, field);
951 if (!ExprResolveInteger(keymap->ctx, value, &val))
952 return ReportMismatch(keymap, action->type, field,
953 "integer (range 1..255)");
955 if (val < 0 || val > 255) {
957 "Button must specify default or be in the range 1..255; "
958 "Illegal button value %d ignored\n", val);
965 else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
969 return ReportActionNotArray(keymap, action->type, field);
971 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
972 return ReportMismatch(keymap, action->type, field,
975 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
979 else if (field == F_Count) {
983 return ReportActionNotArray(keymap, action->type, field);
985 /* XXX: Should this actually be ResolveButton? */
986 if (!ExprResolveButton(keymap->ctx, value, &btn))
987 return ReportMismatch(keymap, action->type, field, "integer");
989 if (btn < 0 || btn > 255) {
991 "The count field must have a value in the range 0..255; "
992 "Illegal count %d ignored\n", btn);
999 else if (field == F_Device) {
1003 return ReportActionNotArray(keymap, action->type, field);
1005 if (!ExprResolveInteger(keymap->ctx, value, &val))
1006 return ReportMismatch(keymap, action->type, field,
1007 "integer (range 1..255)");
1009 if (val < 0 || val > 255) {
1010 log_err(keymap->ctx,
1011 "Device must specify default or be in the range 1..255; "
1012 "Illegal device value %d ignored\n", val);
1020 return ReportIllegal(keymap, action->type, field);
1024 HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
1025 unsigned field, const ExprDef *array_ndx,
1026 const ExprDef *value)
1028 struct xkb_device_valuator_action *act = &action->devval;
1031 /* XXX - Not yet implemented */
1036 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
1037 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
1039 struct xkb_private_action *act = &action->priv;
1041 if (field == F_Type) {
1044 if (!ExprResolveInteger(keymap->ctx, value, &type))
1045 return ReportMismatch(keymap, PrivateAction, field, "integer");
1047 if (type < 0 || type > 255) {
1048 log_err(keymap->ctx,
1049 "Private action type must be in the range 0..255; "
1050 "Illegal type %d ignored\n", type);
1054 act->type = (uint8_t) type;
1057 else if (field == F_Data) {
1058 if (array_ndx == NULL) {
1062 if (!ExprResolveString(keymap->ctx, value, &str))
1063 return ReportMismatch(keymap, action->type, field, "string");
1066 if (len < 1 || len > 7) {
1067 log_warn(keymap->ctx,
1068 "A private action has 7 data bytes; "
1069 "Extra %d bytes ignored\n", len - 6);
1073 strncpy((char *) act->data, str, sizeof(act->data));
1079 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1080 log_err(keymap->ctx,
1081 "Array subscript must be integer; "
1082 "Illegal subscript ignored\n");
1086 if (ndx < 0 || ndx >= sizeof(act->data)) {
1087 log_err(keymap->ctx,
1088 "The data for a private action is %zu bytes long; "
1089 "Attempt to use data[%d] ignored\n",
1090 sizeof(act->data), ndx);
1094 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1095 return ReportMismatch(keymap, act->type, field, "integer");
1097 if (datum < 0 || datum > 255) {
1098 log_err(keymap->ctx,
1099 "All data for a private action must be 0..255; "
1100 "Illegal datum %d ignored\n", datum);
1104 act->data[ndx] = (uint8_t) datum;
1109 return ReportIllegal(keymap, PrivateAction, field);
1112 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1113 union xkb_action *action, unsigned field,
1114 const ExprDef *array_ndx, const ExprDef *value);
1116 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1117 [XkbSA_NoAction] = HandleNoAction,
1118 [XkbSA_SetMods] = HandleSetLatchMods,
1119 [XkbSA_LatchMods] = HandleSetLatchMods,
1120 [XkbSA_LockMods] = HandleLockMods,
1121 [XkbSA_SetGroup] = HandleSetLatchGroup,
1122 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1123 [XkbSA_LockGroup] = HandleLockGroup,
1124 [XkbSA_MovePtr] = HandleMovePtr,
1125 [XkbSA_PtrBtn] = HandlePtrBtn,
1126 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1127 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1128 [XkbSA_ISOLock] = HandleISOLock,
1129 [XkbSA_Terminate] = HandleNoAction,
1130 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1131 [XkbSA_SetControls] = HandleSetLockControls,
1132 [XkbSA_LockControls] = HandleSetLockControls,
1133 [XkbSA_ActionMessage] = HandleActionMessage,
1134 [XkbSA_RedirectKey] = HandleRedirectKey,
1135 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1136 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1137 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1138 [PrivateAction] = HandlePrivate,
1141 /***====================================================================***/
1144 ApplyActionFactoryDefaults(union xkb_action * action)
1146 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1147 action->dflt.affect = XkbSA_AffectDfltBtn;
1148 action->dflt.flags = 0;
1149 action->dflt.value = 1;
1151 else if (action->type == XkbSA_ISOLock) {
1152 action->iso.mods.mods = (1 << ModNameToIndex(XKB_MOD_NAME_CAPS));
1157 HandleActionDef(ExprDef * def,
1158 struct xkb_keymap *keymap,
1159 union xkb_action *action, ActionInfo *info)
1163 unsigned tmp, hndlrType;
1165 if (def->op != EXPR_ACTION_DECL) {
1166 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1167 exprOpText(def->op));
1170 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1172 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1175 if (!stringToAction(str, &tmp)) {
1176 log_err(keymap->ctx, "Unknown action %s\n", str);
1179 action->type = hndlrType = tmp;
1180 if (action->type != XkbSA_NoAction) {
1181 ApplyActionFactoryDefaults((union xkb_action *) action);
1184 if ((info->action == XkbSA_NoAction)
1185 || (info->action == hndlrType)) {
1186 if (!(*handleAction[hndlrType])(keymap, action,
1196 for (arg = def->value.action.args; arg != NULL;
1197 arg = (ExprDef *) arg->common.next) {
1198 const ExprDef *value;
1199 ExprDef *field, *arrayRtrn;
1200 const char *elemRtrn, *fieldRtrn;
1203 if (arg->op == EXPR_ASSIGN) {
1204 field = arg->value.binary.left;
1205 value = arg->value.binary.right;
1208 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1209 field = arg->value.child;
1210 value = &constFalse;
1217 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1219 return false; /* internal error -- already reported */
1221 if (elemRtrn != NULL) {
1222 log_err(keymap->ctx,
1223 "Cannot change defaults in an action definition; "
1224 "Ignoring attempt to change %s.%s\n",
1225 elemRtrn, fieldRtrn);
1228 if (!stringToField(fieldRtrn, &fieldNdx)) {
1229 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1232 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1239 /***====================================================================***/
1242 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1243 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1245 ActionInfo *new, *old;
1247 new = malloc(sizeof(*new));
1249 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1253 if (istreq(elem, "action"))
1254 new->action = XkbSA_NoAction;
1256 if (!stringToAction(elem, &new->action)) {
1260 if (new->action == XkbSA_NoAction) {
1261 log_err(keymap->ctx,
1262 "\"%s\" is not a valid field in a NoAction action\n",
1268 if (!stringToField(field, &new->field)) {
1269 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1273 new->array_ndx = array_ndx;
1277 while ((old) && (old->next))