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, struct xkb_any_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, struct xkb_any_action *action,
281 unsigned field, const ExprDef *array_ndx,
282 const ExprDef *value)
284 struct xkb_mod_action *act;
289 act = (struct xkb_mod_action *) action;
290 if (array_ndx != NULL) {
295 return ReportActionNotArray(keymap, action->type, field);
302 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
310 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
317 return ReportIllegal(keymap, action->type, field);
321 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
322 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
324 struct xkb_mod_action *act;
328 act = (struct xkb_mod_action *) action;
329 if ((array_ndx != NULL) && (field == F_Modifiers))
330 return ReportActionNotArray(keymap, action->type, field);
334 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
341 return ReportIllegal(keymap, action->type, field);
345 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
346 const ExprDef *value, unsigned *flags_inout,
347 xkb_group_index_t *grp_rtrn)
351 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
352 *flags_inout &= ~XkbSA_GroupAbsolute;
353 spec = value->value.child;
356 *flags_inout |= XkbSA_GroupAbsolute;
360 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
361 return ReportMismatch(keymap, action, F_Group,
362 "integer (range 1..8)");
364 if (value->op == EXPR_NEGATE)
365 *grp_rtrn = -*grp_rtrn;
366 else if (value->op != EXPR_UNARY_PLUS)
373 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
374 unsigned field, const ExprDef *array_ndx,
375 const ExprDef *value)
377 struct xkb_group_action *act;
380 xkb_group_index_t t2;
382 act = (struct xkb_group_action *) action;
383 if (array_ndx != NULL) {
388 return ReportActionNotArray(keymap, action->type, field);
395 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
403 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
410 return ReportIllegal(keymap, action->type, field);
414 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
415 unsigned field, const ExprDef *array_ndx,
416 const ExprDef *value)
418 struct xkb_group_action *act;
420 xkb_group_index_t t2;
422 act = (struct xkb_group_action *) action;
423 if ((array_ndx != NULL) && (field == F_Group))
424 return ReportActionNotArray(keymap, action->type, field);
425 if (field == F_Group) {
427 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
434 return ReportIllegal(keymap, action->type, field);
438 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
439 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
441 struct xkb_pointer_action *act;
444 act = (struct xkb_pointer_action *) action;
445 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
446 return ReportActionNotArray(keymap, action->type, field);
448 if (field == F_X || field == F_Y) {
451 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
456 if (!ExprResolveInteger(keymap->ctx, value, &val))
457 return ReportMismatch(keymap, action->type, field, "integer");
461 act->flags |= XkbSA_MoveAbsoluteX;
466 act->flags |= XkbSA_MoveAbsoluteY;
472 else if (field == F_Accel) {
475 if (!ExprResolveBoolean(keymap->ctx, value, &set))
476 return ReportMismatch(keymap, action->type, field, "boolean");
479 act->flags &= ~XkbSA_NoAcceleration;
481 act->flags |= XkbSA_NoAcceleration;
484 return ReportIllegal(keymap, action->type, field);
487 static const LookupEntry lockWhich[] = {
489 { "lock", XkbSA_LockNoUnlock },
490 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
491 { "unlock", XkbSA_LockNoLock },
496 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
497 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
499 struct xkb_pointer_button_action *act;
501 act = (struct xkb_pointer_button_action *) action;
502 if (field == F_Button) {
506 return ReportActionNotArray(keymap, action->type, field);
508 if (!ExprResolveButton(keymap->ctx, value, &btn))
509 return ReportMismatch(keymap, action->type, field,
510 "integer (range 1..5)");
512 if (btn < 0 || btn > 5) {
514 "Button must specify default or be in the range 1..5; "
515 "Illegal button value %d ignored\n", btn);
522 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
526 return ReportActionNotArray(keymap, action->type, field);
528 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
529 return ReportMismatch(keymap, action->type, field,
532 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
536 else if (field == F_Count) {
540 return ReportActionNotArray(keymap, action->type, field);
542 /* XXX: Should this actually be ResolveButton? */
543 if (!ExprResolveButton(keymap->ctx, value, &btn))
544 return ReportMismatch(keymap, action->type, field, "integer");
546 if (btn < 0 || btn > 255) {
548 "The count field must have a value in the range 0..255; "
549 "Illegal count %d ignored\n", btn);
556 return ReportIllegal(keymap, action->type, field);
559 static const LookupEntry ptrDflts[] = {
560 { "dfltbtn", XkbSA_AffectDfltBtn },
561 { "defaultbutton", XkbSA_AffectDfltBtn },
562 { "button", XkbSA_AffectDfltBtn },
567 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
568 unsigned field, const ExprDef *array_ndx,
569 const ExprDef *value)
571 struct xkb_pointer_default_action *act;
573 act = (struct xkb_pointer_default_action *) action;
574 if (field == F_Affect) {
578 return ReportActionNotArray(keymap, action->type, field);
580 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
581 return ReportMismatch(keymap, action->type, field,
582 "pointer component");
586 else if ((field == F_Button) || (field == F_Value)) {
587 const ExprDef *button;
591 return ReportActionNotArray(keymap, action->type, field);
593 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
594 act->flags &= ~XkbSA_DfltBtnAbsolute;
595 button = value->value.child;
598 act->flags |= XkbSA_DfltBtnAbsolute;
602 if (!ExprResolveButton(keymap->ctx, button, &btn))
603 return ReportMismatch(keymap, action->type, field,
604 "integer (range 1..5)");
606 if (btn < 0 || btn > 5) {
608 "New default button value must be in the range 1..5; "
609 "Illegal default button value %d ignored\n", btn);
614 "Cannot set default pointer button to \"default\"; "
615 "Illegal default button setting ignored\n");
619 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
623 return ReportIllegal(keymap, action->type, field);
626 static const LookupEntry isoNames[] = {
627 { "mods", XkbSA_ISONoAffectMods },
628 { "modifiers", XkbSA_ISONoAffectMods },
629 { "group", XkbSA_ISONoAffectGroup },
630 { "groups", XkbSA_ISONoAffectGroup },
631 { "ptr", XkbSA_ISONoAffectPtr },
632 { "pointer", XkbSA_ISONoAffectPtr },
633 { "ctrls", XkbSA_ISONoAffectCtrls },
634 { "controls", XkbSA_ISONoAffectCtrls },
635 { "all", ~((unsigned) 0) },
641 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
642 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
644 struct xkb_iso_action *act;
646 act = (struct xkb_iso_action *) action;
647 if (field == F_Modifiers) {
652 return ReportActionNotArray(keymap, action->type, field);
655 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
658 act->flags = flags & (~XkbSA_ISODfltIsGroup);
659 act->mods.mods = mods;
662 else if (field == F_Group) {
663 xkb_group_index_t group;
667 return ReportActionNotArray(keymap, action->type, field);
670 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
673 act->flags = flags | XkbSA_ISODfltIsGroup;
676 } else if (F_Affect) {
680 return ReportActionNotArray(keymap, action->type, field);
682 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
683 return ReportMismatch(keymap, action->type, field,
684 "keyboard component");
686 act->affect = (~mask) & XkbSA_ISOAffectMask;
690 return ReportIllegal(keymap, action->type, field);
694 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
695 unsigned field, const ExprDef *array_ndx,
696 const ExprDef *value)
698 struct xkb_switch_screen_action *act;
700 act = (struct xkb_switch_screen_action *) action;
701 if (field == F_Screen) {
706 return ReportActionNotArray(keymap, action->type, field);
708 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
709 act->flags &= ~XkbSA_SwitchAbsolute;
710 scrn = value->value.child;
713 act->flags |= XkbSA_SwitchAbsolute;
717 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
718 return ReportMismatch(keymap, action->type, field,
721 if (val < 0 || val > 255) {
723 "Screen index must be in the range 1..255; "
724 "Illegal screen value %d ignored\n", val);
728 act->screen = (value->op == EXPR_NEGATE ? -val : val);
731 else if (field == F_Same) {
735 return ReportActionNotArray(keymap, action->type, field);
737 if (!ExprResolveBoolean(keymap->ctx, value, &set))
738 return ReportMismatch(keymap, action->type, field, "boolean");
741 act->flags &= ~XkbSA_SwitchApplication;
743 act->flags |= XkbSA_SwitchApplication;
748 return ReportIllegal(keymap, action->type, field);
751 const LookupEntry ctrlNames[] = {
752 { "repeatkeys", XkbRepeatKeysMask },
753 { "repeat", XkbRepeatKeysMask },
754 { "autorepeat", XkbRepeatKeysMask },
755 { "slowkeys", XkbSlowKeysMask },
756 { "bouncekeys", XkbBounceKeysMask },
757 { "stickykeys", XkbStickyKeysMask },
758 { "mousekeys", XkbMouseKeysMask },
759 { "mousekeysaccel", XkbMouseKeysAccelMask },
760 { "accessxkeys", XkbAccessXKeysMask },
761 { "accessxtimeout", XkbAccessXTimeoutMask },
762 { "accessxfeedback", XkbAccessXFeedbackMask },
763 { "audiblebell", XkbAudibleBellMask },
764 { "ignoregrouplock", XkbIgnoreGroupLockMask },
765 { "all", XkbAllBooleanCtrlsMask },
773 HandleSetLockControls(struct xkb_keymap *keymap,
774 struct xkb_any_action *action,
775 unsigned field, const ExprDef *array_ndx,
776 const ExprDef *value)
778 struct xkb_controls_action *act;
780 act = (struct xkb_controls_action *) action;
781 if (field == F_Controls) {
785 return ReportActionNotArray(keymap, action->type, field);
787 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
788 return ReportMismatch(keymap, action->type, field,
795 return ReportIllegal(keymap, action->type, field);
798 static const LookupEntry evNames[] = {
799 { "press", XkbSA_MessageOnPress },
800 { "keypress", XkbSA_MessageOnPress },
801 { "release", XkbSA_MessageOnRelease },
802 { "keyrelease", XkbSA_MessageOnRelease },
803 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
809 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
810 unsigned field, const ExprDef *array_ndx,
811 const ExprDef *value)
813 struct xkb_message_action *act;
815 act = (struct xkb_message_action *) action;
816 if (field == F_Report) {
820 return ReportActionNotArray(keymap, action->type, field);
822 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
823 return ReportMismatch(keymap, action->type, field,
826 /* FIXME: Something seems wrong here... */
827 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
828 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
831 else if (field == F_GenKeyEvent) {
835 return ReportActionNotArray(keymap, action->type, field);
837 if (!ExprResolveBoolean(keymap->ctx, value, &set))
838 return ReportMismatch(keymap, action->type, field, "boolean");
841 act->flags |= XkbSA_MessageGenKeyEvent;
843 act->flags &= ~XkbSA_MessageGenKeyEvent;
847 else if (field == F_Data && !array_ndx) {
851 if (!ExprResolveString(keymap->ctx, value, &str))
852 return ReportMismatch(keymap, action->type, field, "string");
855 if (len < 1 || len > 6) {
856 log_warn(keymap->ctx,
857 "An action message can hold only 6 bytes; "
858 "Extra %d bytes ignored\n", len - 6);
861 strncpy((char *) act->message, str, 6);
864 else if (field == F_Data && array_ndx) {
867 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
869 "Array subscript must be integer; "
870 "Illegal subscript ignored\n");
874 if (ndx < 0 || ndx > 5) {
876 "An action message is at most 6 bytes long; "
877 "Attempt to use data[%d] ignored\n", ndx);
881 if (!ExprResolveInteger(keymap->ctx, value, &datum))
882 return ReportMismatch(keymap, action->type, field, "integer");
884 if (datum < 0 || datum > 255) {
886 "Message data must be in the range 0..255; "
887 "Illegal datum %d ignored\n", datum);
891 act->message[ndx] = (uint8_t) datum;
895 return ReportIllegal(keymap, action->type, field);
899 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
900 unsigned field, const ExprDef *array_ndx,
901 const ExprDef *value)
904 struct xkb_redirect_key_action *act;
908 char key_name[XkbKeyNameLength];
910 if (array_ndx != NULL)
911 return ReportActionNotArray(keymap, action->type, field);
913 act = (struct xkb_redirect_key_action *) action;
916 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
917 return ReportMismatch(keymap, action->type, field, "key name");
919 tmp = KeyNameToLong(key_name);
920 key = FindNamedKey(keymap, tmp, true, 0);
922 return ReportNotFound(keymap, action->type, field, "Key",
923 KeyNameText(key_name));
924 act->new_kc = XkbKeyGetKeycode(keymap, key);
930 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
931 act->mods_mask |= (t2 & 0xff);
932 if (field == F_Modifiers)
933 act->mods |= (t2 & 0xff);
935 act->mods &= ~(t2 & 0xff);
937 t2 = (t2 >> XkbNumModifiers) & 0xffff;
938 act->vmods_mask |= t2;
939 if (field == F_Modifiers)
947 return ReportIllegal(keymap, action->type, field);
951 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
952 unsigned field, const ExprDef *array_ndx,
953 const ExprDef *value)
955 struct xkb_device_button_action *act;
957 act = (struct xkb_device_button_action *) action;
958 if (field == F_Button) {
962 return ReportActionNotArray(keymap, action->type, field);
964 if (!ExprResolveInteger(keymap->ctx, value, &val))
965 return ReportMismatch(keymap, action->type, field,
966 "integer (range 1..255)");
968 if (val < 0 || val > 255) {
970 "Button must specify default or be in the range 1..255; "
971 "Illegal button value %d ignored\n", val);
978 else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
982 return ReportActionNotArray(keymap, action->type, field);
984 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
985 return ReportMismatch(keymap, action->type, field,
988 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
992 else if (field == F_Count) {
996 return ReportActionNotArray(keymap, action->type, field);
998 /* XXX: Should this actually be ResolveButton? */
999 if (!ExprResolveButton(keymap->ctx, value, &btn))
1000 return ReportMismatch(keymap, action->type, field, "integer");
1002 if (btn < 0 || btn > 255) {
1003 log_err(keymap->ctx,
1004 "The count field must have a value in the range 0..255; "
1005 "Illegal count %d ignored\n", btn);
1012 else if (field == F_Device) {
1016 return ReportActionNotArray(keymap, action->type, field);
1018 if (!ExprResolveInteger(keymap->ctx, value, &val))
1019 return ReportMismatch(keymap, action->type, field,
1020 "integer (range 1..255)");
1022 if (val < 0 || val > 255) {
1023 log_err(keymap->ctx,
1024 "Device must specify default or be in the range 1..255; "
1025 "Illegal device value %d ignored\n", val);
1033 return ReportIllegal(keymap, action->type, field);
1037 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
1038 unsigned field, const ExprDef *array_ndx,
1039 const ExprDef *value)
1043 struct xkb_device_valuator_action *act;
1045 act = (struct xkb_device_valuator_action *) action;
1046 /* XXX - Not yet implemented */
1052 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
1053 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
1055 if (field == F_Type) {
1058 if (!ExprResolveInteger(keymap->ctx, value, &type))
1059 return ReportMismatch(keymap, PrivateAction, field, "integer");
1061 if (type < 0 || type > 255) {
1062 log_err(keymap->ctx,
1063 "Private action type must be in the range 0..255; "
1064 "Illegal type %d ignored\n", type);
1068 action->type = (uint8_t) type;
1071 else if (field == F_Data) {
1072 if (array_ndx == NULL) {
1076 if (!ExprResolveString(keymap->ctx, value, &str))
1077 return ReportMismatch(keymap, action->type, field, "string");
1080 if (len < 1 || len > 7) {
1081 log_warn(keymap->ctx,
1082 "A private action has 7 data bytes; "
1083 "Extra %d bytes ignored\n", len - 6);
1087 strncpy((char *) action->data, str, sizeof(action->data));
1093 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1094 log_err(keymap->ctx,
1095 "Array subscript must be integer; "
1096 "Illegal subscript ignored\n");
1100 if (ndx < 0 || ndx >= sizeof(action->data)) {
1101 log_err(keymap->ctx,
1102 "The data for a private action is %zu bytes long; "
1103 "Attempt to use data[%d] ignored\n",
1104 sizeof(action->data), ndx);
1108 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1109 return ReportMismatch(keymap, action->type, field, "integer");
1111 if (datum < 0 || datum > 255) {
1112 log_err(keymap->ctx,
1113 "All data for a private action must be 0..255; "
1114 "Illegal datum %d ignored\n", datum);
1118 action->data[ndx] = (uint8_t) datum;
1123 return ReportIllegal(keymap, PrivateAction, field);
1126 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1127 struct xkb_any_action *action, unsigned field,
1128 const ExprDef *array_ndx, const ExprDef *value);
1130 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1131 [XkbSA_NoAction] = HandleNoAction,
1132 [XkbSA_SetMods] = HandleSetLatchMods,
1133 [XkbSA_LatchMods] = HandleSetLatchMods,
1134 [XkbSA_LockMods] = HandleLockMods,
1135 [XkbSA_SetGroup] = HandleSetLatchGroup,
1136 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1137 [XkbSA_LockGroup] = HandleLockGroup,
1138 [XkbSA_MovePtr] = HandleMovePtr,
1139 [XkbSA_PtrBtn] = HandlePtrBtn,
1140 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1141 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1142 [XkbSA_ISOLock] = HandleISOLock,
1143 [XkbSA_Terminate] = HandleNoAction,
1144 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1145 [XkbSA_SetControls] = HandleSetLockControls,
1146 [XkbSA_LockControls] = HandleSetLockControls,
1147 [XkbSA_ActionMessage] = HandleActionMessage,
1148 [XkbSA_RedirectKey] = HandleRedirectKey,
1149 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1150 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1151 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1152 [PrivateAction] = HandlePrivate,
1155 /***====================================================================***/
1158 ApplyActionFactoryDefaults(union xkb_action * action)
1160 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1161 action->dflt.affect = XkbSA_AffectDfltBtn;
1162 action->dflt.flags = 0;
1163 action->dflt.value = 1;
1165 else if (action->type == XkbSA_ISOLock) {
1166 action->iso.mods.mods = (1 << ModNameToIndex(XKB_MOD_NAME_CAPS));
1171 HandleActionDef(ExprDef * def,
1172 struct xkb_keymap *keymap,
1173 struct xkb_any_action *action, ActionInfo *info)
1177 unsigned tmp, hndlrType;
1179 if (def->op != EXPR_ACTION_DECL) {
1180 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1181 exprOpText(def->op));
1184 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1186 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1189 if (!stringToAction(str, &tmp)) {
1190 log_err(keymap->ctx, "Unknown action %s\n", str);
1193 action->type = hndlrType = tmp;
1194 if (action->type != XkbSA_NoAction) {
1195 ApplyActionFactoryDefaults((union xkb_action *) action);
1198 if ((info->action == XkbSA_NoAction)
1199 || (info->action == hndlrType)) {
1200 if (!(*handleAction[hndlrType])(keymap, action,
1210 for (arg = def->value.action.args; arg != NULL;
1211 arg = (ExprDef *) arg->common.next) {
1212 const ExprDef *value;
1213 ExprDef *field, *arrayRtrn;
1214 const char *elemRtrn, *fieldRtrn;
1217 if (arg->op == EXPR_ASSIGN) {
1218 field = arg->value.binary.left;
1219 value = arg->value.binary.right;
1222 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1223 field = arg->value.child;
1224 value = &constFalse;
1231 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1233 return false; /* internal error -- already reported */
1235 if (elemRtrn != NULL) {
1236 log_err(keymap->ctx,
1237 "Cannot change defaults in an action definition; "
1238 "Ignoring attempt to change %s.%s\n",
1239 elemRtrn, fieldRtrn);
1242 if (!stringToField(fieldRtrn, &fieldNdx)) {
1243 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1246 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1253 /***====================================================================***/
1256 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1257 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1259 ActionInfo *new, *old;
1261 new = malloc(sizeof(*new));
1263 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1267 if (istreq(elem, "action"))
1268 new->action = XkbSA_NoAction;
1270 if (!stringToAction(elem, &new->action)) {
1274 if (new->action == XkbSA_NoAction) {
1275 log_err(keymap->ctx,
1276 "\"%s\" is not a valid field in a NoAction action\n",
1282 if (!stringToField(field, &new->field)) {
1283 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1287 new->array_ndx = array_ndx;
1291 while ((old) && (old->next))