1 /************************************************************
2 * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of Silicon Graphics not be
10 * used in advertising or publicity pertaining to distribution
11 * of the software without specific prior written permission.
12 * Silicon Graphics makes no representation about the suitability
13 * of this software for any purpose. It is provided "as is"
14 * without any express or implied warranty.
16 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
29 static bool actionsInitialized;
30 static ExprDef constTrue;
31 static ExprDef constFalse;
33 /***====================================================================***/
35 static const LookupEntry actionStrings[] = {
36 { "noaction", XkbSA_NoAction },
37 { "setmods", XkbSA_SetMods },
38 { "latchmods", XkbSA_LatchMods },
39 { "lockmods", XkbSA_LockMods },
40 { "setgroup", XkbSA_SetGroup },
41 { "latchgroup", XkbSA_LatchGroup },
42 { "lockgroup", XkbSA_LockGroup },
43 { "moveptr", XkbSA_MovePtr },
44 { "movepointer", XkbSA_MovePtr },
45 { "ptrbtn", XkbSA_PtrBtn },
46 { "pointerbutton", XkbSA_PtrBtn },
47 { "lockptrbtn", XkbSA_LockPtrBtn },
48 { "lockpointerbutton", XkbSA_LockPtrBtn },
49 { "lockptrbutton", XkbSA_LockPtrBtn },
50 { "lockpointerbtn", XkbSA_LockPtrBtn },
51 { "setptrdflt", XkbSA_SetPtrDflt },
52 { "setpointerdefault", XkbSA_SetPtrDflt },
53 { "isolock", XkbSA_ISOLock },
54 { "terminate", XkbSA_Terminate },
55 { "terminateserver", XkbSA_Terminate },
56 { "switchscreen", XkbSA_SwitchScreen },
57 { "setcontrols", XkbSA_SetControls },
58 { "lockcontrols", XkbSA_LockControls },
59 { "actionmessage", XkbSA_ActionMessage },
60 { "messageaction", XkbSA_ActionMessage },
61 { "message", XkbSA_ActionMessage },
62 { "redirect", XkbSA_RedirectKey },
63 { "redirectkey", XkbSA_RedirectKey },
64 { "devbtn", XkbSA_DeviceBtn },
65 { "devicebtn", XkbSA_DeviceBtn },
66 { "devbutton", XkbSA_DeviceBtn },
67 { "devicebutton", XkbSA_DeviceBtn },
68 { "lockdevbtn", XkbSA_DeviceBtn },
69 { "lockdevicebtn", XkbSA_LockDeviceBtn },
70 { "lockdevbutton", XkbSA_LockDeviceBtn },
71 { "lockdevicebutton", XkbSA_LockDeviceBtn },
72 { "devval", XkbSA_DeviceValuator },
73 { "deviceval", XkbSA_DeviceValuator },
74 { "devvaluator", XkbSA_DeviceValuator },
75 { "devicevaluator", XkbSA_DeviceValuator },
76 { "private", PrivateAction },
80 static const LookupEntry fieldStrings[] = {
81 { "clearLocks", F_ClearLocks },
82 { "latchToLock", F_LatchToLock },
83 { "genKeyEvent", F_GenKeyEvent },
84 { "generateKeyEvent", F_GenKeyEvent },
85 { "report", F_Report },
86 { "default", F_Default },
87 { "affect", F_Affect },
88 { "increment", F_Increment },
89 { "modifiers", F_Modifiers },
90 { "mods", F_Modifiers },
95 { "accelerate", F_Accel },
96 { "repeat", F_Accel },
97 { "button", F_Button },
99 { "controls", F_Controls },
100 { "ctrls", F_Controls },
102 { "count", F_Count },
103 { "screen", F_Screen },
105 { "sameServer", F_Same },
107 { "device", F_Device },
109 { "key", F_Keycode },
110 { "keycode", F_Keycode },
112 { "clearmods", F_ModsToClear },
113 { "clearmodifiers", F_ModsToClear },
118 stringToValue(const LookupEntry tab[], const char *string,
119 unsigned int *value_rtrn)
121 const LookupEntry *entry;
126 for (entry = tab; entry->name; entry++) {
127 if (istreq(entry->name, string)) {
128 *value_rtrn = entry->value;
137 valueToString(const LookupEntry tab[], unsigned int value)
139 const LookupEntry *entry;
141 for (entry = tab; entry->name; entry++)
142 if (entry->value == value)
149 stringToAction(const char *str, unsigned *type_rtrn)
151 return stringToValue(actionStrings, str, type_rtrn);
155 stringToField(const char *str, unsigned *field_rtrn)
157 return stringToValue(fieldStrings, str, field_rtrn);
161 fieldText(unsigned field)
163 return valueToString(fieldStrings, field);
166 /***====================================================================***/
169 ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
173 "Value of %s field must be of type %s; "
174 "Action %s definition ignored\n",
175 fieldText(field), type, ActionTypeText(action));
180 ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
183 "Field %s is not defined for an action of type %s; "
184 "Action definition ignored\n",
185 fieldText(field), ActionTypeText(action));
190 ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
194 "The %s field in the %s action is not an array; "
195 "Action definition ignored\n",
196 fieldText(field), ActionTypeText(action));
201 ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
202 const char *what, const char *bad)
205 "%s named %s not found; "
206 "Ignoring the %s field of an %s action\n",
207 what, bad, fieldText(field), ActionTypeText(action));
212 HandleNoAction(struct xkb_keymap *keymap, struct xkb_any_action *action,
213 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
216 return ReportIllegal(keymap, action->type, field);
220 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
221 unsigned field, const ExprDef * value,
222 unsigned *flags_inout)
227 if (field == F_ClearLocks)
228 tmp = XkbSA_ClearLocks;
229 else if (field == F_LatchToLock)
230 tmp = XkbSA_LatchToLock;
232 return false; /* WSGO! */
234 if (!ExprResolveBoolean(keymap->ctx, value, &result))
235 return ReportMismatch(keymap, action, field, "boolean");
240 *flags_inout &= ~tmp;
246 CheckModifierField(struct xkb_keymap *keymap, unsigned action,
247 const ExprDef *value, unsigned *flags_inout,
248 xkb_mod_mask_t *mods_rtrn)
250 if (value->op == EXPR_IDENT) {
252 valStr = xkb_atom_text(keymap->ctx, value->value.str);
253 if (valStr && (istreq(valStr, "usemodmapmods") ||
254 istreq(valStr, "modmapmods"))) {
257 *flags_inout |= XkbSA_UseModMapMods;
262 if (!ExprResolveVModMask(keymap, value, mods_rtrn))
263 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
265 *flags_inout &= ~XkbSA_UseModMapMods;
270 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
271 unsigned field, const ExprDef *array_ndx,
272 const ExprDef *value)
274 struct xkb_mod_action *act;
279 act = (struct xkb_mod_action *) action;
280 if (array_ndx != NULL) {
285 return ReportActionNotArray(keymap, action->type, field);
292 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
300 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
302 act->real_mods = act->mask = (t2 & 0xff);
303 act->vmods = (t2 >> 8) & 0xffff;
308 return ReportIllegal(keymap, action->type, field);
312 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
313 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
315 struct xkb_mod_action *act;
319 act = (struct xkb_mod_action *) action;
320 if ((array_ndx != NULL) && (field == F_Modifiers))
321 return ReportActionNotArray(keymap, action->type, field);
325 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
327 act->real_mods = act->mask = (t2 & 0xff);
328 act->vmods = (t2 >> 8) & 0xffff;
333 return ReportIllegal(keymap, action->type, field);
337 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
338 const ExprDef *value, unsigned *flags_inout,
339 xkb_group_index_t *grp_rtrn)
343 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
344 *flags_inout &= ~XkbSA_GroupAbsolute;
345 spec = value->value.child;
348 *flags_inout |= XkbSA_GroupAbsolute;
352 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
353 return ReportMismatch(keymap, action, F_Group,
354 "integer (range 1..8)");
356 if (value->op == EXPR_NEGATE)
357 *grp_rtrn = -*grp_rtrn;
358 else if (value->op != EXPR_UNARY_PLUS)
365 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
366 unsigned field, const ExprDef *array_ndx,
367 const ExprDef *value)
369 struct xkb_group_action *act;
372 xkb_group_index_t t2;
374 act = (struct xkb_group_action *) action;
375 if (array_ndx != NULL) {
380 return ReportActionNotArray(keymap, action->type, field);
387 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
395 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
402 return ReportIllegal(keymap, action->type, field);
406 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
407 unsigned field, const ExprDef *array_ndx,
408 const ExprDef *value)
410 struct xkb_group_action *act;
412 xkb_group_index_t t2;
414 act = (struct xkb_group_action *) action;
415 if ((array_ndx != NULL) && (field == F_Group))
416 return ReportActionNotArray(keymap, action->type, field);
417 if (field == F_Group) {
419 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
426 return ReportIllegal(keymap, action->type, field);
430 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
431 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
433 struct xkb_pointer_action *act;
436 act = (struct xkb_pointer_action *) action;
437 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
438 return ReportActionNotArray(keymap, action->type, field);
440 if (field == F_X || field == F_Y) {
443 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
448 if (!ExprResolveInteger(keymap->ctx, value, &val))
449 return ReportMismatch(keymap, action->type, field, "integer");
453 act->flags |= XkbSA_MoveAbsoluteX;
458 act->flags |= XkbSA_MoveAbsoluteY;
464 else if (field == F_Accel) {
467 if (!ExprResolveBoolean(keymap->ctx, value, &set))
468 return ReportMismatch(keymap, action->type, field, "boolean");
471 act->flags &= ~XkbSA_NoAcceleration;
473 act->flags |= XkbSA_NoAcceleration;
476 return ReportIllegal(keymap, action->type, field);
479 static const LookupEntry lockWhich[] = {
481 { "lock", XkbSA_LockNoUnlock },
482 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
483 { "unlock", XkbSA_LockNoLock },
488 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
489 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
491 struct xkb_pointer_button_action *act;
493 act = (struct xkb_pointer_button_action *) action;
494 if (field == F_Button) {
498 return ReportActionNotArray(keymap, action->type, field);
500 if (!ExprResolveButton(keymap->ctx, value, &btn))
501 return ReportMismatch(keymap, action->type, field,
502 "integer (range 1..5)");
504 if (btn < 0 || btn > 5) {
506 "Button must specify default or be in the range 1..5; "
507 "Illegal button value %d ignored\n", btn);
514 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
518 return ReportActionNotArray(keymap, action->type, field);
520 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
521 return ReportMismatch(keymap, action->type, field,
524 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
528 else if (field == F_Count) {
532 return ReportActionNotArray(keymap, action->type, field);
534 /* XXX: Should this actually be ResolveButton? */
535 if (!ExprResolveButton(keymap->ctx, value, &btn))
536 return ReportMismatch(keymap, action->type, field, "integer");
538 if (btn < 0 || btn > 255) {
540 "The count field must have a value in the range 0..255; "
541 "Illegal count %d ignored\n", btn);
548 return ReportIllegal(keymap, action->type, field);
551 static const LookupEntry ptrDflts[] = {
552 { "dfltbtn", XkbSA_AffectDfltBtn },
553 { "defaultbutton", XkbSA_AffectDfltBtn },
554 { "button", XkbSA_AffectDfltBtn },
559 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
560 unsigned field, const ExprDef *array_ndx,
561 const ExprDef *value)
563 struct xkb_pointer_default_action *act;
565 act = (struct xkb_pointer_default_action *) action;
566 if (field == F_Affect) {
570 return ReportActionNotArray(keymap, action->type, field);
572 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
573 return ReportMismatch(keymap, action->type, field,
574 "pointer component");
578 else if ((field == F_Button) || (field == F_Value)) {
579 const ExprDef *button;
583 return ReportActionNotArray(keymap, action->type, field);
585 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
586 act->flags &= ~XkbSA_DfltBtnAbsolute;
587 button = value->value.child;
590 act->flags |= XkbSA_DfltBtnAbsolute;
594 if (!ExprResolveButton(keymap->ctx, button, &btn))
595 return ReportMismatch(keymap, action->type, field,
596 "integer (range 1..5)");
598 if (btn < 0 || btn > 5) {
600 "New default button value must be in the range 1..5; "
601 "Illegal default button value %d ignored\n", btn);
606 "Cannot set default pointer button to \"default\"; "
607 "Illegal default button setting ignored\n");
611 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
615 return ReportIllegal(keymap, action->type, field);
618 static const LookupEntry isoNames[] = {
619 { "mods", XkbSA_ISONoAffectMods },
620 { "modifiers", XkbSA_ISONoAffectMods },
621 { "group", XkbSA_ISONoAffectGroup },
622 { "groups", XkbSA_ISONoAffectGroup },
623 { "ptr", XkbSA_ISONoAffectPtr },
624 { "pointer", XkbSA_ISONoAffectPtr },
625 { "ctrls", XkbSA_ISONoAffectCtrls },
626 { "controls", XkbSA_ISONoAffectCtrls },
627 { "all", ~((unsigned) 0) },
633 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
634 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
636 struct xkb_iso_action *act;
638 act = (struct xkb_iso_action *) action;
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->real_mods = mods & 0xff;
652 act->vmods = (mods >> 8) & 0xff;
655 else if (field == F_Group) {
656 xkb_group_index_t group;
660 return ReportActionNotArray(keymap, action->type, field);
663 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
666 act->flags = flags | XkbSA_ISODfltIsGroup;
669 } else if (F_Affect) {
673 return ReportActionNotArray(keymap, action->type, field);
675 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
676 return ReportMismatch(keymap, action->type, field,
677 "keyboard component");
679 act->affect = (~mask) & XkbSA_ISOAffectMask;
683 return ReportIllegal(keymap, action->type, field);
687 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
688 unsigned field, const ExprDef *array_ndx,
689 const ExprDef *value)
691 struct xkb_switch_screen_action *act;
693 act = (struct xkb_switch_screen_action *) action;
694 if (field == F_Screen) {
699 return ReportActionNotArray(keymap, action->type, field);
701 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
702 act->flags &= ~XkbSA_SwitchAbsolute;
703 scrn = value->value.child;
706 act->flags |= XkbSA_SwitchAbsolute;
710 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
711 return ReportMismatch(keymap, action->type, field,
714 if (val < 0 || val > 255) {
716 "Screen index must be in the range 1..255; "
717 "Illegal screen value %d ignored\n", val);
721 act->screen = (value->op == EXPR_NEGATE ? -val : val);
724 else if (field == F_Same) {
728 return ReportActionNotArray(keymap, action->type, field);
730 if (!ExprResolveBoolean(keymap->ctx, value, &set))
731 return ReportMismatch(keymap, action->type, field, "boolean");
734 act->flags &= ~XkbSA_SwitchApplication;
736 act->flags |= XkbSA_SwitchApplication;
741 return ReportIllegal(keymap, action->type, field);
744 const LookupEntry ctrlNames[] = {
745 { "repeatkeys", XkbRepeatKeysMask },
746 { "repeat", XkbRepeatKeysMask },
747 { "autorepeat", XkbRepeatKeysMask },
748 { "slowkeys", XkbSlowKeysMask },
749 { "bouncekeys", XkbBounceKeysMask },
750 { "stickykeys", XkbStickyKeysMask },
751 { "mousekeys", XkbMouseKeysMask },
752 { "mousekeysaccel", XkbMouseKeysAccelMask },
753 { "accessxkeys", XkbAccessXKeysMask },
754 { "accessxtimeout", XkbAccessXTimeoutMask },
755 { "accessxfeedback", XkbAccessXFeedbackMask },
756 { "audiblebell", XkbAudibleBellMask },
757 { "ignoregrouplock", XkbIgnoreGroupLockMask },
758 { "all", XkbAllBooleanCtrlsMask },
766 HandleSetLockControls(struct xkb_keymap *keymap,
767 struct xkb_any_action *action,
768 unsigned field, const ExprDef *array_ndx,
769 const ExprDef *value)
771 struct xkb_controls_action *act;
773 act = (struct xkb_controls_action *) action;
774 if (field == F_Controls) {
778 return ReportActionNotArray(keymap, action->type, field);
780 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
781 return ReportMismatch(keymap, action->type, field,
788 return ReportIllegal(keymap, action->type, field);
791 static const LookupEntry evNames[] = {
792 { "press", XkbSA_MessageOnPress },
793 { "keypress", XkbSA_MessageOnPress },
794 { "release", XkbSA_MessageOnRelease },
795 { "keyrelease", XkbSA_MessageOnRelease },
796 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
802 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
803 unsigned field, const ExprDef *array_ndx,
804 const ExprDef *value)
806 struct xkb_message_action *act;
808 act = (struct xkb_message_action *) action;
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, struct xkb_any_action *action,
893 unsigned field, const ExprDef *array_ndx,
894 const ExprDef *value)
897 struct xkb_redirect_key_action *act;
901 char key_name[XkbKeyNameLength];
903 if (array_ndx != NULL)
904 return ReportActionNotArray(keymap, action->type, field);
906 act = (struct xkb_redirect_key_action *) action;
909 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
910 return ReportMismatch(keymap, action->type, field, "key name");
912 tmp = KeyNameToLong(key_name);
913 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
915 return ReportNotFound(keymap, action->type, field, "Key",
916 KeyNameText(key_name));
917 act->new_kc = XkbKeyGetKeycode(keymap, key);
923 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
924 act->mods_mask |= (t2 & 0xff);
925 if (field == F_Modifiers)
926 act->mods |= (t2 & 0xff);
928 act->mods &= ~(t2 & 0xff);
930 t2 = (t2 >> 8) & 0xffff;
931 act->vmods_mask |= t2;
932 if (field == F_Modifiers)
940 return ReportIllegal(keymap, action->type, field);
944 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
945 unsigned field, const ExprDef *array_ndx,
946 const ExprDef *value)
948 struct xkb_device_button_action *act;
950 act = (struct xkb_device_button_action *) action;
951 if (field == F_Button) {
955 return ReportActionNotArray(keymap, action->type, field);
957 if (!ExprResolveInteger(keymap->ctx, value, &val))
958 return ReportMismatch(keymap, action->type, field,
959 "integer (range 1..255)");
961 if (val < 0 || val > 255) {
963 "Button must specify default or be in the range 1..255; "
964 "Illegal button value %d ignored\n", val);
971 else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
975 return ReportActionNotArray(keymap, action->type, field);
977 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
978 return ReportMismatch(keymap, action->type, field,
981 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
985 else if (field == F_Count) {
989 return ReportActionNotArray(keymap, action->type, field);
991 /* XXX: Should this actually be ResolveButton? */
992 if (!ExprResolveButton(keymap->ctx, value, &btn))
993 return ReportMismatch(keymap, action->type, field, "integer");
995 if (btn < 0 || btn > 255) {
997 "The count field must have a value in the range 0..255; "
998 "Illegal count %d ignored\n", btn);
1005 else if (field == F_Device) {
1009 return ReportActionNotArray(keymap, action->type, field);
1011 if (!ExprResolveInteger(keymap->ctx, value, &val))
1012 return ReportMismatch(keymap, action->type, field,
1013 "integer (range 1..255)");
1015 if (val < 0 || val > 255) {
1016 log_err(keymap->ctx,
1017 "Device must specify default or be in the range 1..255; "
1018 "Illegal device value %d ignored\n", val);
1026 return ReportIllegal(keymap, action->type, field);
1030 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
1031 unsigned field, const ExprDef *array_ndx,
1032 const ExprDef *value)
1036 struct xkb_device_valuator_action *act;
1038 act = (struct xkb_device_valuator_action *) action;
1039 /* XXX - Not yet implemented */
1045 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
1046 unsigned field, const ExprDef *array_ndx, const ExprDef *value)
1048 if (field == F_Type) {
1051 if (!ExprResolveInteger(keymap->ctx, value, &type))
1052 return ReportMismatch(keymap, PrivateAction, field, "integer");
1054 if (type < 0 || type > 255) {
1055 log_err(keymap->ctx,
1056 "Private action type must be in the range 0..255; "
1057 "Illegal type %d ignored\n", type);
1061 action->type = (uint8_t) type;
1064 else if (field == F_Data) {
1065 if (array_ndx == NULL) {
1069 if (!ExprResolveString(keymap->ctx, value, &str))
1070 return ReportMismatch(keymap, action->type, field, "string");
1073 if (len < 1 || len > 7) {
1074 log_warn(keymap->ctx,
1075 "A private action has 7 data bytes; "
1076 "Extra %d bytes ignored\n", len - 6);
1080 strncpy((char *) action->data, str, sizeof(action->data));
1086 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1087 log_err(keymap->ctx,
1088 "Array subscript must be integer; "
1089 "Illegal subscript ignored\n");
1093 if (ndx < 0 || ndx >= sizeof(action->data)) {
1094 log_err(keymap->ctx,
1095 "The data for a private action is %zu bytes long; "
1096 "Attempt to use data[%d] ignored\n",
1097 sizeof(action->data), ndx);
1101 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1102 return ReportMismatch(keymap, action->type, field, "integer");
1104 if (datum < 0 || datum > 255) {
1105 log_err(keymap->ctx,
1106 "All data for a private action must be 0..255; "
1107 "Illegal datum %d ignored\n", datum);
1111 action->data[ndx] = (uint8_t) datum;
1116 return ReportIllegal(keymap, PrivateAction, field);
1119 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1120 struct xkb_any_action *action, unsigned field,
1121 const ExprDef *array_ndx, const ExprDef *value);
1123 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1124 [XkbSA_NoAction] = HandleNoAction,
1125 [XkbSA_SetMods] = HandleSetLatchMods,
1126 [XkbSA_LatchMods] = HandleSetLatchMods,
1127 [XkbSA_LockMods] = HandleLockMods,
1128 [XkbSA_SetGroup] = HandleSetLatchGroup,
1129 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1130 [XkbSA_LockGroup] = HandleLockGroup,
1131 [XkbSA_MovePtr] = HandleMovePtr,
1132 [XkbSA_PtrBtn] = HandlePtrBtn,
1133 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1134 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1135 [XkbSA_ISOLock] = HandleISOLock,
1136 [XkbSA_Terminate] = HandleNoAction,
1137 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1138 [XkbSA_SetControls] = HandleSetLockControls,
1139 [XkbSA_LockControls] = HandleSetLockControls,
1140 [XkbSA_ActionMessage] = HandleActionMessage,
1141 [XkbSA_RedirectKey] = HandleRedirectKey,
1142 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1143 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1144 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1145 [PrivateAction] = HandlePrivate,
1148 /***====================================================================***/
1151 ApplyActionFactoryDefaults(union xkb_action * action)
1153 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1154 action->dflt.affect = XkbSA_AffectDfltBtn;
1155 action->dflt.flags = 0;
1156 action->dflt.value = 1;
1158 else if (action->type == XkbSA_ISOLock) {
1159 action->iso.real_mods = LockMask;
1164 ActionsInit(struct xkb_context *ctx);
1167 HandleActionDef(ExprDef * def,
1168 struct xkb_keymap *keymap,
1169 struct xkb_any_action *action, ActionInfo *info)
1173 unsigned tmp, hndlrType;
1175 if (!actionsInitialized)
1176 ActionsInit(keymap->ctx);
1178 if (def->op != EXPR_ACTION_DECL) {
1179 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1180 exprOpText(def->op));
1183 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1185 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1188 if (!stringToAction(str, &tmp)) {
1189 log_err(keymap->ctx, "Unknown action %s\n", str);
1192 action->type = hndlrType = tmp;
1193 if (action->type != XkbSA_NoAction) {
1194 ApplyActionFactoryDefaults((union xkb_action *) action);
1197 if ((info->action == XkbSA_NoAction)
1198 || (info->action == hndlrType)) {
1199 if (!(*handleAction[hndlrType])(keymap, action,
1209 for (arg = def->value.action.args; arg != NULL;
1210 arg = (ExprDef *) arg->common.next) {
1211 const ExprDef *value;
1212 ExprDef *field, *arrayRtrn;
1213 const char *elemRtrn, *fieldRtrn;
1216 if (arg->op == EXPR_ASSIGN) {
1217 field = arg->value.binary.left;
1218 value = arg->value.binary.right;
1221 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1222 field = arg->value.child;
1223 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1224 value = &constFalse;
1228 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1232 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1234 return false; /* internal error -- already reported */
1236 if (elemRtrn != NULL) {
1237 log_err(keymap->ctx,
1238 "Cannot change defaults in an action definition; "
1239 "Ignoring attempt to change %s.%s\n",
1240 elemRtrn, fieldRtrn);
1243 if (!stringToField(fieldRtrn, &fieldNdx)) {
1244 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1247 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1254 /***====================================================================***/
1257 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1258 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1260 ActionInfo *new, *old;
1262 if (!actionsInitialized)
1263 ActionsInit(keymap->ctx);
1265 new = malloc(sizeof(*new));
1267 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1271 if (istreq(elem, "action"))
1272 new->action = XkbSA_NoAction;
1274 if (!stringToAction(elem, &new->action)) {
1278 if (new->action == XkbSA_NoAction) {
1279 log_err(keymap->ctx,
1280 "\"%s\" is not a valid field in a NoAction action\n",
1286 if (!stringToField(field, &new->field)) {
1287 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1291 new->array_ndx = array_ndx;
1295 while ((old) && (old->next))
1304 /***====================================================================***/
1307 ActionsInit(struct xkb_context *ctx)
1309 if (!actionsInitialized) {
1310 memset(&constTrue, 0, sizeof(constTrue));
1311 memset(&constFalse, 0, sizeof(constFalse));
1312 constTrue.common.type = STMT_EXPR;
1313 constTrue.common.next = NULL;
1314 constTrue.op = EXPR_IDENT;
1315 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1316 constTrue.value.str = xkb_atom_intern(ctx, "true");
1317 constFalse.common.type = STMT_EXPR;
1318 constFalse.common.next = NULL;
1319 constFalse.op = EXPR_IDENT;
1320 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1321 constFalse.value.str = xkb_atom_intern(ctx, "false");
1322 actionsInitialized = 1;
1327 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1330 size_t old_ndx, old_num_acts, new_ndx;
1333 key->acts_index = 0;
1337 if (XkbKeyHasActions(key) && key->width >= needed)
1338 return XkbKeyActionsPtr(keymap, key);
1341 * The key may already be in the array, but without enough space.
1342 * This should not happen often, so in order to avoid moving and
1343 * copying stuff from acts and key_acts, we just allocate new
1344 * space for the key at the end, and leave the old space alone.
1347 old_ndx = key->acts_index;
1348 old_num_acts = XkbKeyNumActions(key);
1349 new_ndx = darray_size(keymap->acts);
1351 darray_resize0(keymap->acts, new_ndx + needed);
1352 key->acts_index = new_ndx;
1355 * The key was already in the array, copy the old actions to the
1359 memcpy(darray_mem(keymap->acts, new_ndx),
1360 darray_mem(keymap->acts, old_ndx),
1361 old_num_acts * sizeof(union xkb_action));
1363 return XkbKeyActionsPtr(keymap, key);