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)) {
312 act->real_mods = act->mask = (t2 & 0xff);
313 act->vmods = (t2 >> 8) & 0xffff;
318 return ReportIllegal(keymap, action->type, field);
322 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
323 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
325 struct xkb_mod_action *act;
329 act = (struct xkb_mod_action *) action;
330 if ((array_ndx != NULL) && (field == F_Modifiers))
331 return ReportActionNotArray(keymap, action->type, field);
335 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
337 act->real_mods = act->mask = (t2 & 0xff);
338 act->vmods = (t2 >> 8) & 0xffff;
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, struct xkb_any_action *action,
376 unsigned field, const ExprDef *array_ndx,
377 const ExprDef *value)
379 struct xkb_group_action *act;
382 xkb_group_index_t t2;
384 act = (struct xkb_group_action *) action;
385 if (array_ndx != NULL) {
390 return ReportActionNotArray(keymap, action->type, field);
397 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
405 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
412 return ReportIllegal(keymap, action->type, field);
416 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
417 unsigned field, const ExprDef *array_ndx,
418 const ExprDef *value)
420 struct xkb_group_action *act;
422 xkb_group_index_t t2;
424 act = (struct xkb_group_action *) action;
425 if ((array_ndx != NULL) && (field == F_Group))
426 return ReportActionNotArray(keymap, action->type, field);
427 if (field == F_Group) {
429 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
436 return ReportIllegal(keymap, action->type, field);
440 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
441 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
443 struct xkb_pointer_action *act;
446 act = (struct xkb_pointer_action *) action;
447 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
448 return ReportActionNotArray(keymap, action->type, field);
450 if (field == F_X || field == F_Y) {
453 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
458 if (!ExprResolveInteger(keymap->ctx, value, &val))
459 return ReportMismatch(keymap, action->type, field, "integer");
463 act->flags |= XkbSA_MoveAbsoluteX;
468 act->flags |= XkbSA_MoveAbsoluteY;
474 else if (field == F_Accel) {
477 if (!ExprResolveBoolean(keymap->ctx, value, &set))
478 return ReportMismatch(keymap, action->type, field, "boolean");
481 act->flags &= ~XkbSA_NoAcceleration;
483 act->flags |= XkbSA_NoAcceleration;
486 return ReportIllegal(keymap, action->type, field);
489 static const LookupEntry lockWhich[] = {
491 { "lock", XkbSA_LockNoUnlock },
492 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
493 { "unlock", XkbSA_LockNoLock },
498 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
499 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
501 struct xkb_pointer_button_action *act;
503 act = (struct xkb_pointer_button_action *) action;
504 if (field == F_Button) {
508 return ReportActionNotArray(keymap, action->type, field);
510 if (!ExprResolveButton(keymap->ctx, value, &btn))
511 return ReportMismatch(keymap, action->type, field,
512 "integer (range 1..5)");
514 if (btn < 0 || btn > 5) {
516 "Button must specify default or be in the range 1..5; "
517 "Illegal button value %d ignored\n", btn);
524 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
528 return ReportActionNotArray(keymap, action->type, field);
530 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
531 return ReportMismatch(keymap, action->type, field,
534 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
538 else if (field == F_Count) {
542 return ReportActionNotArray(keymap, action->type, field);
544 /* XXX: Should this actually be ResolveButton? */
545 if (!ExprResolveButton(keymap->ctx, value, &btn))
546 return ReportMismatch(keymap, action->type, field, "integer");
548 if (btn < 0 || btn > 255) {
550 "The count field must have a value in the range 0..255; "
551 "Illegal count %d ignored\n", btn);
558 return ReportIllegal(keymap, action->type, field);
561 static const LookupEntry ptrDflts[] = {
562 { "dfltbtn", XkbSA_AffectDfltBtn },
563 { "defaultbutton", XkbSA_AffectDfltBtn },
564 { "button", XkbSA_AffectDfltBtn },
569 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
570 unsigned field, const ExprDef *array_ndx,
571 const ExprDef *value)
573 struct xkb_pointer_default_action *act;
575 act = (struct xkb_pointer_default_action *) action;
576 if (field == F_Affect) {
580 return ReportActionNotArray(keymap, action->type, field);
582 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
583 return ReportMismatch(keymap, action->type, field,
584 "pointer component");
588 else if ((field == F_Button) || (field == F_Value)) {
589 const ExprDef *button;
593 return ReportActionNotArray(keymap, action->type, field);
595 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
596 act->flags &= ~XkbSA_DfltBtnAbsolute;
597 button = value->value.child;
600 act->flags |= XkbSA_DfltBtnAbsolute;
604 if (!ExprResolveButton(keymap->ctx, button, &btn))
605 return ReportMismatch(keymap, action->type, field,
606 "integer (range 1..5)");
608 if (btn < 0 || btn > 5) {
610 "New default button value must be in the range 1..5; "
611 "Illegal default button value %d ignored\n", btn);
616 "Cannot set default pointer button to \"default\"; "
617 "Illegal default button setting ignored\n");
621 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
625 return ReportIllegal(keymap, action->type, field);
628 static const LookupEntry isoNames[] = {
629 { "mods", XkbSA_ISONoAffectMods },
630 { "modifiers", XkbSA_ISONoAffectMods },
631 { "group", XkbSA_ISONoAffectGroup },
632 { "groups", XkbSA_ISONoAffectGroup },
633 { "ptr", XkbSA_ISONoAffectPtr },
634 { "pointer", XkbSA_ISONoAffectPtr },
635 { "ctrls", XkbSA_ISONoAffectCtrls },
636 { "controls", XkbSA_ISONoAffectCtrls },
637 { "all", ~((unsigned) 0) },
643 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
644 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
646 struct xkb_iso_action *act;
648 act = (struct xkb_iso_action *) action;
649 if (field == F_Modifiers) {
654 return ReportActionNotArray(keymap, action->type, field);
657 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
660 act->flags = flags & (~XkbSA_ISODfltIsGroup);
661 act->real_mods = mods & 0xff;
662 act->vmods = (mods >> 8) & 0xff;
665 else if (field == F_Group) {
666 xkb_group_index_t group;
670 return ReportActionNotArray(keymap, action->type, field);
673 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
676 act->flags = flags | XkbSA_ISODfltIsGroup;
679 } else if (F_Affect) {
683 return ReportActionNotArray(keymap, action->type, field);
685 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
686 return ReportMismatch(keymap, action->type, field,
687 "keyboard component");
689 act->affect = (~mask) & XkbSA_ISOAffectMask;
693 return ReportIllegal(keymap, action->type, field);
697 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
698 unsigned field, const ExprDef *array_ndx,
699 const ExprDef *value)
701 struct xkb_switch_screen_action *act;
703 act = (struct xkb_switch_screen_action *) action;
704 if (field == F_Screen) {
709 return ReportActionNotArray(keymap, action->type, field);
711 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
712 act->flags &= ~XkbSA_SwitchAbsolute;
713 scrn = value->value.child;
716 act->flags |= XkbSA_SwitchAbsolute;
720 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
721 return ReportMismatch(keymap, action->type, field,
724 if (val < 0 || val > 255) {
726 "Screen index must be in the range 1..255; "
727 "Illegal screen value %d ignored\n", val);
731 act->screen = (value->op == EXPR_NEGATE ? -val : val);
734 else if (field == F_Same) {
738 return ReportActionNotArray(keymap, action->type, field);
740 if (!ExprResolveBoolean(keymap->ctx, value, &set))
741 return ReportMismatch(keymap, action->type, field, "boolean");
744 act->flags &= ~XkbSA_SwitchApplication;
746 act->flags |= XkbSA_SwitchApplication;
751 return ReportIllegal(keymap, action->type, field);
754 const LookupEntry ctrlNames[] = {
755 { "repeatkeys", XkbRepeatKeysMask },
756 { "repeat", XkbRepeatKeysMask },
757 { "autorepeat", XkbRepeatKeysMask },
758 { "slowkeys", XkbSlowKeysMask },
759 { "bouncekeys", XkbBounceKeysMask },
760 { "stickykeys", XkbStickyKeysMask },
761 { "mousekeys", XkbMouseKeysMask },
762 { "mousekeysaccel", XkbMouseKeysAccelMask },
763 { "accessxkeys", XkbAccessXKeysMask },
764 { "accessxtimeout", XkbAccessXTimeoutMask },
765 { "accessxfeedback", XkbAccessXFeedbackMask },
766 { "audiblebell", XkbAudibleBellMask },
767 { "ignoregrouplock", XkbIgnoreGroupLockMask },
768 { "all", XkbAllBooleanCtrlsMask },
776 HandleSetLockControls(struct xkb_keymap *keymap,
777 struct xkb_any_action *action,
778 unsigned field, const ExprDef *array_ndx,
779 const ExprDef *value)
781 struct xkb_controls_action *act;
783 act = (struct xkb_controls_action *) action;
784 if (field == F_Controls) {
788 return ReportActionNotArray(keymap, action->type, field);
790 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
791 return ReportMismatch(keymap, action->type, field,
798 return ReportIllegal(keymap, action->type, field);
801 static const LookupEntry evNames[] = {
802 { "press", XkbSA_MessageOnPress },
803 { "keypress", XkbSA_MessageOnPress },
804 { "release", XkbSA_MessageOnRelease },
805 { "keyrelease", XkbSA_MessageOnRelease },
806 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
812 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
813 unsigned field, const ExprDef *array_ndx,
814 const ExprDef *value)
816 struct xkb_message_action *act;
818 act = (struct xkb_message_action *) action;
819 if (field == F_Report) {
823 return ReportActionNotArray(keymap, action->type, field);
825 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
826 return ReportMismatch(keymap, action->type, field,
829 /* FIXME: Something seems wrong here... */
830 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
831 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
834 else if (field == F_GenKeyEvent) {
838 return ReportActionNotArray(keymap, action->type, field);
840 if (!ExprResolveBoolean(keymap->ctx, value, &set))
841 return ReportMismatch(keymap, action->type, field, "boolean");
844 act->flags |= XkbSA_MessageGenKeyEvent;
846 act->flags &= ~XkbSA_MessageGenKeyEvent;
850 else if (field == F_Data && !array_ndx) {
854 if (!ExprResolveString(keymap->ctx, value, &str))
855 return ReportMismatch(keymap, action->type, field, "string");
858 if (len < 1 || len > 6) {
859 log_warn(keymap->ctx,
860 "An action message can hold only 6 bytes; "
861 "Extra %d bytes ignored\n", len - 6);
864 strncpy((char *) act->message, str, 6);
867 else if (field == F_Data && array_ndx) {
870 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
872 "Array subscript must be integer; "
873 "Illegal subscript ignored\n");
877 if (ndx < 0 || ndx > 5) {
879 "An action message is at most 6 bytes long; "
880 "Attempt to use data[%d] ignored\n", ndx);
884 if (!ExprResolveInteger(keymap->ctx, value, &datum))
885 return ReportMismatch(keymap, action->type, field, "integer");
887 if (datum < 0 || datum > 255) {
889 "Message data must be in the range 0..255; "
890 "Illegal datum %d ignored\n", datum);
894 act->message[ndx] = (uint8_t) datum;
898 return ReportIllegal(keymap, action->type, field);
902 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
903 unsigned field, const ExprDef *array_ndx,
904 const ExprDef *value)
907 struct xkb_redirect_key_action *act;
911 char key_name[XkbKeyNameLength];
913 if (array_ndx != NULL)
914 return ReportActionNotArray(keymap, action->type, field);
916 act = (struct xkb_redirect_key_action *) action;
919 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
920 return ReportMismatch(keymap, action->type, field, "key name");
922 tmp = KeyNameToLong(key_name);
923 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
925 return ReportNotFound(keymap, action->type, field, "Key",
926 KeyNameText(key_name));
927 act->new_kc = XkbKeyGetKeycode(keymap, key);
933 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
934 act->mods_mask |= (t2 & 0xff);
935 if (field == F_Modifiers)
936 act->mods |= (t2 & 0xff);
938 act->mods &= ~(t2 & 0xff);
940 t2 = (t2 >> 8) & 0xffff;
941 act->vmods_mask |= t2;
942 if (field == F_Modifiers)
950 return ReportIllegal(keymap, action->type, field);
954 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
955 unsigned field, const ExprDef *array_ndx,
956 const ExprDef *value)
958 struct xkb_device_button_action *act;
960 act = (struct xkb_device_button_action *) action;
961 if (field == F_Button) {
965 return ReportActionNotArray(keymap, action->type, field);
967 if (!ExprResolveInteger(keymap->ctx, value, &val))
968 return ReportMismatch(keymap, action->type, field,
969 "integer (range 1..255)");
971 if (val < 0 || val > 255) {
973 "Button must specify default or be in the range 1..255; "
974 "Illegal button value %d ignored\n", val);
981 else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
985 return ReportActionNotArray(keymap, action->type, field);
987 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
988 return ReportMismatch(keymap, action->type, field,
991 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
995 else if (field == F_Count) {
999 return ReportActionNotArray(keymap, action->type, field);
1001 /* XXX: Should this actually be ResolveButton? */
1002 if (!ExprResolveButton(keymap->ctx, value, &btn))
1003 return ReportMismatch(keymap, action->type, field, "integer");
1005 if (btn < 0 || btn > 255) {
1006 log_err(keymap->ctx,
1007 "The count field must have a value in the range 0..255; "
1008 "Illegal count %d ignored\n", btn);
1015 else if (field == F_Device) {
1019 return ReportActionNotArray(keymap, action->type, field);
1021 if (!ExprResolveInteger(keymap->ctx, value, &val))
1022 return ReportMismatch(keymap, action->type, field,
1023 "integer (range 1..255)");
1025 if (val < 0 || val > 255) {
1026 log_err(keymap->ctx,
1027 "Device must specify default or be in the range 1..255; "
1028 "Illegal device value %d ignored\n", val);
1036 return ReportIllegal(keymap, action->type, field);
1040 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
1041 unsigned field, const ExprDef *array_ndx,
1042 const ExprDef *value)
1046 struct xkb_device_valuator_action *act;
1048 act = (struct xkb_device_valuator_action *) action;
1049 /* XXX - Not yet implemented */
1055 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
1056 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
1058 if (field == F_Type) {
1061 if (!ExprResolveInteger(keymap->ctx, value, &type))
1062 return ReportMismatch(keymap, PrivateAction, field, "integer");
1064 if (type < 0 || type > 255) {
1065 log_err(keymap->ctx,
1066 "Private action type must be in the range 0..255; "
1067 "Illegal type %d ignored\n", type);
1071 action->type = (uint8_t) type;
1074 else if (field == F_Data) {
1075 if (array_ndx == NULL) {
1079 if (!ExprResolveString(keymap->ctx, value, &str))
1080 return ReportMismatch(keymap, action->type, field, "string");
1083 if (len < 1 || len > 7) {
1084 log_warn(keymap->ctx,
1085 "A private action has 7 data bytes; "
1086 "Extra %d bytes ignored\n", len - 6);
1090 strncpy((char *) action->data, str, sizeof(action->data));
1096 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1097 log_err(keymap->ctx,
1098 "Array subscript must be integer; "
1099 "Illegal subscript ignored\n");
1103 if (ndx < 0 || ndx >= sizeof(action->data)) {
1104 log_err(keymap->ctx,
1105 "The data for a private action is %zu bytes long; "
1106 "Attempt to use data[%d] ignored\n",
1107 sizeof(action->data), ndx);
1111 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1112 return ReportMismatch(keymap, action->type, field, "integer");
1114 if (datum < 0 || datum > 255) {
1115 log_err(keymap->ctx,
1116 "All data for a private action must be 0..255; "
1117 "Illegal datum %d ignored\n", datum);
1121 action->data[ndx] = (uint8_t) datum;
1126 return ReportIllegal(keymap, PrivateAction, field);
1129 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1130 struct xkb_any_action *action, unsigned field,
1131 const ExprDef *array_ndx, const ExprDef *value);
1133 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1134 [XkbSA_NoAction] = HandleNoAction,
1135 [XkbSA_SetMods] = HandleSetLatchMods,
1136 [XkbSA_LatchMods] = HandleSetLatchMods,
1137 [XkbSA_LockMods] = HandleLockMods,
1138 [XkbSA_SetGroup] = HandleSetLatchGroup,
1139 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1140 [XkbSA_LockGroup] = HandleLockGroup,
1141 [XkbSA_MovePtr] = HandleMovePtr,
1142 [XkbSA_PtrBtn] = HandlePtrBtn,
1143 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1144 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1145 [XkbSA_ISOLock] = HandleISOLock,
1146 [XkbSA_Terminate] = HandleNoAction,
1147 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1148 [XkbSA_SetControls] = HandleSetLockControls,
1149 [XkbSA_LockControls] = HandleSetLockControls,
1150 [XkbSA_ActionMessage] = HandleActionMessage,
1151 [XkbSA_RedirectKey] = HandleRedirectKey,
1152 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1153 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1154 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1155 [PrivateAction] = HandlePrivate,
1158 /***====================================================================***/
1161 ApplyActionFactoryDefaults(union xkb_action * action)
1163 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1164 action->dflt.affect = XkbSA_AffectDfltBtn;
1165 action->dflt.flags = 0;
1166 action->dflt.value = 1;
1168 else if (action->type == XkbSA_ISOLock) {
1169 action->iso.real_mods = LockMask;
1174 HandleActionDef(ExprDef * def,
1175 struct xkb_keymap *keymap,
1176 struct xkb_any_action *action, ActionInfo *info)
1180 unsigned tmp, hndlrType;
1182 if (def->op != EXPR_ACTION_DECL) {
1183 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1184 exprOpText(def->op));
1187 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1189 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1192 if (!stringToAction(str, &tmp)) {
1193 log_err(keymap->ctx, "Unknown action %s\n", str);
1196 action->type = hndlrType = tmp;
1197 if (action->type != XkbSA_NoAction) {
1198 ApplyActionFactoryDefaults((union xkb_action *) action);
1201 if ((info->action == XkbSA_NoAction)
1202 || (info->action == hndlrType)) {
1203 if (!(*handleAction[hndlrType])(keymap, action,
1213 for (arg = def->value.action.args; arg != NULL;
1214 arg = (ExprDef *) arg->common.next) {
1215 const ExprDef *value;
1216 ExprDef *field, *arrayRtrn;
1217 const char *elemRtrn, *fieldRtrn;
1220 if (arg->op == EXPR_ASSIGN) {
1221 field = arg->value.binary.left;
1222 value = arg->value.binary.right;
1225 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1226 field = arg->value.child;
1227 value = &constFalse;
1234 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1236 return false; /* internal error -- already reported */
1238 if (elemRtrn != NULL) {
1239 log_err(keymap->ctx,
1240 "Cannot change defaults in an action definition; "
1241 "Ignoring attempt to change %s.%s\n",
1242 elemRtrn, fieldRtrn);
1245 if (!stringToField(fieldRtrn, &fieldNdx)) {
1246 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1249 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1256 /***====================================================================***/
1259 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1260 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1262 ActionInfo *new, *old;
1264 new = malloc(sizeof(*new));
1266 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1270 if (istreq(elem, "action"))
1271 new->action = XkbSA_NoAction;
1273 if (!stringToAction(elem, &new->action)) {
1277 if (new->action == XkbSA_NoAction) {
1278 log_err(keymap->ctx,
1279 "\"%s\" is not a valid field in a NoAction action\n",
1285 if (!stringToField(field, &new->field)) {
1286 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1290 new->array_ndx = array_ndx;
1294 while ((old) && (old->next))
1303 /***====================================================================***/
1306 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1309 size_t old_ndx, old_num_acts, new_ndx;
1312 key->acts_index = 0;
1316 if (XkbKeyHasActions(key) && key->width >= needed)
1317 return XkbKeyActionsPtr(keymap, key);
1320 * The key may already be in the array, but without enough space.
1321 * This should not happen often, so in order to avoid moving and
1322 * copying stuff from acts and key_acts, we just allocate new
1323 * space for the key at the end, and leave the old space alone.
1326 old_ndx = key->acts_index;
1327 old_num_acts = XkbKeyNumActions(key);
1328 new_ndx = darray_size(keymap->acts);
1330 darray_resize0(keymap->acts, new_ndx + needed);
1331 key->acts_index = new_ndx;
1334 * The key was already in the array, copy the old actions to the
1338 memcpy(darray_mem(keymap->acts, new_ndx),
1339 darray_mem(keymap->acts, old_ndx),
1340 old_num_acts * sizeof(union xkb_action));
1342 return XkbKeyActionsPtr(keymap, key);