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 #define PrivateAction (XkbSA_LastAction + 1)
35 static const ExprDef constTrue = {
36 .common = { .type = STMT_EXPR, .next = NULL },
38 .value_type = EXPR_TYPE_BOOLEAN,
39 .value = { .ival = 1 },
42 static const ExprDef constFalse = {
43 .common = { .type = STMT_EXPR, .next = NULL },
45 .value_type = EXPR_TYPE_BOOLEAN,
46 .value = { .ival = 0 },
50 ACTION_FIELD_CLEAR_LOCKS,
51 ACTION_FIELD_LATCH_TO_LOCK,
52 ACTION_FIELD_GEN_KEY_EVENT,
56 ACTION_FIELD_INCREMENT,
57 ACTION_FIELD_MODIFIERS,
64 ACTION_FIELD_CONTROLS,
72 ACTION_FIELD_MODS_TO_CLEAR,
77 enum action_field field;
80 struct _ActionInfo *next;
84 FreeActionInfo(ActionInfo *info)
94 static const LookupEntry actionStrings[] = {
95 { "noaction", XkbSA_NoAction },
96 { "setmods", XkbSA_SetMods },
97 { "latchmods", XkbSA_LatchMods },
98 { "lockmods", XkbSA_LockMods },
99 { "setgroup", XkbSA_SetGroup },
100 { "latchgroup", XkbSA_LatchGroup },
101 { "lockgroup", XkbSA_LockGroup },
102 { "moveptr", XkbSA_MovePtr },
103 { "movepointer", XkbSA_MovePtr },
104 { "ptrbtn", XkbSA_PtrBtn },
105 { "pointerbutton", XkbSA_PtrBtn },
106 { "lockptrbtn", XkbSA_LockPtrBtn },
107 { "lockpointerbutton", XkbSA_LockPtrBtn },
108 { "lockptrbutton", XkbSA_LockPtrBtn },
109 { "lockpointerbtn", XkbSA_LockPtrBtn },
110 { "setptrdflt", XkbSA_SetPtrDflt },
111 { "setpointerdefault", XkbSA_SetPtrDflt },
112 { "isolock", XkbSA_ISOLock },
113 { "terminate", XkbSA_Terminate },
114 { "terminateserver", XkbSA_Terminate },
115 { "switchscreen", XkbSA_SwitchScreen },
116 { "setcontrols", XkbSA_SetControls },
117 { "lockcontrols", XkbSA_LockControls },
118 { "actionmessage", XkbSA_ActionMessage },
119 { "messageaction", XkbSA_ActionMessage },
120 { "message", XkbSA_ActionMessage },
121 { "redirect", XkbSA_RedirectKey },
122 { "redirectkey", XkbSA_RedirectKey },
123 { "devbtn", XkbSA_DeviceBtn },
124 { "devicebtn", XkbSA_DeviceBtn },
125 { "devbutton", XkbSA_DeviceBtn },
126 { "devicebutton", XkbSA_DeviceBtn },
127 { "lockdevbtn", XkbSA_DeviceBtn },
128 { "lockdevicebtn", XkbSA_LockDeviceBtn },
129 { "lockdevbutton", XkbSA_LockDeviceBtn },
130 { "lockdevicebutton", XkbSA_LockDeviceBtn },
131 { "devval", XkbSA_DeviceValuator },
132 { "deviceval", XkbSA_DeviceValuator },
133 { "devvaluator", XkbSA_DeviceValuator },
134 { "devicevaluator", XkbSA_DeviceValuator },
135 { "private", PrivateAction },
139 static const LookupEntry fieldStrings[] = {
140 { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
141 { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
142 { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
143 { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
144 { "report", ACTION_FIELD_REPORT },
145 { "default", ACTION_FIELD_DEFAULT },
146 { "affect", ACTION_FIELD_AFFECT },
147 { "increment", ACTION_FIELD_INCREMENT },
148 { "modifiers", ACTION_FIELD_MODIFIERS },
149 { "mods", ACTION_FIELD_MODIFIERS },
150 { "group", ACTION_FIELD_GROUP },
151 { "x", ACTION_FIELD_X },
152 { "y", ACTION_FIELD_Y },
153 { "accel", ACTION_FIELD_ACCEL },
154 { "accelerate", ACTION_FIELD_ACCEL },
155 { "repeat", ACTION_FIELD_ACCEL },
156 { "button", ACTION_FIELD_BUTTON },
157 { "value", ACTION_FIELD_VALUE },
158 { "controls", ACTION_FIELD_CONTROLS },
159 { "ctrls", ACTION_FIELD_CONTROLS },
160 { "type", ACTION_FIELD_TYPE },
161 { "count", ACTION_FIELD_COUNT },
162 { "screen", ACTION_FIELD_SCREEN },
163 { "same", ACTION_FIELD_SAME },
164 { "sameServer", ACTION_FIELD_SAME },
165 { "data", ACTION_FIELD_DATA },
166 { "device", ACTION_FIELD_DEVICE },
167 { "dev", ACTION_FIELD_DEVICE },
168 { "key", ACTION_FIELD_KEYCODE },
169 { "keycode", ACTION_FIELD_KEYCODE },
170 { "kc", ACTION_FIELD_KEYCODE },
171 { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
172 { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
177 stringToValue(const LookupEntry tab[], const char *string,
178 unsigned int *value_rtrn)
180 const LookupEntry *entry;
185 for (entry = tab; entry->name; entry++) {
186 if (istreq(entry->name, string)) {
187 *value_rtrn = entry->value;
196 valueToString(const LookupEntry tab[], unsigned int value)
198 const LookupEntry *entry;
200 for (entry = tab; entry->name; entry++)
201 if (entry->value == value)
208 stringToAction(const char *str, unsigned *type_rtrn)
210 return stringToValue(actionStrings, str, type_rtrn);
214 stringToField(const char *str, enum action_field *field_rtrn)
216 return stringToValue(fieldStrings, str, field_rtrn);
220 fieldText(enum action_field field)
222 return valueToString(fieldStrings, field);
225 /***====================================================================***/
228 ReportMismatch(struct xkb_keymap *keymap, unsigned action,
229 enum action_field field, const char *type)
232 "Value of %s field must be of type %s; "
233 "Action %s definition ignored\n",
234 fieldText(field), type, ActionTypeText(action));
239 ReportIllegal(struct xkb_keymap *keymap, unsigned action,
240 enum action_field field)
243 "Field %s is not defined for an action of type %s; "
244 "Action definition ignored\n",
245 fieldText(field), ActionTypeText(action));
250 ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
251 enum action_field field)
254 "The %s field in the %s action is not an array; "
255 "Action definition ignored\n",
256 fieldText(field), ActionTypeText(action));
261 ReportNotFound(struct xkb_keymap *keymap, unsigned action,
262 enum action_field field, const char *what, const char *bad)
265 "%s named %s not found; "
266 "Ignoring the %s field of an %s action\n",
267 what, bad, fieldText(field), ActionTypeText(action));
272 HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
273 enum action_field field, const ExprDef *array_ndx,
274 const ExprDef *value)
277 return ReportIllegal(keymap, action->type, field);
281 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
282 enum action_field field, const ExprDef * value,
283 unsigned *flags_inout)
288 if (field == ACTION_FIELD_CLEAR_LOCKS)
289 tmp = XkbSA_ClearLocks;
290 else if (field == ACTION_FIELD_LATCH_TO_LOCK)
291 tmp = XkbSA_LatchToLock;
293 return false; /* WSGO! */
295 if (!ExprResolveBoolean(keymap->ctx, value, &result))
296 return ReportMismatch(keymap, action, field, "boolean");
301 *flags_inout &= ~tmp;
307 CheckModifierField(struct xkb_keymap *keymap, unsigned action,
308 const ExprDef *value, unsigned *flags_inout,
309 xkb_mod_mask_t *mods_rtrn)
311 if (value->op == EXPR_IDENT) {
313 valStr = xkb_atom_text(keymap->ctx, value->value.str);
314 if (valStr && (istreq(valStr, "usemodmapmods") ||
315 istreq(valStr, "modmapmods"))) {
318 *flags_inout |= XkbSA_UseModMapMods;
323 if (!ExprResolveVModMask(keymap, value, mods_rtrn))
324 return ReportMismatch(keymap, action,
325 ACTION_FIELD_MODIFIERS, "modifier mask");
327 *flags_inout &= ~XkbSA_UseModMapMods;
332 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
333 enum action_field field, const ExprDef *array_ndx,
334 const ExprDef *value)
336 struct xkb_mod_action *act = &action->mods;
341 if (array_ndx != NULL) {
343 case ACTION_FIELD_CLEAR_LOCKS:
344 case ACTION_FIELD_LATCH_TO_LOCK:
345 case ACTION_FIELD_MODIFIERS:
346 return ReportActionNotArray(keymap, action->type, field);
353 case ACTION_FIELD_CLEAR_LOCKS:
354 case ACTION_FIELD_LATCH_TO_LOCK:
356 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
362 case ACTION_FIELD_MODIFIERS:
364 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
375 return ReportIllegal(keymap, action->type, field);
379 HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
380 enum action_field field, const ExprDef *array_ndx,
381 const ExprDef *value)
383 struct xkb_mod_action *act = &action->mods;
387 if (array_ndx && field == ACTION_FIELD_MODIFIERS)
388 return ReportActionNotArray(keymap, action->type, field);
391 case ACTION_FIELD_MODIFIERS:
393 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
404 return ReportIllegal(keymap, action->type, field);
408 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
409 const ExprDef *value, unsigned *flags_inout,
410 xkb_group_index_t *grp_rtrn)
414 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
415 *flags_inout &= ~XkbSA_GroupAbsolute;
416 spec = value->value.child;
419 *flags_inout |= XkbSA_GroupAbsolute;
423 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
424 return ReportMismatch(keymap, action, ACTION_FIELD_GROUP,
425 "integer (range 1..8)");
427 if (value->op == EXPR_NEGATE)
428 *grp_rtrn = -*grp_rtrn;
429 else if (value->op != EXPR_UNARY_PLUS)
436 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
437 enum action_field field, const ExprDef *array_ndx,
438 const ExprDef *value)
440 struct xkb_group_action *act = &action->group;
443 xkb_group_index_t t2;
445 if (array_ndx != NULL) {
447 case ACTION_FIELD_CLEAR_LOCKS:
448 case ACTION_FIELD_LATCH_TO_LOCK:
449 case ACTION_FIELD_GROUP:
450 return ReportActionNotArray(keymap, action->type, field);
458 case ACTION_FIELD_CLEAR_LOCKS:
459 case ACTION_FIELD_LATCH_TO_LOCK:
461 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
467 case ACTION_FIELD_GROUP:
469 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
480 return ReportIllegal(keymap, action->type, field);
484 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
485 enum action_field field, const ExprDef *array_ndx,
486 const ExprDef *value)
488 struct xkb_group_action *act = &action->group;
490 xkb_group_index_t t2;
492 if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
493 return ReportActionNotArray(keymap, action->type, field);
494 if (field == ACTION_FIELD_GROUP) {
496 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
503 return ReportIllegal(keymap, action->type, field);
507 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
508 enum action_field field, const ExprDef *array_ndx,
509 const ExprDef *value)
511 struct xkb_pointer_action *act = &action->ptr;
514 if (array_ndx && (field == ACTION_FIELD_X || field == ACTION_FIELD_Y))
515 return ReportActionNotArray(keymap, action->type, field);
517 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
520 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
525 if (!ExprResolveInteger(keymap->ctx, value, &val))
526 return ReportMismatch(keymap, action->type, field, "integer");
528 if (field == ACTION_FIELD_X) {
530 act->flags |= XkbSA_MoveAbsoluteX;
535 act->flags |= XkbSA_MoveAbsoluteY;
541 else if (field == ACTION_FIELD_ACCEL) {
544 if (!ExprResolveBoolean(keymap->ctx, value, &set))
545 return ReportMismatch(keymap, action->type, field, "boolean");
548 act->flags &= ~XkbSA_NoAcceleration;
550 act->flags |= XkbSA_NoAcceleration;
553 return ReportIllegal(keymap, action->type, field);
556 static const LookupEntry lockWhich[] = {
558 { "lock", XkbSA_LockNoUnlock },
559 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
560 { "unlock", XkbSA_LockNoLock },
565 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
566 enum action_field field, const ExprDef *array_ndx,
567 const ExprDef *value)
569 struct xkb_pointer_button_action *act = &action->btn;
571 if (field == ACTION_FIELD_BUTTON) {
575 return ReportActionNotArray(keymap, action->type, field);
577 if (!ExprResolveButton(keymap->ctx, value, &btn))
578 return ReportMismatch(keymap, action->type, field,
579 "integer (range 1..5)");
581 if (btn < 0 || btn > 5) {
583 "Button must specify default or be in the range 1..5; "
584 "Illegal button value %d ignored\n", btn);
591 else if (action->type == XkbSA_LockPtrBtn &&
592 field == ACTION_FIELD_AFFECT) {
596 return ReportActionNotArray(keymap, action->type, field);
598 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
599 return ReportMismatch(keymap, action->type, field,
602 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
606 else if (field == ACTION_FIELD_COUNT) {
610 return ReportActionNotArray(keymap, action->type, field);
612 /* XXX: Should this actually be ResolveButton? */
613 if (!ExprResolveButton(keymap->ctx, value, &btn))
614 return ReportMismatch(keymap, action->type, field, "integer");
616 if (btn < 0 || btn > 255) {
618 "The count field must have a value in the range 0..255; "
619 "Illegal count %d ignored\n", btn);
626 return ReportIllegal(keymap, action->type, field);
629 static const LookupEntry ptrDflts[] = {
630 { "dfltbtn", XkbSA_AffectDfltBtn },
631 { "defaultbutton", XkbSA_AffectDfltBtn },
632 { "button", XkbSA_AffectDfltBtn },
637 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
638 enum action_field field, const ExprDef *array_ndx,
639 const ExprDef *value)
641 struct xkb_pointer_default_action *act = &action->dflt;
643 if (field == ACTION_FIELD_AFFECT) {
647 return ReportActionNotArray(keymap, action->type, field);
649 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
650 return ReportMismatch(keymap, action->type, field,
651 "pointer component");
655 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
656 const ExprDef *button;
660 return ReportActionNotArray(keymap, action->type, field);
662 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
663 act->flags &= ~XkbSA_DfltBtnAbsolute;
664 button = value->value.child;
667 act->flags |= XkbSA_DfltBtnAbsolute;
671 if (!ExprResolveButton(keymap->ctx, button, &btn))
672 return ReportMismatch(keymap, action->type, field,
673 "integer (range 1..5)");
675 if (btn < 0 || btn > 5) {
677 "New default button value must be in the range 1..5; "
678 "Illegal default button value %d ignored\n", btn);
683 "Cannot set default pointer button to \"default\"; "
684 "Illegal default button setting ignored\n");
688 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
692 return ReportIllegal(keymap, action->type, field);
695 static const LookupEntry isoNames[] = {
696 { "mods", XkbSA_ISONoAffectMods },
697 { "modifiers", XkbSA_ISONoAffectMods },
698 { "group", XkbSA_ISONoAffectGroup },
699 { "groups", XkbSA_ISONoAffectGroup },
700 { "ptr", XkbSA_ISONoAffectPtr },
701 { "pointer", XkbSA_ISONoAffectPtr },
702 { "ctrls", XkbSA_ISONoAffectCtrls },
703 { "controls", XkbSA_ISONoAffectCtrls },
704 { "all", ~((unsigned) 0) },
710 HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
711 enum action_field field, const ExprDef *array_ndx,
712 const ExprDef *value)
714 struct xkb_iso_action *act = &action->iso;
716 if (field == ACTION_FIELD_MODIFIERS) {
721 return ReportActionNotArray(keymap, action->type, field);
724 if (!CheckModifierField(keymap, action->type, value, &flags, &mods))
727 act->flags = flags & (~XkbSA_ISODfltIsGroup);
728 act->mods.mods = mods;
731 else if (field == ACTION_FIELD_GROUP) {
732 xkb_group_index_t group;
736 return ReportActionNotArray(keymap, action->type, field);
739 if (!CheckGroupField(keymap, action->type, value, &flags, &group))
742 act->flags = flags | XkbSA_ISODfltIsGroup;
745 } else if (ACTION_FIELD_AFFECT) {
749 return ReportActionNotArray(keymap, action->type, field);
751 if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames))
752 return ReportMismatch(keymap, action->type, field,
753 "keyboard component");
755 act->affect = (~mask) & XkbSA_ISOAffectMask;
759 return ReportIllegal(keymap, action->type, field);
763 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
764 enum action_field field, const ExprDef *array_ndx,
765 const ExprDef *value)
767 struct xkb_switch_screen_action *act = &action->screen;
769 if (field == ACTION_FIELD_SCREEN) {
774 return ReportActionNotArray(keymap, action->type, field);
776 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
777 act->flags &= ~XkbSA_SwitchAbsolute;
778 scrn = value->value.child;
781 act->flags |= XkbSA_SwitchAbsolute;
785 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
786 return ReportMismatch(keymap, action->type, field,
789 if (val < 0 || val > 255) {
791 "Screen index must be in the range 1..255; "
792 "Illegal screen value %d ignored\n", val);
796 act->screen = (value->op == EXPR_NEGATE ? -val : val);
799 else if (field == ACTION_FIELD_SAME) {
803 return ReportActionNotArray(keymap, action->type, field);
805 if (!ExprResolveBoolean(keymap->ctx, value, &set))
806 return ReportMismatch(keymap, action->type, field, "boolean");
809 act->flags &= ~XkbSA_SwitchApplication;
811 act->flags |= XkbSA_SwitchApplication;
816 return ReportIllegal(keymap, action->type, field);
819 const LookupEntry ctrlNames[] = {
820 { "repeatkeys", XkbRepeatKeysMask },
821 { "repeat", XkbRepeatKeysMask },
822 { "autorepeat", XkbRepeatKeysMask },
823 { "slowkeys", XkbSlowKeysMask },
824 { "bouncekeys", XkbBounceKeysMask },
825 { "stickykeys", XkbStickyKeysMask },
826 { "mousekeys", XkbMouseKeysMask },
827 { "mousekeysaccel", XkbMouseKeysAccelMask },
828 { "accessxkeys", XkbAccessXKeysMask },
829 { "accessxtimeout", XkbAccessXTimeoutMask },
830 { "accessxfeedback", XkbAccessXFeedbackMask },
831 { "audiblebell", XkbAudibleBellMask },
832 { "ignoregrouplock", XkbIgnoreGroupLockMask },
833 { "all", XkbAllBooleanCtrlsMask },
841 HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
842 enum action_field field, const ExprDef *array_ndx,
843 const ExprDef *value)
845 struct xkb_controls_action *act = &action->ctrls;
847 if (field == ACTION_FIELD_CONTROLS) {
851 return ReportActionNotArray(keymap, action->type, field);
853 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
854 return ReportMismatch(keymap, action->type, field,
861 return ReportIllegal(keymap, action->type, field);
864 static const LookupEntry evNames[] = {
865 { "press", XkbSA_MessageOnPress },
866 { "keypress", XkbSA_MessageOnPress },
867 { "release", XkbSA_MessageOnRelease },
868 { "keyrelease", XkbSA_MessageOnRelease },
869 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
875 HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
876 enum action_field field, const ExprDef *array_ndx,
877 const ExprDef *value)
879 struct xkb_message_action *act = &action->msg;
881 if (field == ACTION_FIELD_REPORT) {
885 return ReportActionNotArray(keymap, action->type, field);
887 if (!ExprResolveMask(keymap->ctx, value, &mask, evNames))
888 return ReportMismatch(keymap, action->type, field,
891 /* FIXME: Something seems wrong here... */
892 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
893 act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
896 else if (field == ACTION_FIELD_GEN_KEY_EVENT) {
900 return ReportActionNotArray(keymap, action->type, field);
902 if (!ExprResolveBoolean(keymap->ctx, value, &set))
903 return ReportMismatch(keymap, action->type, field, "boolean");
906 act->flags |= XkbSA_MessageGenKeyEvent;
908 act->flags &= ~XkbSA_MessageGenKeyEvent;
912 else if (field == ACTION_FIELD_DATA && !array_ndx) {
916 if (!ExprResolveString(keymap->ctx, value, &str))
917 return ReportMismatch(keymap, action->type, field, "string");
920 if (len < 1 || len > 6) {
921 log_warn(keymap->ctx,
922 "An action message can hold only 6 bytes; "
923 "Extra %d bytes ignored\n", len - 6);
926 strncpy((char *) act->message, str, 6);
929 else if (field == ACTION_FIELD_DATA && array_ndx) {
932 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
934 "Array subscript must be integer; "
935 "Illegal subscript ignored\n");
939 if (ndx < 0 || ndx > 5) {
941 "An action message is at most 6 bytes long; "
942 "Attempt to use data[%d] ignored\n", ndx);
946 if (!ExprResolveInteger(keymap->ctx, value, &datum))
947 return ReportMismatch(keymap, action->type, field, "integer");
949 if (datum < 0 || datum > 255) {
951 "Message data must be in the range 0..255; "
952 "Illegal datum %d ignored\n", datum);
956 act->message[ndx] = (uint8_t) datum;
960 return ReportIllegal(keymap, action->type, field);
964 HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
965 enum action_field field, const ExprDef *array_ndx,
966 const ExprDef *value)
969 struct xkb_redirect_key_action *act = &action->redirect;
973 char key_name[XkbKeyNameLength];
975 if (array_ndx != NULL)
976 return ReportActionNotArray(keymap, action->type, field);
979 case ACTION_FIELD_KEYCODE:
980 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
981 return ReportMismatch(keymap, action->type, field, "key name");
983 tmp = KeyNameToLong(key_name);
984 key = FindNamedKey(keymap, tmp, true, 0);
986 return ReportNotFound(keymap, action->type, field, "Key",
987 KeyNameText(key_name));
988 act->new_kc = XkbKeyGetKeycode(keymap, key);
991 case ACTION_FIELD_MODS_TO_CLEAR:
992 case ACTION_FIELD_MODIFIERS:
994 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
995 act->mods_mask |= (t2 & 0xff);
996 if (field == ACTION_FIELD_MODIFIERS)
997 act->mods |= (t2 & 0xff);
999 act->mods &= ~(t2 & 0xff);
1001 t2 = (t2 >> XkbNumModifiers) & 0xffff;
1002 act->vmods_mask |= t2;
1003 if (field == ACTION_FIELD_MODIFIERS)
1015 return ReportIllegal(keymap, action->type, field);
1019 HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
1020 enum action_field field, const ExprDef *array_ndx,
1021 const ExprDef *value)
1023 struct xkb_device_button_action *act = &action->devbtn;
1025 if (field == ACTION_FIELD_BUTTON) {
1029 return ReportActionNotArray(keymap, action->type, field);
1031 if (!ExprResolveInteger(keymap->ctx, value, &val))
1032 return ReportMismatch(keymap, action->type, field,
1033 "integer (range 1..255)");
1035 if (val < 0 || val > 255) {
1036 log_err(keymap->ctx,
1037 "Button must specify default or be in the range 1..255; "
1038 "Illegal button value %d ignored\n", val);
1045 else if (action->type == XkbSA_LockDeviceBtn &&
1046 field == ACTION_FIELD_AFFECT) {
1050 return ReportActionNotArray(keymap, action->type, field);
1052 if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich))
1053 return ReportMismatch(keymap, action->type, field,
1056 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
1060 else if (field == ACTION_FIELD_COUNT) {
1064 return ReportActionNotArray(keymap, action->type, field);
1066 /* XXX: Should this actually be ResolveButton? */
1067 if (!ExprResolveButton(keymap->ctx, value, &btn))
1068 return ReportMismatch(keymap, action->type, field, "integer");
1070 if (btn < 0 || btn > 255) {
1071 log_err(keymap->ctx,
1072 "The count field must have a value in the range 0..255; "
1073 "Illegal count %d ignored\n", btn);
1080 else if (field == ACTION_FIELD_DEVICE) {
1084 return ReportActionNotArray(keymap, action->type, field);
1086 if (!ExprResolveInteger(keymap->ctx, value, &val))
1087 return ReportMismatch(keymap, action->type, field,
1088 "integer (range 1..255)");
1090 if (val < 0 || val > 255) {
1091 log_err(keymap->ctx,
1092 "Device must specify default or be in the range 1..255; "
1093 "Illegal device value %d ignored\n", val);
1101 return ReportIllegal(keymap, action->type, field);
1105 HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
1106 enum action_field field, const ExprDef *array_ndx,
1107 const ExprDef *value)
1109 struct xkb_device_valuator_action *act = &action->devval;
1112 /* XXX - Not yet implemented */
1117 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
1118 enum action_field field, const ExprDef *array_ndx,
1119 const ExprDef *value)
1121 struct xkb_private_action *act = &action->priv;
1123 if (field == ACTION_FIELD_TYPE) {
1126 if (!ExprResolveInteger(keymap->ctx, value, &type))
1127 return ReportMismatch(keymap, PrivateAction, field, "integer");
1129 if (type < 0 || type > 255) {
1130 log_err(keymap->ctx,
1131 "Private action type must be in the range 0..255; "
1132 "Illegal type %d ignored\n", type);
1136 act->type = (uint8_t) type;
1139 else if (field == ACTION_FIELD_DATA) {
1140 if (array_ndx == NULL) {
1144 if (!ExprResolveString(keymap->ctx, value, &str))
1145 return ReportMismatch(keymap, action->type, field, "string");
1148 if (len < 1 || len > 7) {
1149 log_warn(keymap->ctx,
1150 "A private action has 7 data bytes; "
1151 "Extra %d bytes ignored\n", len - 6);
1155 strncpy((char *) act->data, str, sizeof(act->data));
1161 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1162 log_err(keymap->ctx,
1163 "Array subscript must be integer; "
1164 "Illegal subscript ignored\n");
1168 if (ndx < 0 || ndx >= sizeof(act->data)) {
1169 log_err(keymap->ctx,
1170 "The data for a private action is %zu bytes long; "
1171 "Attempt to use data[%d] ignored\n",
1172 sizeof(act->data), ndx);
1176 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1177 return ReportMismatch(keymap, act->type, field, "integer");
1179 if (datum < 0 || datum > 255) {
1180 log_err(keymap->ctx,
1181 "All data for a private action must be 0..255; "
1182 "Illegal datum %d ignored\n", datum);
1186 act->data[ndx] = (uint8_t) datum;
1191 return ReportIllegal(keymap, PrivateAction, field);
1194 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1195 union xkb_action *action,
1196 enum action_field field,
1197 const ExprDef *array_ndx,
1198 const ExprDef *value);
1200 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1201 [XkbSA_NoAction] = HandleNoAction,
1202 [XkbSA_SetMods] = HandleSetLatchMods,
1203 [XkbSA_LatchMods] = HandleSetLatchMods,
1204 [XkbSA_LockMods] = HandleLockMods,
1205 [XkbSA_SetGroup] = HandleSetLatchGroup,
1206 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1207 [XkbSA_LockGroup] = HandleLockGroup,
1208 [XkbSA_MovePtr] = HandleMovePtr,
1209 [XkbSA_PtrBtn] = HandlePtrBtn,
1210 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1211 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1212 [XkbSA_ISOLock] = HandleISOLock,
1213 [XkbSA_Terminate] = HandleNoAction,
1214 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1215 [XkbSA_SetControls] = HandleSetLockControls,
1216 [XkbSA_LockControls] = HandleSetLockControls,
1217 [XkbSA_ActionMessage] = HandleActionMessage,
1218 [XkbSA_RedirectKey] = HandleRedirectKey,
1219 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1220 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1221 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1222 [PrivateAction] = HandlePrivate,
1225 /***====================================================================***/
1228 ApplyActionFactoryDefaults(union xkb_action *action)
1230 if (action->type == XkbSA_SetPtrDflt) {
1231 /* Increment default button. */
1232 action->dflt.affect = XkbSA_AffectDfltBtn;
1233 action->dflt.flags = 0;
1234 action->dflt.value = 1;
1236 else if (action->type == XkbSA_ISOLock) {
1237 action->iso.mods.mods = (1 << ModNameToIndex(XKB_MOD_NAME_CAPS));
1242 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
1243 union xkb_action *action, ActionInfo *info)
1249 if (def->op != EXPR_ACTION_DECL) {
1250 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1251 expr_op_type_to_string(def->op));
1255 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1256 if (!stringToAction(str, &hndlrType)) {
1257 log_err(keymap->ctx, "Unknown action %s\n", str);
1261 action->type = hndlrType;
1264 * Go through all of the ActionInfo's which change the default values
1265 * for this action->type and apply them to this action, e.g. if the
1266 * action is latchMods, and a statement such as this:
1267 * latchMods.clearLocks = True;
1268 * appears in the section before, then we apply it.
1270 if (action->type != XkbSA_NoAction) {
1271 ApplyActionFactoryDefaults(action);
1273 for (; info; info = info->next) {
1274 if (info->action != XkbSA_NoAction && info->action != hndlrType)
1277 if (!handleAction[hndlrType](keymap, action, info->field,
1278 info->array_ndx, info->value))
1284 * Now change the action properties as specified for this
1285 * particular instance, e.g. "modifiers" and "clearLocks" in:
1286 * SetMods(modifiers=Alt,clearLocks);
1288 for (arg = def->value.action.args; arg != NULL;
1289 arg = (ExprDef *) arg->common.next) {
1290 const ExprDef *value;
1291 ExprDef *field, *arrayRtrn;
1292 const char *elemRtrn, *fieldRtrn;
1293 enum action_field fieldNdx;
1295 if (arg->op == EXPR_ASSIGN) {
1296 field = arg->value.binary.left;
1297 value = arg->value.binary.right;
1299 else if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1300 field = arg->value.child;
1301 value = &constFalse;
1308 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1313 log_err(keymap->ctx,
1314 "Cannot change defaults in an action definition; "
1315 "Ignoring attempt to change %s.%s\n",
1316 elemRtrn, fieldRtrn);
1320 if (!stringToField(fieldRtrn, &fieldNdx)) {
1321 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1325 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1334 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1335 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1337 ActionInfo *new, *old;
1339 new = malloc(sizeof(*new));
1341 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1345 if (istreq(elem, "action")) {
1346 new->action = XkbSA_NoAction;
1349 if (!stringToAction(elem, &new->action))
1352 if (new->action == XkbSA_NoAction) {
1353 log_err(keymap->ctx,
1354 "\"%s\" is not a valid field in a NoAction action\n",
1360 if (!stringToField(field, &new->field)) {
1361 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1365 new->array_ndx = array_ndx;
1370 while (old && old->next)