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 *value_rtrn)
121 const LookupEntry *entry;
126 for (entry = tab; entry->name != NULL; entry++) {
127 if (istreq(entry->name, string)) {
128 *value_rtrn = entry->result;
137 valueToString(const LookupEntry tab[], unsigned value)
139 const LookupEntry *entry;
141 for (entry = tab; entry->name != NULL; entry++)
142 if (entry->result == 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, ExprDef *array_ndx, ExprDef *value)
216 return ReportIllegal(keymap, action->type, field);
220 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
221 unsigned field, ExprDef * value, unsigned *flags_inout)
226 if (field == F_ClearLocks)
227 tmp = XkbSA_ClearLocks;
228 else if (field == F_LatchToLock)
229 tmp = XkbSA_LatchToLock;
231 return false; /* WSGO! */
233 if (!ExprResolveBoolean(keymap->ctx, value, &result))
234 return ReportMismatch(keymap, action, field, "boolean");
239 *flags_inout &= ~tmp;
245 CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
246 unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn)
248 if (value->op == EXPR_IDENT) {
250 valStr = xkb_atom_text(keymap->ctx, value->value.str);
251 if (valStr && (istreq(valStr, "usemodmapmods") ||
252 istreq(valStr, "modmapmods"))) {
255 *flags_inout |= XkbSA_UseModMapMods;
260 if (!ExprResolveVModMask(keymap, value, mods_rtrn))
261 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
263 *flags_inout &= ~XkbSA_UseModMapMods;
268 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
269 unsigned field, ExprDef *array_ndx, ExprDef *value)
271 struct xkb_mod_action *act;
276 act = (struct xkb_mod_action *) action;
277 if (array_ndx != NULL) {
282 return ReportActionNotArray(keymap, action->type, field);
289 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
297 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
299 act->real_mods = act->mask = (t2 & 0xff);
300 act->vmods = (t2 >> 8) & 0xffff;
305 return ReportIllegal(keymap, action->type, field);
309 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
310 unsigned field, ExprDef *array_ndx, ExprDef *value)
312 struct xkb_mod_action *act;
316 act = (struct xkb_mod_action *) action;
317 if ((array_ndx != NULL) && (field == F_Modifiers))
318 return ReportActionNotArray(keymap, action->type, field);
322 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
324 act->real_mods = act->mask = (t2 & 0xff);
325 act->vmods = (t2 >> 8) & 0xffff;
330 return ReportIllegal(keymap, action->type, field);
334 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
335 ExprDef * value, unsigned *flags_inout,
336 xkb_group_index_t *grp_rtrn)
340 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
341 *flags_inout &= ~XkbSA_GroupAbsolute;
342 spec = value->value.child;
345 *flags_inout |= XkbSA_GroupAbsolute;
349 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
350 return ReportMismatch(keymap, action, F_Group,
351 "integer (range 1..8)");
353 if (value->op == EXPR_NEGATE)
354 *grp_rtrn = -*grp_rtrn;
355 else if (value->op != EXPR_UNARY_PLUS)
362 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
363 unsigned field, ExprDef *array_ndx, ExprDef *value)
365 struct xkb_group_action *act;
368 xkb_group_index_t t2;
370 act = (struct xkb_group_action *) action;
371 if (array_ndx != NULL) {
376 return ReportActionNotArray(keymap, action->type, field);
383 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
391 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
398 return ReportIllegal(keymap, action->type, field);
402 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
403 unsigned field, ExprDef *array_ndx, ExprDef *value)
405 struct xkb_group_action *act;
407 xkb_group_index_t t2;
409 act = (struct xkb_group_action *) action;
410 if ((array_ndx != NULL) && (field == F_Group))
411 return ReportActionNotArray(keymap, action->type, field);
412 if (field == F_Group) {
414 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
421 return ReportIllegal(keymap, action->type, field);
425 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
426 unsigned field, ExprDef *array_ndx, ExprDef *value)
428 struct xkb_pointer_action *act;
431 act = (struct xkb_pointer_action *) action;
432 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
433 return ReportActionNotArray(keymap, action->type, field);
435 if (field == F_X || field == F_Y) {
438 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
443 if (!ExprResolveInteger(keymap->ctx, value, &val))
444 return ReportMismatch(keymap, action->type, field, "integer");
448 act->flags |= XkbSA_MoveAbsoluteX;
453 act->flags |= XkbSA_MoveAbsoluteY;
459 else if (field == F_Accel) {
462 if (!ExprResolveBoolean(keymap->ctx, value, &set))
463 return ReportMismatch(keymap, action->type, field, "boolean");
466 act->flags &= ~XkbSA_NoAcceleration;
468 act->flags |= XkbSA_NoAcceleration;
471 return ReportIllegal(keymap, action->type, field);
474 static const LookupEntry lockWhich[] = {
476 { "lock", XkbSA_LockNoUnlock },
477 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
478 { "unlock", XkbSA_LockNoLock },
483 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
484 unsigned field, ExprDef *array_ndx, ExprDef *value)
487 struct xkb_pointer_button_action *act;
489 act = (struct xkb_pointer_button_action *) action;
490 if (field == F_Button) {
494 return ReportActionNotArray(keymap, action->type, field);
496 if (!ExprResolveButton(keymap->ctx, value, &btn))
497 return ReportMismatch(keymap, action->type, field,
498 "integer (range 1..5)");
500 if (btn < 0 || btn > 5) {
502 "Button must specify default or be in the range 1..5; "
503 "Illegal button value %d ignored\n", btn);
510 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
511 if (array_ndx != NULL)
512 return ReportActionNotArray(keymap, action->type, field);
513 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
514 return ReportMismatch(keymap, action->type, field,
516 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
517 act->flags |= rtrn.ival;
520 else if (field == F_Count) {
524 return ReportActionNotArray(keymap, action->type, field);
526 /* XXX: Should this actually be ResolveButton? */
527 if (!ExprResolveButton(keymap->ctx, value, &btn))
528 return ReportMismatch(keymap, action->type, field, "integer");
530 if (btn < 0 || btn > 255) {
532 "The count field must have a value in the range 0..255; "
533 "Illegal count %d ignored\n", rtrn.ival);
540 return ReportIllegal(keymap, action->type, field);
543 static const LookupEntry ptrDflts[] = {
544 { "dfltbtn", XkbSA_AffectDfltBtn },
545 { "defaultbutton", XkbSA_AffectDfltBtn },
546 { "button", XkbSA_AffectDfltBtn },
551 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
552 unsigned field, ExprDef *array_ndx, ExprDef *value)
555 struct xkb_pointer_default_action *act;
557 act = (struct xkb_pointer_default_action *) action;
558 if (field == F_Affect) {
559 if (array_ndx != NULL)
560 return ReportActionNotArray(keymap, action->type, field);
561 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
562 return ReportMismatch(keymap, action->type, field,
563 "pointer component");
564 act->affect = rtrn.uval;
567 else if ((field == F_Button) || (field == F_Value)) {
572 return ReportActionNotArray(keymap, action->type, field);
574 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
575 act->flags &= ~XkbSA_DfltBtnAbsolute;
576 button = value->value.child;
579 act->flags |= XkbSA_DfltBtnAbsolute;
583 if (!ExprResolveButton(keymap->ctx, button, &btn))
584 return ReportMismatch(keymap, action->type, field,
585 "integer (range 1..5)");
587 if (btn < 0 || btn > 5) {
589 "New default button value must be in the range 1..5; "
590 "Illegal default button value %d ignored\n", rtrn.ival);
595 "Cannot set default pointer button to \"default\"; "
596 "Illegal default button setting ignored\n");
600 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
604 return ReportIllegal(keymap, action->type, field);
607 static const LookupEntry isoNames[] = {
608 { "mods", XkbSA_ISONoAffectMods },
609 { "modifiers", XkbSA_ISONoAffectMods },
610 { "group", XkbSA_ISONoAffectGroup },
611 { "groups", XkbSA_ISONoAffectGroup },
612 { "ptr", XkbSA_ISONoAffectPtr },
613 { "pointer", XkbSA_ISONoAffectPtr },
614 { "ctrls", XkbSA_ISONoAffectCtrls },
615 { "controls", XkbSA_ISONoAffectCtrls },
616 { "all", ~((unsigned) 0) },
622 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
623 unsigned field, ExprDef *array_ndx, ExprDef *value)
625 struct xkb_iso_action *act;
627 act = (struct xkb_iso_action *) action;
628 if (field == F_Modifiers) {
633 return ReportActionNotArray(keymap, action->type, field);
636 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
639 act->flags = flags & (~XkbSA_ISODfltIsGroup);
640 act->real_mods = mods & 0xff;
641 act->vmods = (mods >> 8) & 0xff;
644 else if (field == F_Group) {
645 xkb_group_index_t group;
649 return ReportActionNotArray(keymap, action->type, field);
652 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
655 act->flags = flags | XkbSA_ISODfltIsGroup;
658 } else if (F_Affect) {
662 return ReportActionNotArray(keymap, action->type, field);
664 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
665 return ReportMismatch(keymap, action->type, field,
666 "keyboard component");
668 act->affect = (~mask) & XkbSA_ISOAffectMask;
672 return ReportIllegal(keymap, action->type, field);
676 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
677 unsigned field, ExprDef *array_ndx, ExprDef *value)
680 struct xkb_switch_screen_action *act;
682 act = (struct xkb_switch_screen_action *) action;
683 if (field == F_Screen) {
688 return ReportActionNotArray(keymap, action->type, field);
690 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
691 act->flags &= ~XkbSA_SwitchAbsolute;
692 scrn = value->value.child;
695 act->flags |= XkbSA_SwitchAbsolute;
699 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
700 return ReportMismatch(keymap, action->type, field,
703 if (val < 0 || val > 255) {
705 "Screen index must be in the range 1..255; "
706 "Illegal screen value %d ignored\n", rtrn.ival);
710 act->screen = (value->op == EXPR_NEGATE ? -val : val);
713 else if (field == F_Same) {
717 return ReportActionNotArray(keymap, action->type, field);
719 if (!ExprResolveBoolean(keymap->ctx, value, &set))
720 return ReportMismatch(keymap, action->type, field, "boolean");
723 act->flags &= ~XkbSA_SwitchApplication;
725 act->flags |= XkbSA_SwitchApplication;
730 return ReportIllegal(keymap, action->type, field);
733 const LookupEntry ctrlNames[] = {
734 { "repeatkeys", XkbRepeatKeysMask },
735 { "repeat", XkbRepeatKeysMask },
736 { "autorepeat", XkbRepeatKeysMask },
737 { "slowkeys", XkbSlowKeysMask },
738 { "bouncekeys", XkbBounceKeysMask },
739 { "stickykeys", XkbStickyKeysMask },
740 { "mousekeys", XkbMouseKeysMask },
741 { "mousekeysaccel", XkbMouseKeysAccelMask },
742 { "accessxkeys", XkbAccessXKeysMask },
743 { "accessxtimeout", XkbAccessXTimeoutMask },
744 { "accessxfeedback", XkbAccessXFeedbackMask },
745 { "audiblebell", XkbAudibleBellMask },
746 { "ignoregrouplock", XkbIgnoreGroupLockMask },
747 { "all", XkbAllBooleanCtrlsMask },
755 HandleSetLockControls(struct xkb_keymap *keymap,
756 struct xkb_any_action *action,
757 unsigned field, ExprDef *array_ndx,
760 struct xkb_controls_action *act;
762 act = (struct xkb_controls_action *) action;
763 if (field == F_Controls) {
767 return ReportActionNotArray(keymap, action->type, field);
769 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
770 return ReportMismatch(keymap, action->type, field,
777 return ReportIllegal(keymap, action->type, field);
780 static const LookupEntry evNames[] = {
781 { "press", XkbSA_MessageOnPress },
782 { "keypress", XkbSA_MessageOnPress },
783 { "release", XkbSA_MessageOnRelease },
784 { "keyrelease", XkbSA_MessageOnRelease },
785 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
791 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
792 unsigned field, ExprDef *array_ndx, ExprDef *value)
794 struct xkb_message_action *act;
796 act = (struct xkb_message_action *) action;
797 if (field == F_Report) {
801 return ReportActionNotArray(keymap, action->type, field);
803 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
804 return ReportMismatch(keymap, action->type, field,
807 /* FIXME: Something seems wrong here... */
808 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
809 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
812 else if (field == F_GenKeyEvent) {
816 return ReportActionNotArray(keymap, action->type, field);
818 if (!ExprResolveBoolean(keymap->ctx, value, &set))
819 return ReportMismatch(keymap, action->type, field, "boolean");
822 act->flags |= XkbSA_MessageGenKeyEvent;
824 act->flags &= ~XkbSA_MessageGenKeyEvent;
828 else if (field == F_Data && !array_ndx) {
832 if (!ExprResolveString(keymap->ctx, value, &str))
833 return ReportMismatch(keymap, action->type, field, "string");
836 if (len < 1 || len > 6) {
837 log_warn(keymap->ctx,
838 "An action message can hold only 6 bytes; "
839 "Extra %d bytes ignored\n", len - 6);
842 strncpy((char *) act->message, str, 6);
845 else if (field == F_Data && array_ndx) {
848 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
850 "Array subscript must be integer; "
851 "Illegal subscript ignored\n");
855 if (ndx < 0 || ndx > 5) {
857 "An action message is at most 6 bytes long; "
858 "Attempt to use data[%d] ignored\n", ndx);
862 if (!ExprResolveInteger(keymap->ctx, value, &datum))
863 return ReportMismatch(keymap, action->type, field, "integer");
865 if (datum < 0 || datum > 255) {
867 "Message data must be in the range 0..255; "
868 "Illegal datum %d ignored\n", datum);
872 act->message[ndx] = (uint8_t) datum;
876 return ReportIllegal(keymap, action->type, field);
880 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
881 unsigned field, ExprDef *array_ndx, ExprDef *value)
884 struct xkb_redirect_key_action *act;
888 char key_name[XkbKeyNameLength];
890 if (array_ndx != NULL)
891 return ReportActionNotArray(keymap, action->type, field);
893 act = (struct xkb_redirect_key_action *) action;
896 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
897 return ReportMismatch(keymap, action->type, field, "key name");
899 tmp = KeyNameToLong(key_name);
900 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
902 return ReportNotFound(keymap, action->type, field, "Key",
903 KeyNameText(key_name));
904 act->new_kc = XkbKeyGetKeycode(keymap, key);
910 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
911 act->mods_mask |= (t2 & 0xff);
912 if (field == F_Modifiers)
913 act->mods |= (t2 & 0xff);
915 act->mods &= ~(t2 & 0xff);
917 t2 = (t2 >> 8) & 0xffff;
918 act->vmods_mask |= t2;
919 if (field == F_Modifiers)
927 return ReportIllegal(keymap, action->type, field);
931 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
932 unsigned field, ExprDef *array_ndx, ExprDef *value)
935 struct xkb_device_button_action *act;
937 act = (struct xkb_device_button_action *) action;
938 if (field == F_Button) {
942 return ReportActionNotArray(keymap, action->type, field);
944 if (!ExprResolveInteger(keymap->ctx, value, &val))
945 return ReportMismatch(keymap, action->type, field,
946 "integer (range 1..255)");
948 if (val < 0 || val > 255) {
950 "Button must specify default or be in the range 1..255; "
951 "Illegal button value %d ignored\n", val);
958 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
959 if (array_ndx != NULL)
960 return ReportActionNotArray(keymap, action->type, field);
961 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
962 return ReportMismatch(keymap, action->type, field,
964 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
965 act->flags |= rtrn.ival;
968 else if (field == F_Count) {
972 return ReportActionNotArray(keymap, action->type, field);
974 /* XXX: Should this actually be ResolveButton? */
975 if (!ExprResolveButton(keymap->ctx, value, &btn))
976 return ReportMismatch(keymap, action->type, field, "integer");
978 if (btn < 0 || btn > 255) {
980 "The count field must have a value in the range 0..255; "
981 "Illegal count %d ignored\n", rtrn.ival);
988 else if (field == F_Device) {
992 return ReportActionNotArray(keymap, action->type, field);
994 if (!ExprResolveInteger(keymap->ctx, value, &val))
995 return ReportMismatch(keymap, action->type, field,
996 "integer (range 1..255)");
998 if (val < 0 || val > 255) {
1000 "Device must specify default or be in the range 1..255; "
1001 "Illegal device value %d ignored\n", val);
1009 return ReportIllegal(keymap, action->type, field);
1013 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
1014 unsigned field, ExprDef *array_ndx, ExprDef *value)
1018 struct xkb_device_valuator_action *act;
1020 act = (struct xkb_device_valuator_action *) action;
1021 /* XXX - Not yet implemented */
1027 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
1028 unsigned field, ExprDef *array_ndx, ExprDef *value)
1030 if (field == F_Type) {
1033 if (!ExprResolveInteger(keymap->ctx, value, &type))
1034 return ReportMismatch(keymap, PrivateAction, field, "integer");
1036 if (type < 0 || type > 255) {
1037 log_err(keymap->ctx,
1038 "Private action type must be in the range 0..255; "
1039 "Illegal type %d ignored\n", type);
1043 action->type = (uint8_t) type;
1046 else if (field == F_Data) {
1047 if (array_ndx == NULL) {
1051 if (!ExprResolveString(keymap->ctx, value, &str))
1052 return ReportMismatch(keymap, action->type, field, "string");
1055 if (len < 1 || len > 7) {
1056 log_warn(keymap->ctx,
1057 "A private action has 7 data bytes; "
1058 "Extra %d bytes ignored\n", len - 6);
1062 strncpy((char *) action->data, str, sizeof(action->data));
1068 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1069 log_err(keymap->ctx,
1070 "Array subscript must be integer; "
1071 "Illegal subscript ignored\n");
1075 if (ndx < 0 || ndx >= sizeof(action->data)) {
1076 log_err(keymap->ctx,
1077 "The data for a private action is %zu bytes long; "
1078 "Attempt to use data[%d] ignored\n",
1079 sizeof(action->data), ndx);
1083 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1084 return ReportMismatch(keymap, action->type, field, "integer");
1086 if (datum < 0 || datum > 255) {
1087 log_err(keymap->ctx,
1088 "All data for a private action must be 0..255; "
1089 "Illegal datum %d ignored\n", datum);
1093 action->data[ndx] = (uint8_t) datum;
1098 return ReportIllegal(keymap, PrivateAction, field);
1101 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1102 struct xkb_any_action *action, unsigned field,
1103 ExprDef *array_ndx, ExprDef *value);
1105 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1106 [XkbSA_NoAction] = HandleNoAction,
1107 [XkbSA_SetMods] = HandleSetLatchMods,
1108 [XkbSA_LatchMods] = HandleSetLatchMods,
1109 [XkbSA_LockMods] = HandleLockMods,
1110 [XkbSA_SetGroup] = HandleSetLatchGroup,
1111 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1112 [XkbSA_LockGroup] = HandleLockGroup,
1113 [XkbSA_MovePtr] = HandleMovePtr,
1114 [XkbSA_PtrBtn] = HandlePtrBtn,
1115 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1116 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1117 [XkbSA_ISOLock] = HandleISOLock,
1118 [XkbSA_Terminate] = HandleNoAction,
1119 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1120 [XkbSA_SetControls] = HandleSetLockControls,
1121 [XkbSA_LockControls] = HandleSetLockControls,
1122 [XkbSA_ActionMessage] = HandleActionMessage,
1123 [XkbSA_RedirectKey] = HandleRedirectKey,
1124 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1125 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1126 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1127 [PrivateAction] = HandlePrivate,
1130 /***====================================================================***/
1133 ApplyActionFactoryDefaults(union xkb_action * action)
1135 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1136 action->dflt.affect = XkbSA_AffectDfltBtn;
1137 action->dflt.flags = 0;
1138 action->dflt.value = 1;
1140 else if (action->type == XkbSA_ISOLock) {
1141 action->iso.real_mods = LockMask;
1146 ActionsInit(struct xkb_context *ctx);
1149 HandleActionDef(ExprDef * def,
1150 struct xkb_keymap *keymap,
1151 struct xkb_any_action *action, ActionInfo *info)
1155 unsigned tmp, hndlrType;
1157 if (!actionsInitialized)
1158 ActionsInit(keymap->ctx);
1160 if (def->op != EXPR_ACTION_DECL) {
1161 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1162 exprOpText(def->op));
1165 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1167 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1170 if (!stringToAction(str, &tmp)) {
1171 log_err(keymap->ctx, "Unknown action %s\n", str);
1174 action->type = hndlrType = tmp;
1175 if (action->type != XkbSA_NoAction) {
1176 ApplyActionFactoryDefaults((union xkb_action *) action);
1179 if ((info->action == XkbSA_NoAction)
1180 || (info->action == hndlrType)) {
1181 if (!(*handleAction[hndlrType])(keymap, action,
1191 for (arg = def->value.action.args; arg != NULL;
1192 arg = (ExprDef *) arg->common.next) {
1193 ExprDef *field, *value, *arrayRtrn;
1194 const char *elemRtrn, *fieldRtrn;
1197 if (arg->op == EXPR_ASSIGN) {
1198 field = arg->value.binary.left;
1199 value = arg->value.binary.right;
1202 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1203 field = arg->value.child;
1204 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1205 value = &constFalse;
1209 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1213 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1215 return false; /* internal error -- already reported */
1217 if (elemRtrn != NULL) {
1218 log_err(keymap->ctx,
1219 "Cannot change defaults in an action definition; "
1220 "Ignoring attempt to change %s.%s\n",
1221 elemRtrn, fieldRtrn);
1224 if (!stringToField(fieldRtrn, &fieldNdx)) {
1225 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1228 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1235 /***====================================================================***/
1238 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1239 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1241 ActionInfo *new, *old;
1243 if (!actionsInitialized)
1244 ActionsInit(keymap->ctx);
1246 new = malloc(sizeof(*new));
1248 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1252 if (istreq(elem, "action"))
1253 new->action = XkbSA_NoAction;
1255 if (!stringToAction(elem, &new->action)) {
1259 if (new->action == XkbSA_NoAction) {
1260 log_err(keymap->ctx,
1261 "\"%s\" is not a valid field in a NoAction action\n",
1267 if (!stringToField(field, &new->field)) {
1268 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1272 new->array_ndx = array_ndx;
1276 while ((old) && (old->next))
1285 /***====================================================================***/
1288 ActionsInit(struct xkb_context *ctx)
1290 if (!actionsInitialized) {
1291 memset(&constTrue, 0, sizeof(constTrue));
1292 memset(&constFalse, 0, sizeof(constFalse));
1293 constTrue.common.type = STMT_EXPR;
1294 constTrue.common.next = NULL;
1295 constTrue.op = EXPR_IDENT;
1296 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1297 constTrue.value.str = xkb_atom_intern(ctx, "true");
1298 constFalse.common.type = STMT_EXPR;
1299 constFalse.common.next = NULL;
1300 constFalse.op = EXPR_IDENT;
1301 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1302 constFalse.value.str = xkb_atom_intern(ctx, "false");
1303 actionsInitialized = 1;
1308 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1311 size_t old_ndx, old_num_acts, new_ndx;
1314 key->acts_index = 0;
1318 if (XkbKeyHasActions(key) && key->width >= needed)
1319 return XkbKeyActionsPtr(keymap, key);
1322 * The key may already be in the array, but without enough space.
1323 * This should not happen often, so in order to avoid moving and
1324 * copying stuff from acts and key_acts, we just allocate new
1325 * space for the key at the end, and leave the old space alone.
1328 old_ndx = key->acts_index;
1329 old_num_acts = XkbKeyNumActions(key);
1330 new_ndx = darray_size(keymap->acts);
1332 darray_resize0(keymap->acts, new_ndx + needed);
1333 key->acts_index = new_ndx;
1336 * The key was already in the array, copy the old actions to the
1340 memcpy(darray_mem(keymap->acts, new_ndx),
1341 darray_mem(keymap->acts, old_ndx),
1342 old_num_acts * sizeof(union xkb_action));
1344 return XkbKeyActionsPtr(keymap, key);