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>
56 #include "xkbcomp-priv.h"
61 static const ExprBoolean constTrue = {
63 .common = { .type = STMT_EXPR, .next = NULL },
65 .value_type = EXPR_TYPE_BOOLEAN,
70 static const ExprBoolean constFalse = {
72 .common = { .type = STMT_EXPR, .next = NULL },
74 .value_type = EXPR_TYPE_BOOLEAN,
80 ACTION_FIELD_CLEAR_LOCKS,
81 ACTION_FIELD_LATCH_TO_LOCK,
82 ACTION_FIELD_GEN_KEY_EVENT,
86 ACTION_FIELD_INCREMENT,
87 ACTION_FIELD_MODIFIERS,
94 ACTION_FIELD_CONTROLS,
101 ACTION_FIELD_KEYCODE,
102 ACTION_FIELD_MODS_TO_CLEAR,
108 enum xkb_action_type type;
111 info = calloc(1, sizeof(*info));
115 for (type = 0; type < _ACTION_TYPE_NUM_ENTRIES; type++)
116 info->actions[type].type = type;
118 /* Apply some "factory defaults". */
120 /* Increment default button. */
121 info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0;
122 info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1;
123 info->actions[ACTION_TYPE_PTR_MOVE].ptr.flags = ACTION_ACCEL;
124 info->actions[ACTION_TYPE_SWITCH_VT].screen.flags = ACTION_SAME_SCREEN;
130 FreeActionsInfo(ActionsInfo *info)
135 static const LookupEntry fieldStrings[] = {
136 { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
137 { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
138 { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
139 { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
140 { "report", ACTION_FIELD_REPORT },
141 { "default", ACTION_FIELD_DEFAULT },
142 { "affect", ACTION_FIELD_AFFECT },
143 { "increment", ACTION_FIELD_INCREMENT },
144 { "modifiers", ACTION_FIELD_MODIFIERS },
145 { "mods", ACTION_FIELD_MODIFIERS },
146 { "group", ACTION_FIELD_GROUP },
147 { "x", ACTION_FIELD_X },
148 { "y", ACTION_FIELD_Y },
149 { "accel", ACTION_FIELD_ACCEL },
150 { "accelerate", ACTION_FIELD_ACCEL },
151 { "repeat", ACTION_FIELD_ACCEL },
152 { "button", ACTION_FIELD_BUTTON },
153 { "value", ACTION_FIELD_VALUE },
154 { "controls", ACTION_FIELD_CONTROLS },
155 { "ctrls", ACTION_FIELD_CONTROLS },
156 { "type", ACTION_FIELD_TYPE },
157 { "count", ACTION_FIELD_COUNT },
158 { "screen", ACTION_FIELD_SCREEN },
159 { "same", ACTION_FIELD_SAME },
160 { "sameServer", ACTION_FIELD_SAME },
161 { "data", ACTION_FIELD_DATA },
162 { "device", ACTION_FIELD_DEVICE },
163 { "dev", ACTION_FIELD_DEVICE },
164 { "key", ACTION_FIELD_KEYCODE },
165 { "keycode", ACTION_FIELD_KEYCODE },
166 { "kc", ACTION_FIELD_KEYCODE },
167 { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
168 { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
173 stringToAction(const char *str, enum xkb_action_type *type_rtrn)
175 return LookupString(actionTypeNames, str, type_rtrn);
179 stringToField(const char *str, enum action_field *field_rtrn)
181 return LookupString(fieldStrings, str, field_rtrn);
185 fieldText(enum action_field field)
187 return LookupValue(fieldStrings, field);
190 /***====================================================================***/
193 ReportMismatch(struct xkb_context *ctx, enum xkb_action_type action,
194 enum action_field field, const char *type)
197 "Value of %s field must be of type %s; "
198 "Action %s definition ignored\n",
199 fieldText(field), type, ActionTypeText(action));
204 ReportIllegal(struct xkb_context *ctx, enum xkb_action_type action,
205 enum action_field field)
208 "Field %s is not defined for an action of type %s; "
209 "Action definition ignored\n",
210 fieldText(field), ActionTypeText(action));
215 ReportActionNotArray(struct xkb_context *ctx, enum xkb_action_type action,
216 enum action_field field)
219 "The %s field in the %s action is not an array; "
220 "Action definition ignored\n",
221 fieldText(field), ActionTypeText(action));
226 HandleNoAction(struct xkb_context *ctx, const struct xkb_mod_set *mods,
227 union xkb_action *action, enum action_field field,
228 const ExprDef *array_ndx, const ExprDef *value)
235 CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
236 enum action_field field, enum xkb_action_flags flag,
237 const ExprDef *array_ndx, const ExprDef *value,
238 enum xkb_action_flags *flags_inout)
243 return ReportActionNotArray(ctx, action, field);
245 if (!ExprResolveBoolean(ctx, value, &set))
246 return ReportMismatch(ctx, action, field, "boolean");
249 *flags_inout |= flag;
251 *flags_inout &= ~flag;
257 CheckModifierField(struct xkb_context *ctx, const struct xkb_mod_set *mods,
258 enum xkb_action_type action, const ExprDef *array_ndx,
259 const ExprDef *value, enum xkb_action_flags *flags_inout,
260 xkb_mod_mask_t *mods_rtrn)
263 return ReportActionNotArray(ctx, action, ACTION_FIELD_MODIFIERS);
265 if (value->expr.op == EXPR_IDENT) {
267 valStr = xkb_atom_text(ctx, value->ident.ident);
268 if (valStr && (istreq(valStr, "usemodmapmods") ||
269 istreq(valStr, "modmapmods"))) {
271 *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
276 if (!ExprResolveModMask(ctx, value, MOD_BOTH, mods, mods_rtrn))
277 return ReportMismatch(ctx, action,
278 ACTION_FIELD_MODIFIERS, "modifier mask");
280 *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
284 static const LookupEntry lockWhich[] = {
286 { "lock", ACTION_LOCK_NO_UNLOCK },
287 { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
288 { "unlock", ACTION_LOCK_NO_LOCK },
293 CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
294 const ExprDef *array_ndx, const ExprDef *value,
295 enum xkb_action_flags *flags_inout)
297 enum xkb_action_flags flags;
300 return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
302 if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
303 return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
304 "lock, unlock, both, neither");
306 *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
307 *flags_inout |= flags;
312 HandleSetLatchLockMods(struct xkb_context *ctx, const struct xkb_mod_set *mods,
313 union xkb_action *action, enum action_field field,
314 const ExprDef *array_ndx, const ExprDef *value)
316 struct xkb_mod_action *act = &action->mods;
317 const enum xkb_action_type type = action->type;
319 if (field == ACTION_FIELD_MODIFIERS)
320 return CheckModifierField(ctx, mods, action->type, array_ndx, value,
321 &act->flags, &act->mods.mods);
322 if ((type == ACTION_TYPE_MOD_SET || type == ACTION_TYPE_MOD_LATCH) &&
323 field == ACTION_FIELD_CLEAR_LOCKS)
324 return CheckBooleanFlag(ctx, action->type, field,
325 ACTION_LOCK_CLEAR, array_ndx, value,
327 if (type == ACTION_TYPE_MOD_LATCH &&
328 field == ACTION_FIELD_LATCH_TO_LOCK)
329 return CheckBooleanFlag(ctx, action->type, field,
330 ACTION_LATCH_TO_LOCK, array_ndx, value,
332 if (type == ACTION_TYPE_MOD_LOCK &&
333 field == ACTION_FIELD_AFFECT)
334 return CheckAffectField(ctx, action->type, array_ndx, value,
337 return ReportIllegal(ctx, action->type, field);
341 CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action,
342 const ExprDef *array_ndx, const ExprDef *value,
343 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
346 xkb_layout_index_t idx;
347 enum xkb_action_flags flags = *flags_inout;
350 return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP);
352 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
353 flags &= ~ACTION_ABSOLUTE_SWITCH;
354 spec = value->unary.child;
357 flags |= ACTION_ABSOLUTE_SWITCH;
361 if (!ExprResolveGroup(ctx, spec, &idx))
362 return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
363 "integer (range 1..8)");
365 /* +n, -n are relative, n is absolute. */
366 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
367 *group_rtrn = (int32_t) idx;
368 if (value->expr.op == EXPR_NEGATE)
369 *group_rtrn = -*group_rtrn;
372 *group_rtrn = (int32_t) (idx - 1);
374 *flags_inout = flags;
379 HandleSetLatchLockGroup(struct xkb_context *ctx, const struct xkb_mod_set *mods,
380 union xkb_action *action, enum action_field field,
381 const ExprDef *array_ndx, const ExprDef *value)
383 struct xkb_group_action *act = &action->group;
384 const enum xkb_action_type type = action->type;
386 if (field == ACTION_FIELD_GROUP)
387 return CheckGroupField(ctx, action->type, array_ndx, value,
388 &act->flags, &act->group);
389 if ((type == ACTION_TYPE_GROUP_SET || type == ACTION_TYPE_GROUP_LATCH) &&
390 field == ACTION_FIELD_CLEAR_LOCKS)
391 return CheckBooleanFlag(ctx, action->type, field,
392 ACTION_LOCK_CLEAR, array_ndx, value,
394 if (type == ACTION_TYPE_GROUP_LATCH &&
395 field == ACTION_FIELD_LATCH_TO_LOCK)
396 return CheckBooleanFlag(ctx, action->type, field,
397 ACTION_LATCH_TO_LOCK, array_ndx, value,
400 return ReportIllegal(ctx, action->type, field);
404 HandleMovePtr(struct xkb_context *ctx, const struct xkb_mod_set *mods,
405 union xkb_action *action, enum action_field field,
406 const ExprDef *array_ndx, const ExprDef *value)
408 struct xkb_pointer_action *act = &action->ptr;
410 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
412 const bool absolute = (value->expr.op != EXPR_NEGATE &&
413 value->expr.op != EXPR_UNARY_PLUS);
416 return ReportActionNotArray(ctx, action->type, field);
418 if (!ExprResolveInteger(ctx, value, &val))
419 return ReportMismatch(ctx, action->type, field, "integer");
421 if (val < INT16_MIN || val > INT16_MAX) {
423 "The %s field in the %s action must be in range %d..%d; "
424 "Action definition ignored\n",
425 fieldText(field), ActionTypeText(action->type),
426 INT16_MIN, INT16_MAX);
430 if (field == ACTION_FIELD_X) {
432 act->flags |= ACTION_ABSOLUTE_X;
433 act->x = (int16_t) val;
437 act->flags |= ACTION_ABSOLUTE_Y;
438 act->y = (int16_t) val;
443 else if (field == ACTION_FIELD_ACCEL) {
444 return CheckBooleanFlag(ctx, action->type, field,
445 ACTION_ACCEL, array_ndx, value, &act->flags);
448 return ReportIllegal(ctx, action->type, field);
452 HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
453 union xkb_action *action, enum action_field field,
454 const ExprDef *array_ndx, const ExprDef *value)
456 struct xkb_pointer_button_action *act = &action->btn;
458 if (field == ACTION_FIELD_BUTTON) {
462 return ReportActionNotArray(ctx, action->type, field);
464 if (!ExprResolveButton(ctx, value, &btn))
465 return ReportMismatch(ctx, action->type, field,
466 "integer (range 1..5)");
468 if (btn < 0 || btn > 5) {
470 "Button must specify default or be in the range 1..5; "
471 "Illegal button value %d ignored\n", btn);
478 else if (action->type == ACTION_TYPE_PTR_LOCK &&
479 field == ACTION_FIELD_AFFECT) {
480 return CheckAffectField(ctx, action->type, array_ndx, value,
483 else if (field == ACTION_FIELD_COUNT) {
487 return ReportActionNotArray(ctx, action->type, field);
489 if (!ExprResolveInteger(ctx, value, &val))
490 return ReportMismatch(ctx, action->type, field, "integer");
492 if (val < 0 || val > 255) {
494 "The count field must have a value in the range 0..255; "
495 "Illegal count %d ignored\n", val);
499 act->count = (uint8_t) val;
503 return ReportIllegal(ctx, action->type, field);
506 static const LookupEntry ptrDflts[] = {
508 { "defaultbutton", 1 },
514 HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
515 union xkb_action *action, enum action_field field,
516 const ExprDef *array_ndx, const ExprDef *value)
518 struct xkb_pointer_default_action *act = &action->dflt;
520 if (field == ACTION_FIELD_AFFECT) {
524 return ReportActionNotArray(ctx, action->type, field);
526 if (!ExprResolveEnum(ctx, value, &val, ptrDflts))
527 return ReportMismatch(ctx, action->type, field,
528 "pointer component");
531 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
532 const ExprDef *button;
536 return ReportActionNotArray(ctx, action->type, field);
538 if (value->expr.op == EXPR_NEGATE ||
539 value->expr.op == EXPR_UNARY_PLUS) {
540 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
541 button = value->unary.child;
544 act->flags |= ACTION_ABSOLUTE_SWITCH;
548 if (!ExprResolveButton(ctx, button, &btn))
549 return ReportMismatch(ctx, action->type, field,
550 "integer (range 1..5)");
552 if (btn < 0 || btn > 5) {
554 "New default button value must be in the range 1..5; "
555 "Illegal default button value %d ignored\n", btn);
560 "Cannot set default pointer button to \"default\"; "
561 "Illegal default button setting ignored\n");
565 act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn);
569 return ReportIllegal(ctx, action->type, field);
573 HandleSwitchScreen(struct xkb_context *ctx, const struct xkb_mod_set *mods,
574 union xkb_action *action, enum action_field field,
575 const ExprDef *array_ndx, const ExprDef *value)
577 struct xkb_switch_screen_action *act = &action->screen;
579 if (field == ACTION_FIELD_SCREEN) {
584 return ReportActionNotArray(ctx, action->type, field);
586 if (value->expr.op == EXPR_NEGATE ||
587 value->expr.op == EXPR_UNARY_PLUS) {
588 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
589 scrn = value->unary.child;
592 act->flags |= ACTION_ABSOLUTE_SWITCH;
596 if (!ExprResolveInteger(ctx, scrn, &val))
597 return ReportMismatch(ctx, action->type, field,
600 if (val < 0 || val > 255) {
602 "Screen index must be in the range 1..255; "
603 "Illegal screen value %d ignored\n", val);
607 act->screen = (value->expr.op == EXPR_NEGATE ? -val : val);
610 else if (field == ACTION_FIELD_SAME) {
611 return CheckBooleanFlag(ctx, action->type, field,
612 ACTION_SAME_SCREEN, array_ndx, value,
616 return ReportIllegal(ctx, action->type, field);
620 HandleSetLockControls(struct xkb_context *ctx, const struct xkb_mod_set *mods,
621 union xkb_action *action, enum action_field field,
622 const ExprDef *array_ndx, const ExprDef *value)
624 struct xkb_controls_action *act = &action->ctrls;
626 if (field == ACTION_FIELD_CONTROLS) {
627 enum xkb_action_controls mask;
630 return ReportActionNotArray(ctx, action->type, field);
632 if (!ExprResolveMask(ctx, value, &mask, ctrlMaskNames))
633 return ReportMismatch(ctx, action->type, field,
639 else if (field == ACTION_FIELD_AFFECT) {
640 return CheckAffectField(ctx, action->type, array_ndx, value,
644 return ReportIllegal(ctx, action->type, field);
648 HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
649 union xkb_action *action, enum action_field field,
650 const ExprDef *array_ndx, const ExprDef *value)
652 struct xkb_private_action *act = &action->priv;
654 if (field == ACTION_FIELD_TYPE) {
658 return ReportActionNotArray(ctx, action->type, field);
660 if (!ExprResolveInteger(ctx, value, &type))
661 return ReportMismatch(ctx, ACTION_TYPE_PRIVATE, field, "integer");
663 if (type < 0 || type > 255) {
665 "Private action type must be in the range 0..255; "
666 "Illegal type %d ignored\n", type);
671 * It's possible for someone to write something like this:
672 * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
673 * where the type refers to some existing action type, e.g. LockMods.
674 * This assumes that this action's struct is laid out in memory
675 * exactly as described in the XKB specification and libraries.
676 * We, however, have changed these structs in various ways, so this
677 * assumption is no longer true. Since this is a lousy "feature", we
678 * make actions like these no-ops for now.
680 if (type < ACTION_TYPE_PRIVATE) {
682 "Private actions of type %s are not supported; Ignored\n",
683 ActionTypeText(type));
684 act->type = ACTION_TYPE_NONE;
687 act->type = (enum xkb_action_type) type;
692 else if (field == ACTION_FIELD_DATA) {
693 if (array_ndx == NULL) {
698 if (!ExprResolveString(ctx, value, &val))
699 return ReportMismatch(ctx, action->type, field, "string");
701 str = xkb_atom_text(ctx, val);
703 if (len < 1 || len > sizeof(act->data)) {
705 "A private action has %ld data bytes; "
706 "Illegal data ignored\n", sizeof(act->data));
710 /* act->data may not be null-terminated, this is intentional */
711 memset(act->data, 0, sizeof(act->data));
712 memcpy(act->data, str, len);
718 if (!ExprResolveInteger(ctx, array_ndx, &ndx)) {
720 "Array subscript must be integer; "
721 "Illegal subscript ignored\n");
725 if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
727 "The data for a private action is %lu bytes long; "
728 "Attempt to use data[%d] ignored\n",
729 (unsigned long) sizeof(act->data), ndx);
733 if (!ExprResolveInteger(ctx, value, &datum))
734 return ReportMismatch(ctx, act->type, field, "integer");
736 if (datum < 0 || datum > 255) {
738 "All data for a private action must be 0..255; "
739 "Illegal datum %d ignored\n", datum);
743 act->data[ndx] = (uint8_t) datum;
748 return ReportIllegal(ctx, ACTION_TYPE_NONE, field);
751 typedef bool (*actionHandler)(struct xkb_context *ctx,
752 const struct xkb_mod_set *mods,
753 union xkb_action *action,
754 enum action_field field,
755 const ExprDef *array_ndx,
756 const ExprDef *value);
758 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
759 [ACTION_TYPE_NONE] = HandleNoAction,
760 [ACTION_TYPE_MOD_SET] = HandleSetLatchLockMods,
761 [ACTION_TYPE_MOD_LATCH] = HandleSetLatchLockMods,
762 [ACTION_TYPE_MOD_LOCK] = HandleSetLatchLockMods,
763 [ACTION_TYPE_GROUP_SET] = HandleSetLatchLockGroup,
764 [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchLockGroup,
765 [ACTION_TYPE_GROUP_LOCK] = HandleSetLatchLockGroup,
766 [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
767 [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
768 [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
769 [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
770 [ACTION_TYPE_TERMINATE] = HandleNoAction,
771 [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
772 [ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
773 [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
774 [ACTION_TYPE_PRIVATE] = HandlePrivate,
777 /***====================================================================***/
780 HandleActionDef(struct xkb_context *ctx, ActionsInfo *info,
781 const struct xkb_mod_set *mods, ExprDef *def,
782 union xkb_action *action)
786 enum xkb_action_type handler_type;
788 if (def->expr.op != EXPR_ACTION_DECL) {
789 log_err(ctx, "Expected an action definition, found %s\n",
790 expr_op_type_to_string(def->expr.op));
794 str = xkb_atom_text(ctx, def->action.name);
795 if (!stringToAction(str, &handler_type)) {
796 log_err(ctx, "Unknown action %s\n", str);
801 * Get the default values for this action type, as modified by
802 * statements such as:
803 * latchMods.clearLocks = True;
805 *action = info->actions[handler_type];
808 * Now change the action properties as specified for this
809 * particular instance, e.g. "modifiers" and "clearLocks" in:
810 * SetMods(modifiers=Alt,clearLocks);
812 for (arg = def->action.args; arg != NULL;
813 arg = (ExprDef *) arg->common.next) {
814 const ExprDef *value;
815 ExprDef *field, *arrayRtrn;
816 const char *elemRtrn, *fieldRtrn;
817 enum action_field fieldNdx;
819 if (arg->expr.op == EXPR_ASSIGN) {
820 field = arg->binary.left;
821 value = arg->binary.right;
823 else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) {
824 field = arg->unary.child;
825 value = (const ExprDef *) &constFalse;
829 value = (const ExprDef *) &constTrue;
832 if (!ExprResolveLhs(ctx, field, &elemRtrn, &fieldRtrn, &arrayRtrn))
837 "Cannot change defaults in an action definition; "
838 "Ignoring attempt to change %s.%s\n",
839 elemRtrn, fieldRtrn);
843 if (!stringToField(fieldRtrn, &fieldNdx)) {
844 log_err(ctx, "Unknown field name %s\n", fieldRtrn);
848 if (!handleAction[handler_type](ctx, mods, action, fieldNdx,
857 SetActionField(struct xkb_context *ctx, ActionsInfo *info,
858 struct xkb_mod_set *mods, const char *elem,
859 const char *field, ExprDef *array_ndx, ExprDef *value)
861 enum xkb_action_type action;
862 enum action_field action_field;
864 if (!stringToAction(elem, &action))
867 if (!stringToField(field, &action_field)) {
868 log_err(ctx, "\"%s\" is not a legal field name\n", field);
872 return handleAction[action](ctx, mods, &info->actions[action],
873 action_field, array_ndx, value);