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 ********************************************************/
28 * Copyright © 2012 Intel Corporation
29 * Copyright © 2012 Ran Benita <ran234@gmail.com>
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
38 * The above copyright notice and this permission notice (including the next
39 * paragraph) shall be included in all copies or substantial portions of the
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
47 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
48 * DEALINGS IN THE SOFTWARE.
50 * Author: Daniel Stone <daniel@fooishbar.org>
51 * Ran Benita <ran234@gmail.com>
54 #include "xkbcomp-priv.h"
59 static const ExprBoolean constTrue = {
61 .common = { .type = STMT_EXPR, .next = NULL },
63 .value_type = EXPR_TYPE_BOOLEAN,
68 static const ExprBoolean constFalse = {
70 .common = { .type = STMT_EXPR, .next = NULL },
72 .value_type = EXPR_TYPE_BOOLEAN,
78 ACTION_FIELD_CLEAR_LOCKS,
79 ACTION_FIELD_LATCH_TO_LOCK,
80 ACTION_FIELD_GEN_KEY_EVENT,
84 ACTION_FIELD_INCREMENT,
85 ACTION_FIELD_MODIFIERS,
92 ACTION_FIELD_CONTROLS,
100 ACTION_FIELD_MODS_TO_CLEAR,
106 enum xkb_action_type type;
109 info = calloc(1, sizeof(*info));
113 for (type = 0; type < _ACTION_TYPE_NUM_ENTRIES; type++)
114 info->actions[type].type = type;
116 /* Apply some "factory defaults". */
118 /* Increment default button. */
119 info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0;
120 info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1;
121 info->actions[ACTION_TYPE_PTR_MOVE].ptr.flags = ACTION_ACCEL;
122 info->actions[ACTION_TYPE_SWITCH_VT].screen.flags = ACTION_SAME_SCREEN;
128 FreeActionsInfo(ActionsInfo *info)
133 static const LookupEntry fieldStrings[] = {
134 { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
135 { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
136 { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
137 { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
138 { "report", ACTION_FIELD_REPORT },
139 { "default", ACTION_FIELD_DEFAULT },
140 { "affect", ACTION_FIELD_AFFECT },
141 { "increment", ACTION_FIELD_INCREMENT },
142 { "modifiers", ACTION_FIELD_MODIFIERS },
143 { "mods", ACTION_FIELD_MODIFIERS },
144 { "group", ACTION_FIELD_GROUP },
145 { "x", ACTION_FIELD_X },
146 { "y", ACTION_FIELD_Y },
147 { "accel", ACTION_FIELD_ACCEL },
148 { "accelerate", ACTION_FIELD_ACCEL },
149 { "repeat", ACTION_FIELD_ACCEL },
150 { "button", ACTION_FIELD_BUTTON },
151 { "value", ACTION_FIELD_VALUE },
152 { "controls", ACTION_FIELD_CONTROLS },
153 { "ctrls", ACTION_FIELD_CONTROLS },
154 { "type", ACTION_FIELD_TYPE },
155 { "count", ACTION_FIELD_COUNT },
156 { "screen", ACTION_FIELD_SCREEN },
157 { "same", ACTION_FIELD_SAME },
158 { "sameServer", ACTION_FIELD_SAME },
159 { "data", ACTION_FIELD_DATA },
160 { "device", ACTION_FIELD_DEVICE },
161 { "dev", ACTION_FIELD_DEVICE },
162 { "key", ACTION_FIELD_KEYCODE },
163 { "keycode", ACTION_FIELD_KEYCODE },
164 { "kc", ACTION_FIELD_KEYCODE },
165 { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
166 { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
171 stringToAction(const char *str, enum xkb_action_type *type_rtrn)
173 return LookupString(actionTypeNames, str, type_rtrn);
177 stringToField(const char *str, enum action_field *field_rtrn)
179 return LookupString(fieldStrings, str, field_rtrn);
183 fieldText(enum action_field field)
185 return LookupValue(fieldStrings, field);
188 /***====================================================================***/
191 ReportMismatch(struct xkb_context *ctx, enum xkb_action_type action,
192 enum action_field field, const char *type)
195 "Value of %s field must be of type %s; "
196 "Action %s definition ignored\n",
197 fieldText(field), type, ActionTypeText(action));
202 ReportIllegal(struct xkb_context *ctx, enum xkb_action_type action,
203 enum action_field field)
206 "Field %s is not defined for an action of type %s; "
207 "Action definition ignored\n",
208 fieldText(field), ActionTypeText(action));
213 ReportActionNotArray(struct xkb_context *ctx, enum xkb_action_type action,
214 enum action_field field)
217 "The %s field in the %s action is not an array; "
218 "Action definition ignored\n",
219 fieldText(field), ActionTypeText(action));
224 HandleNoAction(struct xkb_context *ctx, const struct xkb_mod_set *mods,
225 union xkb_action *action, enum action_field field,
226 const ExprDef *array_ndx, const ExprDef *value)
233 CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
234 enum action_field field, enum xkb_action_flags flag,
235 const ExprDef *array_ndx, const ExprDef *value,
236 enum xkb_action_flags *flags_inout)
241 return ReportActionNotArray(ctx, action, field);
243 if (!ExprResolveBoolean(ctx, value, &set))
244 return ReportMismatch(ctx, action, field, "boolean");
247 *flags_inout |= flag;
249 *flags_inout &= ~flag;
255 CheckModifierField(struct xkb_context *ctx, const struct xkb_mod_set *mods,
256 enum xkb_action_type action, const ExprDef *array_ndx,
257 const ExprDef *value, enum xkb_action_flags *flags_inout,
258 xkb_mod_mask_t *mods_rtrn)
261 return ReportActionNotArray(ctx, action, ACTION_FIELD_MODIFIERS);
263 if (value->expr.op == EXPR_IDENT) {
265 valStr = xkb_atom_text(ctx, value->ident.ident);
266 if (valStr && (istreq(valStr, "usemodmapmods") ||
267 istreq(valStr, "modmapmods"))) {
269 *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
274 if (!ExprResolveModMask(ctx, value, MOD_BOTH, mods, mods_rtrn))
275 return ReportMismatch(ctx, action,
276 ACTION_FIELD_MODIFIERS, "modifier mask");
278 *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
282 static const LookupEntry lockWhich[] = {
284 { "lock", ACTION_LOCK_NO_UNLOCK },
285 { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
286 { "unlock", ACTION_LOCK_NO_LOCK },
291 CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
292 const ExprDef *array_ndx, const ExprDef *value,
293 enum xkb_action_flags *flags_inout)
295 enum xkb_action_flags flags;
298 return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
300 if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
301 return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
302 "lock, unlock, both, neither");
304 *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
305 *flags_inout |= flags;
310 HandleSetLatchLockMods(struct xkb_context *ctx, const struct xkb_mod_set *mods,
311 union xkb_action *action, enum action_field field,
312 const ExprDef *array_ndx, const ExprDef *value)
314 struct xkb_mod_action *act = &action->mods;
315 const enum xkb_action_type type = action->type;
317 if (field == ACTION_FIELD_MODIFIERS)
318 return CheckModifierField(ctx, mods, action->type, array_ndx, value,
319 &act->flags, &act->mods.mods);
320 if ((type == ACTION_TYPE_MOD_SET || type == ACTION_TYPE_MOD_LATCH) &&
321 field == ACTION_FIELD_CLEAR_LOCKS)
322 return CheckBooleanFlag(ctx, action->type, field,
323 ACTION_LOCK_CLEAR, array_ndx, value,
325 if (type == ACTION_TYPE_MOD_LATCH &&
326 field == ACTION_FIELD_LATCH_TO_LOCK)
327 return CheckBooleanFlag(ctx, action->type, field,
328 ACTION_LATCH_TO_LOCK, array_ndx, value,
330 if (type == ACTION_TYPE_MOD_LOCK &&
331 field == ACTION_FIELD_AFFECT)
332 return CheckAffectField(ctx, action->type, array_ndx, value,
335 return ReportIllegal(ctx, action->type, field);
339 CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action,
340 const ExprDef *array_ndx, const ExprDef *value,
341 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
344 xkb_layout_index_t idx;
345 enum xkb_action_flags flags = *flags_inout;
348 return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP);
350 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
351 flags &= ~ACTION_ABSOLUTE_SWITCH;
352 spec = value->unary.child;
355 flags |= ACTION_ABSOLUTE_SWITCH;
359 if (!ExprResolveGroup(ctx, spec, &idx))
360 return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
361 "integer (range 1..8)");
363 /* +n, -n are relative, n is absolute. */
364 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
365 *group_rtrn = (int32_t) idx;
366 if (value->expr.op == EXPR_NEGATE)
367 *group_rtrn = -*group_rtrn;
370 *group_rtrn = (int32_t) (idx - 1);
372 *flags_inout = flags;
377 HandleSetLatchLockGroup(struct xkb_context *ctx, const struct xkb_mod_set *mods,
378 union xkb_action *action, enum action_field field,
379 const ExprDef *array_ndx, const ExprDef *value)
381 struct xkb_group_action *act = &action->group;
382 const enum xkb_action_type type = action->type;
384 if (field == ACTION_FIELD_GROUP)
385 return CheckGroupField(ctx, action->type, array_ndx, value,
386 &act->flags, &act->group);
387 if ((type == ACTION_TYPE_GROUP_SET || type == ACTION_TYPE_GROUP_LATCH) &&
388 field == ACTION_FIELD_CLEAR_LOCKS)
389 return CheckBooleanFlag(ctx, action->type, field,
390 ACTION_LOCK_CLEAR, array_ndx, value,
392 if (type == ACTION_TYPE_GROUP_LATCH &&
393 field == ACTION_FIELD_LATCH_TO_LOCK)
394 return CheckBooleanFlag(ctx, action->type, field,
395 ACTION_LATCH_TO_LOCK, array_ndx, value,
398 return ReportIllegal(ctx, action->type, field);
402 HandleMovePtr(struct xkb_context *ctx, const struct xkb_mod_set *mods,
403 union xkb_action *action, enum action_field field,
404 const ExprDef *array_ndx, const ExprDef *value)
406 struct xkb_pointer_action *act = &action->ptr;
408 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
410 const bool absolute = (value->expr.op != EXPR_NEGATE &&
411 value->expr.op != EXPR_UNARY_PLUS);
414 return ReportActionNotArray(ctx, action->type, field);
416 if (!ExprResolveInteger(ctx, value, &val))
417 return ReportMismatch(ctx, action->type, field, "integer");
419 if (val < INT16_MIN || val > INT16_MAX) {
421 "The %s field in the %s action must be in range %d..%d; "
422 "Action definition ignored\n",
423 fieldText(field), ActionTypeText(action->type),
424 INT16_MIN, INT16_MAX);
428 if (field == ACTION_FIELD_X) {
430 act->flags |= ACTION_ABSOLUTE_X;
431 act->x = (int16_t) val;
435 act->flags |= ACTION_ABSOLUTE_Y;
436 act->y = (int16_t) val;
441 else if (field == ACTION_FIELD_ACCEL) {
442 return CheckBooleanFlag(ctx, action->type, field,
443 ACTION_ACCEL, array_ndx, value, &act->flags);
446 return ReportIllegal(ctx, action->type, field);
450 HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
451 union xkb_action *action, enum action_field field,
452 const ExprDef *array_ndx, const ExprDef *value)
454 struct xkb_pointer_button_action *act = &action->btn;
456 if (field == ACTION_FIELD_BUTTON) {
460 return ReportActionNotArray(ctx, action->type, field);
462 if (!ExprResolveButton(ctx, value, &btn))
463 return ReportMismatch(ctx, action->type, field,
464 "integer (range 1..5)");
466 if (btn < 0 || btn > 5) {
468 "Button must specify default or be in the range 1..5; "
469 "Illegal button value %d ignored\n", btn);
476 else if (action->type == ACTION_TYPE_PTR_LOCK &&
477 field == ACTION_FIELD_AFFECT) {
478 return CheckAffectField(ctx, action->type, array_ndx, value,
481 else if (field == ACTION_FIELD_COUNT) {
485 return ReportActionNotArray(ctx, action->type, field);
487 if (!ExprResolveInteger(ctx, value, &val))
488 return ReportMismatch(ctx, action->type, field, "integer");
490 if (val < 0 || val > 255) {
492 "The count field must have a value in the range 0..255; "
493 "Illegal count %d ignored\n", val);
497 act->count = (uint8_t) val;
501 return ReportIllegal(ctx, action->type, field);
504 static const LookupEntry ptrDflts[] = {
506 { "defaultbutton", 1 },
512 HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
513 union xkb_action *action, enum action_field field,
514 const ExprDef *array_ndx, const ExprDef *value)
516 struct xkb_pointer_default_action *act = &action->dflt;
518 if (field == ACTION_FIELD_AFFECT) {
522 return ReportActionNotArray(ctx, action->type, field);
524 if (!ExprResolveEnum(ctx, value, &val, ptrDflts))
525 return ReportMismatch(ctx, action->type, field,
526 "pointer component");
529 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
530 const ExprDef *button;
534 return ReportActionNotArray(ctx, action->type, field);
536 if (value->expr.op == EXPR_NEGATE ||
537 value->expr.op == EXPR_UNARY_PLUS) {
538 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
539 button = value->unary.child;
542 act->flags |= ACTION_ABSOLUTE_SWITCH;
546 if (!ExprResolveButton(ctx, button, &btn))
547 return ReportMismatch(ctx, action->type, field,
548 "integer (range 1..5)");
550 if (btn < 0 || btn > 5) {
552 "New default button value must be in the range 1..5; "
553 "Illegal default button value %d ignored\n", btn);
558 "Cannot set default pointer button to \"default\"; "
559 "Illegal default button setting ignored\n");
563 act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn);
567 return ReportIllegal(ctx, action->type, field);
571 HandleSwitchScreen(struct xkb_context *ctx, const struct xkb_mod_set *mods,
572 union xkb_action *action, enum action_field field,
573 const ExprDef *array_ndx, const ExprDef *value)
575 struct xkb_switch_screen_action *act = &action->screen;
577 if (field == ACTION_FIELD_SCREEN) {
582 return ReportActionNotArray(ctx, action->type, field);
584 if (value->expr.op == EXPR_NEGATE ||
585 value->expr.op == EXPR_UNARY_PLUS) {
586 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
587 scrn = value->unary.child;
590 act->flags |= ACTION_ABSOLUTE_SWITCH;
594 if (!ExprResolveInteger(ctx, scrn, &val))
595 return ReportMismatch(ctx, action->type, field,
598 if (val < 0 || val > 255) {
600 "Screen index must be in the range 1..255; "
601 "Illegal screen value %d ignored\n", val);
605 act->screen = (value->expr.op == EXPR_NEGATE ? -val : val);
608 else if (field == ACTION_FIELD_SAME) {
609 return CheckBooleanFlag(ctx, action->type, field,
610 ACTION_SAME_SCREEN, array_ndx, value,
614 return ReportIllegal(ctx, action->type, field);
618 HandleSetLockControls(struct xkb_context *ctx, const struct xkb_mod_set *mods,
619 union xkb_action *action, enum action_field field,
620 const ExprDef *array_ndx, const ExprDef *value)
622 struct xkb_controls_action *act = &action->ctrls;
624 if (field == ACTION_FIELD_CONTROLS) {
625 enum xkb_action_controls mask;
628 return ReportActionNotArray(ctx, action->type, field);
630 if (!ExprResolveMask(ctx, value, &mask, ctrlMaskNames))
631 return ReportMismatch(ctx, action->type, field,
637 else if (field == ACTION_FIELD_AFFECT) {
638 return CheckAffectField(ctx, action->type, array_ndx, value,
642 return ReportIllegal(ctx, action->type, field);
646 HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
647 union xkb_action *action, enum action_field field,
648 const ExprDef *array_ndx, const ExprDef *value)
650 struct xkb_private_action *act = &action->priv;
652 if (field == ACTION_FIELD_TYPE) {
656 return ReportActionNotArray(ctx, action->type, field);
658 if (!ExprResolveInteger(ctx, value, &type))
659 return ReportMismatch(ctx, ACTION_TYPE_PRIVATE, field, "integer");
661 if (type < 0 || type > 255) {
663 "Private action type must be in the range 0..255; "
664 "Illegal type %d ignored\n", type);
669 * It's possible for someone to write something like this:
670 * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
671 * where the type refers to some existing action type, e.g. LockMods.
672 * This assumes that this action's struct is laid out in memory
673 * exactly as described in the XKB specification and libraries.
674 * We, however, have changed these structs in various ways, so this
675 * assumption is no longer true. Since this is a lousy "feature", we
676 * make actions like these no-ops for now.
678 if (type < ACTION_TYPE_PRIVATE) {
680 "Private actions of type %s are not supported; Ignored\n",
681 ActionTypeText(type));
682 act->type = ACTION_TYPE_NONE;
685 act->type = (enum xkb_action_type) type;
690 else if (field == ACTION_FIELD_DATA) {
691 if (array_ndx == NULL) {
696 if (!ExprResolveString(ctx, value, &val))
697 return ReportMismatch(ctx, action->type, field, "string");
699 str = xkb_atom_text(ctx, val);
701 if (len < 1 || len > 7) {
703 "A private action has 7 data bytes; "
704 "Illegal data ignored\n");
708 strncpy((char *) act->data, str, sizeof(act->data));
714 if (!ExprResolveInteger(ctx, array_ndx, &ndx)) {
716 "Array subscript must be integer; "
717 "Illegal subscript ignored\n");
721 if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
723 "The data for a private action is %lu bytes long; "
724 "Attempt to use data[%d] ignored\n",
725 (unsigned long) sizeof(act->data), ndx);
729 if (!ExprResolveInteger(ctx, value, &datum))
730 return ReportMismatch(ctx, act->type, field, "integer");
732 if (datum < 0 || datum > 255) {
734 "All data for a private action must be 0..255; "
735 "Illegal datum %d ignored\n", datum);
739 act->data[ndx] = (uint8_t) datum;
744 return ReportIllegal(ctx, ACTION_TYPE_NONE, field);
747 typedef bool (*actionHandler)(struct xkb_context *ctx,
748 const struct xkb_mod_set *mods,
749 union xkb_action *action,
750 enum action_field field,
751 const ExprDef *array_ndx,
752 const ExprDef *value);
754 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
755 [ACTION_TYPE_NONE] = HandleNoAction,
756 [ACTION_TYPE_MOD_SET] = HandleSetLatchLockMods,
757 [ACTION_TYPE_MOD_LATCH] = HandleSetLatchLockMods,
758 [ACTION_TYPE_MOD_LOCK] = HandleSetLatchLockMods,
759 [ACTION_TYPE_GROUP_SET] = HandleSetLatchLockGroup,
760 [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchLockGroup,
761 [ACTION_TYPE_GROUP_LOCK] = HandleSetLatchLockGroup,
762 [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
763 [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
764 [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
765 [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
766 [ACTION_TYPE_TERMINATE] = HandleNoAction,
767 [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
768 [ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
769 [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
770 [ACTION_TYPE_PRIVATE] = HandlePrivate,
773 /***====================================================================***/
776 HandleActionDef(struct xkb_context *ctx, ActionsInfo *info,
777 const struct xkb_mod_set *mods, ExprDef *def,
778 union xkb_action *action)
782 enum xkb_action_type handler_type;
784 if (def->expr.op != EXPR_ACTION_DECL) {
785 log_err(ctx, "Expected an action definition, found %s\n",
786 expr_op_type_to_string(def->expr.op));
790 str = xkb_atom_text(ctx, def->action.name);
791 if (!stringToAction(str, &handler_type)) {
792 log_err(ctx, "Unknown action %s\n", str);
797 * Get the default values for this action type, as modified by
798 * statements such as:
799 * latchMods.clearLocks = True;
801 *action = info->actions[handler_type];
804 * Now change the action properties as specified for this
805 * particular instance, e.g. "modifiers" and "clearLocks" in:
806 * SetMods(modifiers=Alt,clearLocks);
808 for (arg = def->action.args; arg != NULL;
809 arg = (ExprDef *) arg->common.next) {
810 const ExprDef *value;
811 ExprDef *field, *arrayRtrn;
812 const char *elemRtrn, *fieldRtrn;
813 enum action_field fieldNdx;
815 if (arg->expr.op == EXPR_ASSIGN) {
816 field = arg->binary.left;
817 value = arg->binary.right;
819 else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) {
820 field = arg->unary.child;
821 value = (const ExprDef *) &constFalse;
825 value = (const ExprDef *) &constTrue;
828 if (!ExprResolveLhs(ctx, field, &elemRtrn, &fieldRtrn, &arrayRtrn))
833 "Cannot change defaults in an action definition; "
834 "Ignoring attempt to change %s.%s\n",
835 elemRtrn, fieldRtrn);
839 if (!stringToField(fieldRtrn, &fieldNdx)) {
840 log_err(ctx, "Unknown field name %s\n", fieldRtrn);
844 if (!handleAction[handler_type](ctx, mods, action, fieldNdx,
853 SetActionField(struct xkb_context *ctx, ActionsInfo *info,
854 struct xkb_mod_set *mods, const char *elem,
855 const char *field, ExprDef *array_ndx, ExprDef *value)
857 enum xkb_action_type action;
858 enum action_field action_field;
860 if (!stringToAction(elem, &action))
863 if (!stringToField(field, &action_field)) {
864 log_err(ctx, "\"%s\" is not a legal field name\n", field);
868 return handleAction[action](ctx, mods, &info->actions[action],
869 action_field, array_ndx, value);