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 ********************************************************/
27 #include "xkbcomp-priv.h"
33 static const ExprDef constTrue = {
34 .common = { .type = STMT_EXPR, .next = NULL },
36 .value_type = EXPR_TYPE_BOOLEAN,
37 .value = { .ival = 1 },
40 static const ExprDef constFalse = {
41 .common = { .type = STMT_EXPR, .next = NULL },
43 .value_type = EXPR_TYPE_BOOLEAN,
44 .value = { .ival = 0 },
47 /***====================================================================***/
49 static const LookupEntry actionStrings[] = {
50 { "noaction", XkbSA_NoAction },
51 { "setmods", XkbSA_SetMods },
52 { "latchmods", XkbSA_LatchMods },
53 { "lockmods", XkbSA_LockMods },
54 { "setgroup", XkbSA_SetGroup },
55 { "latchgroup", XkbSA_LatchGroup },
56 { "lockgroup", XkbSA_LockGroup },
57 { "moveptr", XkbSA_MovePtr },
58 { "movepointer", XkbSA_MovePtr },
59 { "ptrbtn", XkbSA_PtrBtn },
60 { "pointerbutton", XkbSA_PtrBtn },
61 { "lockptrbtn", XkbSA_LockPtrBtn },
62 { "lockpointerbutton", XkbSA_LockPtrBtn },
63 { "lockptrbutton", XkbSA_LockPtrBtn },
64 { "lockpointerbtn", XkbSA_LockPtrBtn },
65 { "setptrdflt", XkbSA_SetPtrDflt },
66 { "setpointerdefault", XkbSA_SetPtrDflt },
67 { "isolock", XkbSA_ISOLock },
68 { "terminate", XkbSA_Terminate },
69 { "terminateserver", XkbSA_Terminate },
70 { "switchscreen", XkbSA_SwitchScreen },
71 { "setcontrols", XkbSA_SetControls },
72 { "lockcontrols", XkbSA_LockControls },
73 { "actionmessage", XkbSA_ActionMessage },
74 { "messageaction", XkbSA_ActionMessage },
75 { "message", XkbSA_ActionMessage },
76 { "redirect", XkbSA_RedirectKey },
77 { "redirectkey", XkbSA_RedirectKey },
78 { "devbtn", XkbSA_DeviceBtn },
79 { "devicebtn", XkbSA_DeviceBtn },
80 { "devbutton", XkbSA_DeviceBtn },
81 { "devicebutton", XkbSA_DeviceBtn },
82 { "lockdevbtn", XkbSA_DeviceBtn },
83 { "lockdevicebtn", XkbSA_LockDeviceBtn },
84 { "lockdevbutton", XkbSA_LockDeviceBtn },
85 { "lockdevicebutton", XkbSA_LockDeviceBtn },
86 { "devval", XkbSA_DeviceValuator },
87 { "deviceval", XkbSA_DeviceValuator },
88 { "devvaluator", XkbSA_DeviceValuator },
89 { "devicevaluator", XkbSA_DeviceValuator },
90 { "private", PrivateAction },
94 static const LookupEntry fieldStrings[] = {
95 { "clearLocks", F_ClearLocks },
96 { "latchToLock", F_LatchToLock },
97 { "genKeyEvent", F_GenKeyEvent },
98 { "generateKeyEvent", F_GenKeyEvent },
99 { "report", F_Report },
100 { "default", F_Default },
101 { "affect", F_Affect },
102 { "increment", F_Increment },
103 { "modifiers", F_Modifiers },
104 { "mods", F_Modifiers },
105 { "group", F_Group },
108 { "accel", F_Accel },
109 { "accelerate", F_Accel },
110 { "repeat", F_Accel },
111 { "button", F_Button },
112 { "value", F_Value },
113 { "controls", F_Controls },
114 { "ctrls", F_Controls },
116 { "count", F_Count },
117 { "screen", F_Screen },
119 { "sameServer", F_Same },
121 { "device", F_Device },
123 { "key", F_Keycode },
124 { "keycode", F_Keycode },
126 { "clearmods", F_ModsToClear },
127 { "clearmodifiers", F_ModsToClear },
132 stringToValue(const LookupEntry tab[], const char *string,
133 unsigned int *value_rtrn)
135 const LookupEntry *entry;
140 for (entry = tab; entry->name; entry++) {
141 if (istreq(entry->name, string)) {
142 *value_rtrn = entry->value;
151 valueToString(const LookupEntry tab[], unsigned int value)
153 const LookupEntry *entry;
155 for (entry = tab; entry->name; entry++)
156 if (entry->value == value)
163 stringToAction(const char *str, unsigned *type_rtrn)
165 return stringToValue(actionStrings, str, type_rtrn);
169 stringToField(const char *str, unsigned *field_rtrn)
171 return stringToValue(fieldStrings, str, field_rtrn);
175 fieldText(unsigned field)
177 return valueToString(fieldStrings, field);
180 /***====================================================================***/
183 ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
187 "Value of %s field must be of type %s; "
188 "Action %s definition ignored\n",
189 fieldText(field), type, ActionTypeText(action));
194 ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
197 "Field %s is not defined for an action of type %s; "
198 "Action definition ignored\n",
199 fieldText(field), ActionTypeText(action));
204 ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
208 "The %s field in the %s action is not an array; "
209 "Action definition ignored\n",
210 fieldText(field), ActionTypeText(action));
215 ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
216 const char *what, const char *bad)
219 "%s named %s not found; "
220 "Ignoring the %s field of an %s action\n",
221 what, bad, fieldText(field), ActionTypeText(action));
226 HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
227 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
230 return ReportIllegal(keymap, action->type, field);
234 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
235 unsigned field, const ExprDef * value,
236 unsigned *flags_inout)
241 if (field == F_ClearLocks)
242 tmp = XkbSA_ClearLocks;
243 else if (field == F_LatchToLock)
244 tmp = XkbSA_LatchToLock;
246 return false; /* WSGO! */
248 if (!ExprResolveBoolean(keymap->ctx, value, &result))
249 return ReportMismatch(keymap, action, field, "boolean");
254 *flags_inout &= ~tmp;
260 CheckModifierField(struct xkb_keymap *keymap, unsigned action,
261 const ExprDef *value, unsigned *flags_inout,
262 xkb_mod_mask_t *mods_rtrn)
264 if (value->op == EXPR_IDENT) {
266 valStr = xkb_atom_text(keymap->ctx, value->value.str);
267 if (valStr && (istreq(valStr, "usemodmapmods") ||
268 istreq(valStr, "modmapmods"))) {
271 *flags_inout |= XkbSA_UseModMapMods;
276 if (!ExprResolveVModMask(keymap, value, mods_rtrn))
277 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
279 *flags_inout &= ~XkbSA_UseModMapMods;
284 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
285 unsigned field, const ExprDef *array_ndx,
286 const ExprDef *value)
288 struct xkb_mod_action *act = &action->mods;
293 if (array_ndx != NULL) {
298 return ReportActionNotArray(keymap, action->type, field);
305 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
313 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
320 return ReportIllegal(keymap, action->type, field);
324 HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
325 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
327 struct xkb_mod_action *act = &action->mods;
331 if ((array_ndx != NULL) && (field == F_Modifiers))
332 return ReportActionNotArray(keymap, action->type, field);
336 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
343 return ReportIllegal(keymap, action->type, field);
347 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
348 const ExprDef *value, unsigned *flags_inout,
349 xkb_group_index_t *grp_rtrn)
353 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
354 *flags_inout &= ~XkbSA_GroupAbsolute;
355 spec = value->value.child;
358 *flags_inout |= XkbSA_GroupAbsolute;
362 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
363 return ReportMismatch(keymap, action, F_Group,
364 "integer (range 1..8)");
366 if (value->op == EXPR_NEGATE)
367 *grp_rtrn = -*grp_rtrn;
368 else if (value->op != EXPR_UNARY_PLUS)
375 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
376 unsigned field, const ExprDef *array_ndx,
377 const ExprDef *value)
379 struct xkb_group_action *act = &action->group;
382 xkb_group_index_t t2;
384 if (array_ndx != NULL) {
389 return ReportActionNotArray(keymap, action->type, field);
396 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
404 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
411 return ReportIllegal(keymap, action->type, field);
415 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
416 unsigned field, const ExprDef *array_ndx,
417 const ExprDef *value)
419 struct xkb_group_action *act = &action->group;
421 xkb_group_index_t t2;
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, union xkb_action *action,
439 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
441 struct xkb_pointer_action *act = &action->ptr;
444 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
445 return ReportActionNotArray(keymap, action->type, field);
447 if (field == F_X || field == F_Y) {
450 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
455 if (!ExprResolveInteger(keymap->ctx, value, &val))
456 return ReportMismatch(keymap, action->type, field, "integer");
460 act->flags |= XkbSA_MoveAbsoluteX;
465 act->flags |= XkbSA_MoveAbsoluteY;
471 else if (field == F_Accel) {
474 if (!ExprResolveBoolean(keymap->ctx, value, &set))
475 return ReportMismatch(keymap, action->type, field, "boolean");
478 act->flags &= ~XkbSA_NoAcceleration;
480 act->flags |= XkbSA_NoAcceleration;
483 return ReportIllegal(keymap, action->type, field);
486 static const LookupEntry lockWhich[] = {
488 { "lock", XkbSA_LockNoUnlock },
489 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
490 { "unlock", XkbSA_LockNoLock },
495 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
496 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
498 struct xkb_pointer_button_action *act = &action->btn;
500 if (field == F_Button) {
504 return ReportActionNotArray(keymap, action->type, field);
506 if (!ExprResolveButton(keymap->ctx, value, &btn))
507 return ReportMismatch(keymap, action->type, field,
508 "integer (range 1..5)");
510 if (btn < 0 || btn > 5) {
512 "Button must specify default or be in the range 1..5; "
513 "Illegal button value %d ignored\n", btn);
520 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
524 return ReportActionNotArray(keymap, action->type, field);
526 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
527 return ReportMismatch(keymap, action->type, field,
530 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
534 else if (field == F_Count) {
538 return ReportActionNotArray(keymap, action->type, field);
540 /* XXX: Should this actually be ResolveButton? */
541 if (!ExprResolveButton(keymap->ctx, value, &btn))
542 return ReportMismatch(keymap, action->type, field, "integer");
544 if (btn < 0 || btn > 255) {
546 "The count field must have a value in the range 0..255; "
547 "Illegal count %d ignored\n", btn);
554 return ReportIllegal(keymap, action->type, field);
557 static const LookupEntry ptrDflts[] = {
558 { "dfltbtn", XkbSA_AffectDfltBtn },
559 { "defaultbutton", XkbSA_AffectDfltBtn },
560 { "button", XkbSA_AffectDfltBtn },
565 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
566 unsigned field, const ExprDef *array_ndx,
567 const ExprDef *value)
569 struct xkb_pointer_default_action *act = &action->dflt;
571 if (field == F_Affect) {
575 return ReportActionNotArray(keymap, action->type, field);
577 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
578 return ReportMismatch(keymap, action->type, field,
579 "pointer component");
583 else if ((field == F_Button) || (field == F_Value)) {
584 const ExprDef *button;
588 return ReportActionNotArray(keymap, action->type, field);
590 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
591 act->flags &= ~XkbSA_DfltBtnAbsolute;
592 button = value->value.child;
595 act->flags |= XkbSA_DfltBtnAbsolute;
599 if (!ExprResolveButton(keymap->ctx, button, &btn))
600 return ReportMismatch(keymap, action->type, field,
601 "integer (range 1..5)");
603 if (btn < 0 || btn > 5) {
605 "New default button value must be in the range 1..5; "
606 "Illegal default button value %d ignored\n", btn);
611 "Cannot set default pointer button to \"default\"; "
612 "Illegal default button setting ignored\n");
616 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
620 return ReportIllegal(keymap, action->type, field);
623 static const LookupEntry isoNames[] = {
624 { "mods", XkbSA_ISONoAffectMods },
625 { "modifiers", XkbSA_ISONoAffectMods },
626 { "group", XkbSA_ISONoAffectGroup },
627 { "groups", XkbSA_ISONoAffectGroup },
628 { "ptr", XkbSA_ISONoAffectPtr },
629 { "pointer", XkbSA_ISONoAffectPtr },
630 { "ctrls", XkbSA_ISONoAffectCtrls },
631 { "controls", XkbSA_ISONoAffectCtrls },
632 { "all", ~((unsigned) 0) },
638 HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
639 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
641 struct xkb_iso_action *act = &action->iso;
643 if (field == F_Modifiers) {
648 return ReportActionNotArray(keymap, action->type, field);
651 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
654 act->flags = flags & (~XkbSA_ISODfltIsGroup);
655 act->mods.mods = mods;
658 else if (field == F_Group) {
659 xkb_group_index_t group;
663 return ReportActionNotArray(keymap, action->type, field);
666 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
669 act->flags = flags | XkbSA_ISODfltIsGroup;
672 } else if (F_Affect) {
676 return ReportActionNotArray(keymap, action->type, field);
678 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
679 return ReportMismatch(keymap, action->type, field,
680 "keyboard component");
682 act->affect = (~mask) & XkbSA_ISOAffectMask;
686 return ReportIllegal(keymap, action->type, field);
690 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
691 unsigned field, const ExprDef *array_ndx,
692 const ExprDef *value)
694 struct xkb_switch_screen_action *act = &action->screen;
696 if (field == F_Screen) {
701 return ReportActionNotArray(keymap, action->type, field);
703 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
704 act->flags &= ~XkbSA_SwitchAbsolute;
705 scrn = value->value.child;
708 act->flags |= XkbSA_SwitchAbsolute;
712 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
713 return ReportMismatch(keymap, action->type, field,
716 if (val < 0 || val > 255) {
718 "Screen index must be in the range 1..255; "
719 "Illegal screen value %d ignored\n", val);
723 act->screen = (value->op == EXPR_NEGATE ? -val : val);
726 else if (field == F_Same) {
730 return ReportActionNotArray(keymap, action->type, field);
732 if (!ExprResolveBoolean(keymap->ctx, value, &set))
733 return ReportMismatch(keymap, action->type, field, "boolean");
736 act->flags &= ~XkbSA_SwitchApplication;
738 act->flags |= XkbSA_SwitchApplication;
743 return ReportIllegal(keymap, action->type, field);
746 const LookupEntry ctrlNames[] = {
747 { "repeatkeys", XkbRepeatKeysMask },
748 { "repeat", XkbRepeatKeysMask },
749 { "autorepeat", XkbRepeatKeysMask },
750 { "slowkeys", XkbSlowKeysMask },
751 { "bouncekeys", XkbBounceKeysMask },
752 { "stickykeys", XkbStickyKeysMask },
753 { "mousekeys", XkbMouseKeysMask },
754 { "mousekeysaccel", XkbMouseKeysAccelMask },
755 { "accessxkeys", XkbAccessXKeysMask },
756 { "accessxtimeout", XkbAccessXTimeoutMask },
757 { "accessxfeedback", XkbAccessXFeedbackMask },
758 { "audiblebell", XkbAudibleBellMask },
759 { "ignoregrouplock", XkbIgnoreGroupLockMask },
760 { "all", XkbAllBooleanCtrlsMask },
768 HandleSetLockControls(struct xkb_keymap *keymap,
769 union xkb_action *action,
770 unsigned field, const ExprDef *array_ndx,
771 const ExprDef *value)
773 struct xkb_controls_action *act = &action->ctrls;
775 if (field == F_Controls) {
779 return ReportActionNotArray(keymap, action->type, field);
781 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
782 return ReportMismatch(keymap, action->type, field,
789 return ReportIllegal(keymap, action->type, field);
792 static const LookupEntry evNames[] = {
793 { "press", XkbSA_MessageOnPress },
794 { "keypress", XkbSA_MessageOnPress },
795 { "release", XkbSA_MessageOnRelease },
796 { "keyrelease", XkbSA_MessageOnRelease },
797 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
803 HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
804 unsigned field, const ExprDef *array_ndx,
805 const ExprDef *value)
807 struct xkb_message_action *act = &action->msg;
809 if (field == F_Report) {
813 return ReportActionNotArray(keymap, action->type, field);
815 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
816 return ReportMismatch(keymap, action->type, field,
819 /* FIXME: Something seems wrong here... */
820 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
821 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
824 else if (field == F_GenKeyEvent) {
828 return ReportActionNotArray(keymap, action->type, field);
830 if (!ExprResolveBoolean(keymap->ctx, value, &set))
831 return ReportMismatch(keymap, action->type, field, "boolean");
834 act->flags |= XkbSA_MessageGenKeyEvent;
836 act->flags &= ~XkbSA_MessageGenKeyEvent;
840 else if (field == F_Data && !array_ndx) {
844 if (!ExprResolveString(keymap->ctx, value, &str))
845 return ReportMismatch(keymap, action->type, field, "string");
848 if (len < 1 || len > 6) {
849 log_warn(keymap->ctx,
850 "An action message can hold only 6 bytes; "
851 "Extra %d bytes ignored\n", len - 6);
854 strncpy((char *) act->message, str, 6);
857 else if (field == F_Data && array_ndx) {
860 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
862 "Array subscript must be integer; "
863 "Illegal subscript ignored\n");
867 if (ndx < 0 || ndx > 5) {
869 "An action message is at most 6 bytes long; "
870 "Attempt to use data[%d] ignored\n", ndx);
874 if (!ExprResolveInteger(keymap->ctx, value, &datum))
875 return ReportMismatch(keymap, action->type, field, "integer");
877 if (datum < 0 || datum > 255) {
879 "Message data must be in the range 0..255; "
880 "Illegal datum %d ignored\n", datum);
884 act->message[ndx] = (uint8_t) datum;
888 return ReportIllegal(keymap, action->type, field);
892 HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
893 unsigned field, const ExprDef *array_ndx,
894 const ExprDef *value)
897 struct xkb_redirect_key_action *act = &action->redirect;
901 char key_name[XkbKeyNameLength];
903 if (array_ndx != NULL)
904 return ReportActionNotArray(keymap, action->type, field);
908 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
909 return ReportMismatch(keymap, action->type, field, "key name");
911 tmp = KeyNameToLong(key_name);
912 key = FindNamedKey(keymap, tmp, true, 0);
914 return ReportNotFound(keymap, action->type, field, "Key",
915 KeyNameText(key_name));
916 act->new_kc = XkbKeyGetKeycode(keymap, key);
922 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
923 act->mods_mask |= (t2 & 0xff);
924 if (field == F_Modifiers)
925 act->mods |= (t2 & 0xff);
927 act->mods &= ~(t2 & 0xff);
929 t2 = (t2 >> XkbNumModifiers) & 0xffff;
930 act->vmods_mask |= t2;
931 if (field == F_Modifiers)
939 return ReportIllegal(keymap, action->type, field);
943 HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
944 unsigned field, const ExprDef *array_ndx,
945 const ExprDef *value)
947 struct xkb_device_button_action *act = &action->devbtn;
949 if (field == F_Button) {
953 return ReportActionNotArray(keymap, action->type, field);
955 if (!ExprResolveInteger(keymap->ctx, value, &val))
956 return ReportMismatch(keymap, action->type, field,
957 "integer (range 1..255)");
959 if (val < 0 || val > 255) {
961 "Button must specify default or be in the range 1..255; "
962 "Illegal button value %d ignored\n", val);
969 else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
973 return ReportActionNotArray(keymap, action->type, field);
975 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
976 return ReportMismatch(keymap, action->type, field,
979 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
983 else if (field == F_Count) {
987 return ReportActionNotArray(keymap, action->type, field);
989 /* XXX: Should this actually be ResolveButton? */
990 if (!ExprResolveButton(keymap->ctx, value, &btn))
991 return ReportMismatch(keymap, action->type, field, "integer");
993 if (btn < 0 || btn > 255) {
995 "The count field must have a value in the range 0..255; "
996 "Illegal count %d ignored\n", btn);
1003 else if (field == F_Device) {
1007 return ReportActionNotArray(keymap, action->type, field);
1009 if (!ExprResolveInteger(keymap->ctx, value, &val))
1010 return ReportMismatch(keymap, action->type, field,
1011 "integer (range 1..255)");
1013 if (val < 0 || val > 255) {
1014 log_err(keymap->ctx,
1015 "Device must specify default or be in the range 1..255; "
1016 "Illegal device value %d ignored\n", val);
1024 return ReportIllegal(keymap, action->type, field);
1028 HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
1029 unsigned field, const ExprDef *array_ndx,
1030 const ExprDef *value)
1032 struct xkb_device_valuator_action *act = &action->devval;
1035 /* XXX - Not yet implemented */
1040 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
1041 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
1043 struct xkb_private_action *act = &action->priv;
1045 if (field == F_Type) {
1048 if (!ExprResolveInteger(keymap->ctx, value, &type))
1049 return ReportMismatch(keymap, PrivateAction, field, "integer");
1051 if (type < 0 || type > 255) {
1052 log_err(keymap->ctx,
1053 "Private action type must be in the range 0..255; "
1054 "Illegal type %d ignored\n", type);
1058 act->type = (uint8_t) type;
1061 else if (field == F_Data) {
1062 if (array_ndx == NULL) {
1066 if (!ExprResolveString(keymap->ctx, value, &str))
1067 return ReportMismatch(keymap, action->type, field, "string");
1070 if (len < 1 || len > 7) {
1071 log_warn(keymap->ctx,
1072 "A private action has 7 data bytes; "
1073 "Extra %d bytes ignored\n", len - 6);
1077 strncpy((char *) act->data, str, sizeof(act->data));
1083 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1084 log_err(keymap->ctx,
1085 "Array subscript must be integer; "
1086 "Illegal subscript ignored\n");
1090 if (ndx < 0 || ndx >= sizeof(act->data)) {
1091 log_err(keymap->ctx,
1092 "The data for a private action is %zu bytes long; "
1093 "Attempt to use data[%d] ignored\n",
1094 sizeof(act->data), ndx);
1098 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1099 return ReportMismatch(keymap, act->type, field, "integer");
1101 if (datum < 0 || datum > 255) {
1102 log_err(keymap->ctx,
1103 "All data for a private action must be 0..255; "
1104 "Illegal datum %d ignored\n", datum);
1108 act->data[ndx] = (uint8_t) datum;
1113 return ReportIllegal(keymap, PrivateAction, field);
1116 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1117 union xkb_action *action, unsigned field,
1118 const ExprDef *array_ndx, const ExprDef *value);
1120 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1121 [XkbSA_NoAction] = HandleNoAction,
1122 [XkbSA_SetMods] = HandleSetLatchMods,
1123 [XkbSA_LatchMods] = HandleSetLatchMods,
1124 [XkbSA_LockMods] = HandleLockMods,
1125 [XkbSA_SetGroup] = HandleSetLatchGroup,
1126 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1127 [XkbSA_LockGroup] = HandleLockGroup,
1128 [XkbSA_MovePtr] = HandleMovePtr,
1129 [XkbSA_PtrBtn] = HandlePtrBtn,
1130 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1131 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1132 [XkbSA_ISOLock] = HandleISOLock,
1133 [XkbSA_Terminate] = HandleNoAction,
1134 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1135 [XkbSA_SetControls] = HandleSetLockControls,
1136 [XkbSA_LockControls] = HandleSetLockControls,
1137 [XkbSA_ActionMessage] = HandleActionMessage,
1138 [XkbSA_RedirectKey] = HandleRedirectKey,
1139 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1140 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1141 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1142 [PrivateAction] = HandlePrivate,
1145 /***====================================================================***/
1148 ApplyActionFactoryDefaults(union xkb_action * action)
1150 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1151 action->dflt.affect = XkbSA_AffectDfltBtn;
1152 action->dflt.flags = 0;
1153 action->dflt.value = 1;
1155 else if (action->type == XkbSA_ISOLock) {
1156 action->iso.mods.mods = (1 << ModNameToIndex(XKB_MOD_NAME_CAPS));
1161 HandleActionDef(ExprDef * def,
1162 struct xkb_keymap *keymap,
1163 union xkb_action *action, ActionInfo *info)
1167 unsigned tmp, hndlrType;
1169 if (def->op != EXPR_ACTION_DECL) {
1170 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1171 exprOpText(def->op));
1174 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1176 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1179 if (!stringToAction(str, &tmp)) {
1180 log_err(keymap->ctx, "Unknown action %s\n", str);
1183 action->type = hndlrType = tmp;
1184 if (action->type != XkbSA_NoAction) {
1185 ApplyActionFactoryDefaults((union xkb_action *) action);
1188 if ((info->action == XkbSA_NoAction)
1189 || (info->action == hndlrType)) {
1190 if (!(*handleAction[hndlrType])(keymap, action,
1200 for (arg = def->value.action.args; arg != NULL;
1201 arg = (ExprDef *) arg->common.next) {
1202 const ExprDef *value;
1203 ExprDef *field, *arrayRtrn;
1204 const char *elemRtrn, *fieldRtrn;
1207 if (arg->op == EXPR_ASSIGN) {
1208 field = arg->value.binary.left;
1209 value = arg->value.binary.right;
1212 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1213 field = arg->value.child;
1214 value = &constFalse;
1221 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1223 return false; /* internal error -- already reported */
1225 if (elemRtrn != NULL) {
1226 log_err(keymap->ctx,
1227 "Cannot change defaults in an action definition; "
1228 "Ignoring attempt to change %s.%s\n",
1229 elemRtrn, fieldRtrn);
1232 if (!stringToField(fieldRtrn, &fieldNdx)) {
1233 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1236 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1243 /***====================================================================***/
1246 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1247 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1249 ActionInfo *new, *old;
1251 new = malloc(sizeof(*new));
1253 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1257 if (istreq(elem, "action"))
1258 new->action = XkbSA_NoAction;
1260 if (!stringToAction(elem, &new->action)) {
1264 if (new->action == XkbSA_NoAction) {
1265 log_err(keymap->ctx,
1266 "\"%s\" is not a valid field in a NoAction action\n",
1272 if (!stringToField(field, &new->field)) {
1273 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1277 new->array_ndx = array_ndx;
1281 while ((old) && (old->next))