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 },
48 ACTION_FIELD_CLEAR_LOCKS,
49 ACTION_FIELD_LATCH_TO_LOCK,
50 ACTION_FIELD_GEN_KEY_EVENT,
54 ACTION_FIELD_INCREMENT,
55 ACTION_FIELD_MODIFIERS,
62 ACTION_FIELD_CONTROLS,
70 ACTION_FIELD_MODS_TO_CLEAR,
79 info = calloc(1, sizeof(*info));
83 /* This includes PrivateAction. */
84 for (type = 0; type < XkbSA_NumActions + 1; type++)
85 info->actions[type].type = type;
87 /* Apply some "factory defaults". */
89 /* Increment default button. */
90 info->actions[XkbSA_SetPtrDflt].dflt.affect = XkbSA_AffectDfltBtn;
91 info->actions[XkbSA_SetPtrDflt].dflt.flags = 0;
92 info->actions[XkbSA_SetPtrDflt].dflt.value = 1;
94 info->actions[XkbSA_ISOLock].iso.mods.mods =
95 (1 << ModNameToIndex(XKB_MOD_NAME_CAPS));
101 FreeActionsInfo(ActionsInfo *info)
106 static const LookupEntry fieldStrings[] = {
107 { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
108 { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
109 { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
110 { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
111 { "report", ACTION_FIELD_REPORT },
112 { "default", ACTION_FIELD_DEFAULT },
113 { "affect", ACTION_FIELD_AFFECT },
114 { "increment", ACTION_FIELD_INCREMENT },
115 { "modifiers", ACTION_FIELD_MODIFIERS },
116 { "mods", ACTION_FIELD_MODIFIERS },
117 { "group", ACTION_FIELD_GROUP },
118 { "x", ACTION_FIELD_X },
119 { "y", ACTION_FIELD_Y },
120 { "accel", ACTION_FIELD_ACCEL },
121 { "accelerate", ACTION_FIELD_ACCEL },
122 { "repeat", ACTION_FIELD_ACCEL },
123 { "button", ACTION_FIELD_BUTTON },
124 { "value", ACTION_FIELD_VALUE },
125 { "controls", ACTION_FIELD_CONTROLS },
126 { "ctrls", ACTION_FIELD_CONTROLS },
127 { "type", ACTION_FIELD_TYPE },
128 { "count", ACTION_FIELD_COUNT },
129 { "screen", ACTION_FIELD_SCREEN },
130 { "same", ACTION_FIELD_SAME },
131 { "sameServer", ACTION_FIELD_SAME },
132 { "data", ACTION_FIELD_DATA },
133 { "device", ACTION_FIELD_DEVICE },
134 { "dev", ACTION_FIELD_DEVICE },
135 { "key", ACTION_FIELD_KEYCODE },
136 { "keycode", ACTION_FIELD_KEYCODE },
137 { "kc", ACTION_FIELD_KEYCODE },
138 { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
139 { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
144 stringToAction(const char *str, unsigned *type_rtrn)
146 return LookupString(actionTypeNames, str, type_rtrn);
150 stringToField(const char *str, enum action_field *field_rtrn)
152 return LookupString(fieldStrings, str, field_rtrn);
156 fieldText(enum action_field field)
158 return LookupValue(fieldStrings, field);
161 /***====================================================================***/
164 ReportMismatch(struct xkb_keymap *keymap, unsigned action,
165 enum action_field field, const char *type)
168 "Value of %s field must be of type %s; "
169 "Action %s definition ignored\n",
170 fieldText(field), type, ActionTypeText(action));
175 ReportIllegal(struct xkb_keymap *keymap, unsigned action,
176 enum action_field field)
179 "Field %s is not defined for an action of type %s; "
180 "Action definition ignored\n",
181 fieldText(field), ActionTypeText(action));
186 ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
187 enum action_field field)
190 "The %s field in the %s action is not an array; "
191 "Action definition ignored\n",
192 fieldText(field), ActionTypeText(action));
197 ReportNotFound(struct xkb_keymap *keymap, unsigned action,
198 enum action_field field, const char *what, const char *bad)
201 "%s named %s not found; "
202 "Ignoring the %s field of an %s action\n",
203 what, bad, fieldText(field), ActionTypeText(action));
208 HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
209 enum action_field field, const ExprDef *array_ndx,
210 const ExprDef *value)
213 return ReportIllegal(keymap, action->type, field);
217 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
218 enum action_field field, const ExprDef * value,
219 unsigned *flags_inout)
224 if (field == ACTION_FIELD_CLEAR_LOCKS)
225 tmp = XkbSA_ClearLocks;
226 else if (field == ACTION_FIELD_LATCH_TO_LOCK)
227 tmp = XkbSA_LatchToLock;
229 return false; /* WSGO! */
231 if (!ExprResolveBoolean(keymap->ctx, value, &result))
232 return ReportMismatch(keymap, action, field, "boolean");
237 *flags_inout &= ~tmp;
243 CheckModifierField(struct xkb_keymap *keymap, unsigned action,
244 const ExprDef *value, unsigned *flags_inout,
245 xkb_mod_mask_t *mods_rtrn)
247 if (value->op == EXPR_IDENT) {
249 valStr = xkb_atom_text(keymap->ctx, value->value.str);
250 if (valStr && (istreq(valStr, "usemodmapmods") ||
251 istreq(valStr, "modmapmods"))) {
254 *flags_inout |= XkbSA_UseModMapMods;
259 if (!ExprResolveVModMask(keymap, value, mods_rtrn))
260 return ReportMismatch(keymap, action,
261 ACTION_FIELD_MODIFIERS, "modifier mask");
263 *flags_inout &= ~XkbSA_UseModMapMods;
268 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
269 enum action_field field, const ExprDef *array_ndx,
270 const ExprDef *value)
272 struct xkb_mod_action *act = &action->mods;
277 if (array_ndx != NULL) {
279 case ACTION_FIELD_CLEAR_LOCKS:
280 case ACTION_FIELD_LATCH_TO_LOCK:
281 case ACTION_FIELD_MODIFIERS:
282 return ReportActionNotArray(keymap, action->type, field);
289 case ACTION_FIELD_CLEAR_LOCKS:
290 case ACTION_FIELD_LATCH_TO_LOCK:
292 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
298 case ACTION_FIELD_MODIFIERS:
300 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
311 return ReportIllegal(keymap, action->type, field);
315 HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
316 enum action_field field, const ExprDef *array_ndx,
317 const ExprDef *value)
319 struct xkb_mod_action *act = &action->mods;
323 if (array_ndx && field == ACTION_FIELD_MODIFIERS)
324 return ReportActionNotArray(keymap, action->type, field);
327 case ACTION_FIELD_MODIFIERS:
329 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
340 return ReportIllegal(keymap, action->type, field);
344 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
345 const ExprDef *value, unsigned *flags_inout,
346 xkb_group_index_t *grp_rtrn)
350 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
351 *flags_inout &= ~XkbSA_GroupAbsolute;
352 spec = value->value.child;
355 *flags_inout |= XkbSA_GroupAbsolute;
359 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
360 return ReportMismatch(keymap, action, ACTION_FIELD_GROUP,
361 "integer (range 1..8)");
363 if (value->op == EXPR_NEGATE)
364 *grp_rtrn = -*grp_rtrn;
365 else if (value->op != EXPR_UNARY_PLUS)
372 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
373 enum action_field field, const ExprDef *array_ndx,
374 const ExprDef *value)
376 struct xkb_group_action *act = &action->group;
379 xkb_group_index_t t2;
381 if (array_ndx != NULL) {
383 case ACTION_FIELD_CLEAR_LOCKS:
384 case ACTION_FIELD_LATCH_TO_LOCK:
385 case ACTION_FIELD_GROUP:
386 return ReportActionNotArray(keymap, action->type, field);
394 case ACTION_FIELD_CLEAR_LOCKS:
395 case ACTION_FIELD_LATCH_TO_LOCK:
397 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
403 case ACTION_FIELD_GROUP:
405 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
416 return ReportIllegal(keymap, action->type, field);
420 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
421 enum action_field field, const ExprDef *array_ndx,
422 const ExprDef *value)
424 struct xkb_group_action *act = &action->group;
426 xkb_group_index_t t2;
428 if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
429 return ReportActionNotArray(keymap, action->type, field);
430 if (field == ACTION_FIELD_GROUP) {
432 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
439 return ReportIllegal(keymap, action->type, field);
443 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
444 enum action_field field, const ExprDef *array_ndx,
445 const ExprDef *value)
447 struct xkb_pointer_action *act = &action->ptr;
450 if (array_ndx && (field == ACTION_FIELD_X || field == ACTION_FIELD_Y))
451 return ReportActionNotArray(keymap, action->type, field);
453 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
456 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
461 if (!ExprResolveInteger(keymap->ctx, value, &val))
462 return ReportMismatch(keymap, action->type, field, "integer");
464 if (field == ACTION_FIELD_X) {
466 act->flags |= XkbSA_MoveAbsoluteX;
471 act->flags |= XkbSA_MoveAbsoluteY;
477 else if (field == ACTION_FIELD_ACCEL) {
480 if (!ExprResolveBoolean(keymap->ctx, value, &set))
481 return ReportMismatch(keymap, action->type, field, "boolean");
484 act->flags &= ~XkbSA_NoAcceleration;
486 act->flags |= XkbSA_NoAcceleration;
489 return ReportIllegal(keymap, action->type, field);
492 static const LookupEntry lockWhich[] = {
494 { "lock", XkbSA_LockNoUnlock },
495 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
496 { "unlock", XkbSA_LockNoLock },
501 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
502 enum action_field field, const ExprDef *array_ndx,
503 const ExprDef *value)
505 struct xkb_pointer_button_action *act = &action->btn;
507 if (field == ACTION_FIELD_BUTTON) {
511 return ReportActionNotArray(keymap, action->type, field);
513 if (!ExprResolveButton(keymap->ctx, value, &btn))
514 return ReportMismatch(keymap, action->type, field,
515 "integer (range 1..5)");
517 if (btn < 0 || btn > 5) {
519 "Button must specify default or be in the range 1..5; "
520 "Illegal button value %d ignored\n", btn);
527 else if (action->type == XkbSA_LockPtrBtn &&
528 field == ACTION_FIELD_AFFECT) {
532 return ReportActionNotArray(keymap, action->type, field);
534 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
535 return ReportMismatch(keymap, action->type, field,
538 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
542 else if (field == ACTION_FIELD_COUNT) {
546 return ReportActionNotArray(keymap, action->type, field);
548 /* XXX: Should this actually be ResolveButton? */
549 if (!ExprResolveButton(keymap->ctx, value, &btn))
550 return ReportMismatch(keymap, action->type, field, "integer");
552 if (btn < 0 || btn > 255) {
554 "The count field must have a value in the range 0..255; "
555 "Illegal count %d ignored\n", btn);
562 return ReportIllegal(keymap, action->type, field);
565 static const LookupEntry ptrDflts[] = {
566 { "dfltbtn", XkbSA_AffectDfltBtn },
567 { "defaultbutton", XkbSA_AffectDfltBtn },
568 { "button", XkbSA_AffectDfltBtn },
573 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
574 enum action_field field, const ExprDef *array_ndx,
575 const ExprDef *value)
577 struct xkb_pointer_default_action *act = &action->dflt;
579 if (field == ACTION_FIELD_AFFECT) {
583 return ReportActionNotArray(keymap, action->type, field);
585 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
586 return ReportMismatch(keymap, action->type, field,
587 "pointer component");
591 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
592 const ExprDef *button;
596 return ReportActionNotArray(keymap, action->type, field);
598 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
599 act->flags &= ~XkbSA_DfltBtnAbsolute;
600 button = value->value.child;
603 act->flags |= XkbSA_DfltBtnAbsolute;
607 if (!ExprResolveButton(keymap->ctx, button, &btn))
608 return ReportMismatch(keymap, action->type, field,
609 "integer (range 1..5)");
611 if (btn < 0 || btn > 5) {
613 "New default button value must be in the range 1..5; "
614 "Illegal default button value %d ignored\n", btn);
619 "Cannot set default pointer button to \"default\"; "
620 "Illegal default button setting ignored\n");
624 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
628 return ReportIllegal(keymap, action->type, field);
631 static const LookupEntry isoNames[] = {
632 { "mods", XkbSA_ISONoAffectMods },
633 { "modifiers", XkbSA_ISONoAffectMods },
634 { "group", XkbSA_ISONoAffectGroup },
635 { "groups", XkbSA_ISONoAffectGroup },
636 { "ptr", XkbSA_ISONoAffectPtr },
637 { "pointer", XkbSA_ISONoAffectPtr },
638 { "ctrls", XkbSA_ISONoAffectCtrls },
639 { "controls", XkbSA_ISONoAffectCtrls },
640 { "all", ~((unsigned) 0) },
646 HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
647 enum action_field field, const ExprDef *array_ndx,
648 const ExprDef *value)
650 struct xkb_iso_action *act = &action->iso;
652 if (field == ACTION_FIELD_MODIFIERS) {
657 return ReportActionNotArray(keymap, action->type, field);
660 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
663 act->flags = flags & (~XkbSA_ISODfltIsGroup);
664 act->mods.mods = mods;
667 else if (field == ACTION_FIELD_GROUP) {
668 xkb_group_index_t group;
672 return ReportActionNotArray(keymap, action->type, field);
675 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
678 act->flags = flags | XkbSA_ISODfltIsGroup;
681 } else if (ACTION_FIELD_AFFECT) {
685 return ReportActionNotArray(keymap, action->type, field);
687 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
688 return ReportMismatch(keymap, action->type, field,
689 "keyboard component");
691 act->affect = (~mask) & XkbSA_ISOAffectMask;
695 return ReportIllegal(keymap, action->type, field);
699 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
700 enum action_field field, const ExprDef *array_ndx,
701 const ExprDef *value)
703 struct xkb_switch_screen_action *act = &action->screen;
705 if (field == ACTION_FIELD_SCREEN) {
710 return ReportActionNotArray(keymap, action->type, field);
712 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
713 act->flags &= ~XkbSA_SwitchAbsolute;
714 scrn = value->value.child;
717 act->flags |= XkbSA_SwitchAbsolute;
721 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
722 return ReportMismatch(keymap, action->type, field,
725 if (val < 0 || val > 255) {
727 "Screen index must be in the range 1..255; "
728 "Illegal screen value %d ignored\n", val);
732 act->screen = (value->op == EXPR_NEGATE ? -val : val);
735 else if (field == ACTION_FIELD_SAME) {
739 return ReportActionNotArray(keymap, action->type, field);
741 if (!ExprResolveBoolean(keymap->ctx, value, &set))
742 return ReportMismatch(keymap, action->type, field, "boolean");
745 act->flags &= ~XkbSA_SwitchApplication;
747 act->flags |= XkbSA_SwitchApplication;
752 return ReportIllegal(keymap, action->type, field);
756 HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
757 enum action_field field, const ExprDef *array_ndx,
758 const ExprDef *value)
760 struct xkb_controls_action *act = &action->ctrls;
762 if (field == ACTION_FIELD_CONTROLS) {
766 return ReportActionNotArray(keymap, action->type, field);
768 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
769 return ReportMismatch(keymap, action->type, field,
776 return ReportIllegal(keymap, action->type, field);
779 static const LookupEntry evNames[] = {
780 { "press", XkbSA_MessageOnPress },
781 { "keypress", XkbSA_MessageOnPress },
782 { "release", XkbSA_MessageOnRelease },
783 { "keyrelease", XkbSA_MessageOnRelease },
784 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
790 HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
791 enum action_field field, const ExprDef *array_ndx,
792 const ExprDef *value)
794 struct xkb_message_action *act = &action->msg;
796 if (field == ACTION_FIELD_REPORT) {
800 return ReportActionNotArray(keymap, action->type, field);
802 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
803 return ReportMismatch(keymap, action->type, field,
806 /* FIXME: Something seems wrong here... */
807 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
808 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
811 else if (field == ACTION_FIELD_GEN_KEY_EVENT) {
815 return ReportActionNotArray(keymap, action->type, field);
817 if (!ExprResolveBoolean(keymap->ctx, value, &set))
818 return ReportMismatch(keymap, action->type, field, "boolean");
821 act->flags |= XkbSA_MessageGenKeyEvent;
823 act->flags &= ~XkbSA_MessageGenKeyEvent;
827 else if (field == ACTION_FIELD_DATA && !array_ndx) {
832 if (!ExprResolveString(keymap->ctx, value, &val))
833 return ReportMismatch(keymap, action->type, field, "string");
835 str = xkb_atom_text(keymap->ctx, val);
837 if (len < 1 || len > 6) {
838 log_warn(keymap->ctx,
839 "An action message can hold only 6 bytes; "
840 "Extra %d bytes ignored\n", len - 6);
843 strncpy((char *) act->message, str, 6);
846 else if (field == ACTION_FIELD_DATA && array_ndx) {
849 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
851 "Array subscript must be integer; "
852 "Illegal subscript ignored\n");
856 if (ndx < 0 || ndx > 5) {
858 "An action message is at most 6 bytes long; "
859 "Attempt to use data[%d] ignored\n", ndx);
863 if (!ExprResolveInteger(keymap->ctx, value, &datum))
864 return ReportMismatch(keymap, action->type, field, "integer");
866 if (datum < 0 || datum > 255) {
868 "Message data must be in the range 0..255; "
869 "Illegal datum %d ignored\n", datum);
873 act->message[ndx] = (uint8_t) datum;
877 return ReportIllegal(keymap, action->type, field);
881 HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
882 enum action_field field, const ExprDef *array_ndx,
883 const ExprDef *value)
886 struct xkb_redirect_key_action *act = &action->redirect;
890 char key_name[XKB_KEY_NAME_LENGTH];
892 if (array_ndx != NULL)
893 return ReportActionNotArray(keymap, action->type, field);
896 case ACTION_FIELD_KEYCODE:
897 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
898 return ReportMismatch(keymap, action->type, field, "key name");
900 tmp = KeyNameToLong(key_name);
901 key = FindNamedKey(keymap, tmp, true, 0);
903 return ReportNotFound(keymap, action->type, field, "Key",
904 KeyNameText(key_name));
905 act->new_kc = XkbKeyGetKeycode(keymap, key);
908 case ACTION_FIELD_MODS_TO_CLEAR:
909 case ACTION_FIELD_MODIFIERS:
911 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
912 act->mods_mask |= (t2 & 0xff);
913 if (field == ACTION_FIELD_MODIFIERS)
914 act->mods |= (t2 & 0xff);
916 act->mods &= ~(t2 & 0xff);
918 t2 = (t2 >> XKB_NUM_CORE_MODS) & 0xffff;
919 act->vmods_mask |= t2;
920 if (field == ACTION_FIELD_MODIFIERS)
932 return ReportIllegal(keymap, action->type, field);
936 HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
937 enum action_field field, const ExprDef *array_ndx,
938 const ExprDef *value)
940 struct xkb_device_button_action *act = &action->devbtn;
942 if (field == ACTION_FIELD_BUTTON) {
946 return ReportActionNotArray(keymap, action->type, field);
948 if (!ExprResolveInteger(keymap->ctx, value, &val))
949 return ReportMismatch(keymap, action->type, field,
950 "integer (range 1..255)");
952 if (val < 0 || val > 255) {
954 "Button must specify default or be in the range 1..255; "
955 "Illegal button value %d ignored\n", val);
962 else if (action->type == XkbSA_LockDeviceBtn &&
963 field == ACTION_FIELD_AFFECT) {
967 return ReportActionNotArray(keymap, action->type, field);
969 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
970 return ReportMismatch(keymap, action->type, field,
973 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
977 else if (field == ACTION_FIELD_COUNT) {
981 return ReportActionNotArray(keymap, action->type, field);
983 /* XXX: Should this actually be ResolveButton? */
984 if (!ExprResolveButton(keymap->ctx, value, &btn))
985 return ReportMismatch(keymap, action->type, field, "integer");
987 if (btn < 0 || btn > 255) {
989 "The count field must have a value in the range 0..255; "
990 "Illegal count %d ignored\n", btn);
997 else if (field == ACTION_FIELD_DEVICE) {
1001 return ReportActionNotArray(keymap, action->type, field);
1003 if (!ExprResolveInteger(keymap->ctx, value, &val))
1004 return ReportMismatch(keymap, action->type, field,
1005 "integer (range 1..255)");
1007 if (val < 0 || val > 255) {
1008 log_err(keymap->ctx,
1009 "Device must specify default or be in the range 1..255; "
1010 "Illegal device value %d ignored\n", val);
1018 return ReportIllegal(keymap, action->type, field);
1022 HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
1023 enum action_field field, const ExprDef *array_ndx,
1024 const ExprDef *value)
1026 struct xkb_device_valuator_action *act = &action->devval;
1029 /* XXX - Not yet implemented */
1034 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
1035 enum action_field field, const ExprDef *array_ndx,
1036 const ExprDef *value)
1038 struct xkb_private_action *act = &action->priv;
1040 if (field == ACTION_FIELD_TYPE) {
1043 if (!ExprResolveInteger(keymap->ctx, value, &type))
1044 return ReportMismatch(keymap, PrivateAction, field, "integer");
1046 if (type < 0 || type > 255) {
1047 log_err(keymap->ctx,
1048 "Private action type must be in the range 0..255; "
1049 "Illegal type %d ignored\n", type);
1053 act->type = (uint8_t) type;
1056 else if (field == ACTION_FIELD_DATA) {
1057 if (array_ndx == NULL) {
1062 if (!ExprResolveString(keymap->ctx, value, &val))
1063 return ReportMismatch(keymap, action->type, field, "string");
1065 str = xkb_atom_text(keymap->ctx, val);
1067 if (len < 1 || len > 7) {
1068 log_warn(keymap->ctx,
1069 "A private action has 7 data bytes; "
1070 "Extra %d bytes ignored\n", len - 6);
1074 strncpy((char *) act->data, str, sizeof(act->data));
1080 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1081 log_err(keymap->ctx,
1082 "Array subscript must be integer; "
1083 "Illegal subscript ignored\n");
1087 if (ndx < 0 || ndx >= sizeof(act->data)) {
1088 log_err(keymap->ctx,
1089 "The data for a private action is %zu bytes long; "
1090 "Attempt to use data[%d] ignored\n",
1091 sizeof(act->data), ndx);
1095 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1096 return ReportMismatch(keymap, act->type, field, "integer");
1098 if (datum < 0 || datum > 255) {
1099 log_err(keymap->ctx,
1100 "All data for a private action must be 0..255; "
1101 "Illegal datum %d ignored\n", datum);
1105 act->data[ndx] = (uint8_t) datum;
1110 return ReportIllegal(keymap, PrivateAction, field);
1113 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1114 union xkb_action *action,
1115 enum action_field field,
1116 const ExprDef *array_ndx,
1117 const ExprDef *value);
1119 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1120 [XkbSA_NoAction] = HandleNoAction,
1121 [XkbSA_SetMods] = HandleSetLatchMods,
1122 [XkbSA_LatchMods] = HandleSetLatchMods,
1123 [XkbSA_LockMods] = HandleLockMods,
1124 [XkbSA_SetGroup] = HandleSetLatchGroup,
1125 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1126 [XkbSA_LockGroup] = HandleLockGroup,
1127 [XkbSA_MovePtr] = HandleMovePtr,
1128 [XkbSA_PtrBtn] = HandlePtrBtn,
1129 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1130 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1131 [XkbSA_ISOLock] = HandleISOLock,
1132 [XkbSA_Terminate] = HandleNoAction,
1133 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1134 [XkbSA_SetControls] = HandleSetLockControls,
1135 [XkbSA_LockControls] = HandleSetLockControls,
1136 [XkbSA_ActionMessage] = HandleActionMessage,
1137 [XkbSA_RedirectKey] = HandleRedirectKey,
1138 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1139 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1140 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1141 [PrivateAction] = HandlePrivate,
1144 /***====================================================================***/
1147 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
1148 union xkb_action *action, ActionsInfo *info)
1154 if (def->op != EXPR_ACTION_DECL) {
1155 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1156 expr_op_type_to_string(def->op));
1160 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1161 if (!stringToAction(str, &hndlrType)) {
1162 log_err(keymap->ctx, "Unknown action %s\n", str);
1167 * Get the default values for this action type, as modified by
1168 * statements such as:
1169 * latchMods.clearLocks = True;
1171 *action = info->actions[hndlrType];
1174 * Now change the action properties as specified for this
1175 * particular instance, e.g. "modifiers" and "clearLocks" in:
1176 * SetMods(modifiers=Alt,clearLocks);
1178 for (arg = def->value.action.args; arg != NULL;
1179 arg = (ExprDef *) arg->common.next) {
1180 const ExprDef *value;
1181 ExprDef *field, *arrayRtrn;
1182 const char *elemRtrn, *fieldRtrn;
1183 enum action_field fieldNdx;
1185 if (arg->op == EXPR_ASSIGN) {
1186 field = arg->value.binary.left;
1187 value = arg->value.binary.right;
1189 else if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1190 field = arg->value.child;
1191 value = &constFalse;
1198 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1203 log_err(keymap->ctx,
1204 "Cannot change defaults in an action definition; "
1205 "Ignoring attempt to change %s.%s\n",
1206 elemRtrn, fieldRtrn);
1210 if (!stringToField(fieldRtrn, &fieldNdx)) {
1211 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1215 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1225 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1226 ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
1229 enum action_field action_field;
1231 if (!stringToAction(elem, &action))
1234 if (!stringToField(field, &action_field)) {
1235 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1239 return handleAction[action](keymap, &info->actions[action],
1240 action_field, array_ndx, value);