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_keymap *keymap, union xkb_action *action,
225 enum action_field field, const ExprDef *array_ndx,
226 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_keymap *keymap, enum xkb_action_type action,
256 const ExprDef *array_ndx, const ExprDef *value,
257 enum xkb_action_flags *flags_inout, xkb_mod_mask_t *mods_rtrn)
260 return ReportActionNotArray(keymap->ctx, action, ACTION_FIELD_MODIFIERS);
262 if (value->expr.op == EXPR_IDENT) {
264 valStr = xkb_atom_text(keymap->ctx, value->ident.ident);
265 if (valStr && (istreq(valStr, "usemodmapmods") ||
266 istreq(valStr, "modmapmods"))) {
268 *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
273 if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
274 return ReportMismatch(keymap->ctx, action,
275 ACTION_FIELD_MODIFIERS, "modifier mask");
277 *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
281 static const LookupEntry lockWhich[] = {
283 { "lock", ACTION_LOCK_NO_UNLOCK },
284 { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
285 { "unlock", ACTION_LOCK_NO_LOCK },
290 CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
291 const ExprDef *array_ndx, const ExprDef *value,
292 enum xkb_action_flags *flags_inout)
294 enum xkb_action_flags flags;
297 return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
299 if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
300 return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
301 "lock, unlock, both, neither");
303 *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
304 *flags_inout |= flags;
309 HandleSetLatchLockMods(struct xkb_keymap *keymap, union xkb_action *action,
310 enum action_field field, const ExprDef *array_ndx,
311 const ExprDef *value)
313 struct xkb_mod_action *act = &action->mods;
314 const enum xkb_action_type type = action->type;
316 if (field == ACTION_FIELD_MODIFIERS)
317 return CheckModifierField(keymap, action->type, array_ndx, value,
318 &act->flags, &act->mods.mods);
319 if ((type == ACTION_TYPE_MOD_SET || type == ACTION_TYPE_MOD_LATCH) &&
320 field == ACTION_FIELD_CLEAR_LOCKS)
321 return CheckBooleanFlag(keymap->ctx, action->type, field,
322 ACTION_LOCK_CLEAR, array_ndx, value,
324 if (type == ACTION_TYPE_MOD_LATCH &&
325 field == ACTION_FIELD_LATCH_TO_LOCK)
326 return CheckBooleanFlag(keymap->ctx, action->type, field,
327 ACTION_LATCH_TO_LOCK, array_ndx, value,
329 if (type == ACTION_TYPE_MOD_LOCK &&
330 field == ACTION_FIELD_AFFECT)
331 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
334 return ReportIllegal(keymap->ctx, action->type, field);
338 CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action,
339 const ExprDef *array_ndx, const ExprDef *value,
340 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
343 xkb_layout_index_t idx;
344 enum xkb_action_flags flags = *flags_inout;
347 return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP);
349 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
350 flags &= ~ACTION_ABSOLUTE_SWITCH;
351 spec = value->unary.child;
354 flags |= ACTION_ABSOLUTE_SWITCH;
358 if (!ExprResolveGroup(ctx, spec, &idx))
359 return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
360 "integer (range 1..8)");
362 /* +n, -n are relative, n is absolute. */
363 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
364 *group_rtrn = (int32_t) idx;
365 if (value->expr.op == EXPR_NEGATE)
366 *group_rtrn = -*group_rtrn;
369 *group_rtrn = (int32_t) (idx - 1);
371 *flags_inout = flags;
376 HandleSetLatchLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
377 enum action_field field, const ExprDef *array_ndx,
378 const ExprDef *value)
380 struct xkb_group_action *act = &action->group;
381 const enum xkb_action_type type = action->type;
383 if (field == ACTION_FIELD_GROUP)
384 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
385 &act->flags, &act->group);
386 if ((type == ACTION_TYPE_GROUP_SET || type == ACTION_TYPE_GROUP_LATCH) &&
387 field == ACTION_FIELD_CLEAR_LOCKS)
388 return CheckBooleanFlag(keymap->ctx, action->type, field,
389 ACTION_LOCK_CLEAR, array_ndx, value,
391 if (type == ACTION_TYPE_GROUP_LATCH &&
392 field == ACTION_FIELD_LATCH_TO_LOCK)
393 return CheckBooleanFlag(keymap->ctx, action->type, field,
394 ACTION_LATCH_TO_LOCK, array_ndx, value,
397 return ReportIllegal(keymap->ctx, action->type, field);
401 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
402 enum action_field field, const ExprDef *array_ndx,
403 const ExprDef *value)
405 struct xkb_pointer_action *act = &action->ptr;
407 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
409 const bool absolute = (value->expr.op != EXPR_NEGATE &&
410 value->expr.op != EXPR_UNARY_PLUS);
413 return ReportActionNotArray(keymap->ctx, action->type, field);
415 if (!ExprResolveInteger(keymap->ctx, value, &val))
416 return ReportMismatch(keymap->ctx, action->type, field, "integer");
418 if (val < INT16_MIN || val > INT16_MAX) {
420 "The %s field in the %s action must be in range %d..%d; "
421 "Action definition ignored\n",
422 fieldText(field), ActionTypeText(action->type),
423 INT16_MIN, INT16_MAX);
427 if (field == ACTION_FIELD_X) {
429 act->flags |= ACTION_ABSOLUTE_X;
430 act->x = (int16_t) val;
434 act->flags |= ACTION_ABSOLUTE_Y;
435 act->y = (int16_t) val;
440 else if (field == ACTION_FIELD_ACCEL) {
441 return CheckBooleanFlag(keymap->ctx, action->type, field,
442 ACTION_ACCEL, array_ndx, value, &act->flags);
445 return ReportIllegal(keymap->ctx, action->type, field);
449 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
450 enum action_field field, const ExprDef *array_ndx,
451 const ExprDef *value)
453 struct xkb_pointer_button_action *act = &action->btn;
455 if (field == ACTION_FIELD_BUTTON) {
459 return ReportActionNotArray(keymap->ctx, action->type, field);
461 if (!ExprResolveButton(keymap->ctx, value, &btn))
462 return ReportMismatch(keymap->ctx, action->type, field,
463 "integer (range 1..5)");
465 if (btn < 0 || btn > 5) {
467 "Button must specify default or be in the range 1..5; "
468 "Illegal button value %d ignored\n", btn);
475 else if (action->type == ACTION_TYPE_PTR_LOCK &&
476 field == ACTION_FIELD_AFFECT) {
477 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
480 else if (field == ACTION_FIELD_COUNT) {
484 return ReportActionNotArray(keymap->ctx, action->type, field);
486 if (!ExprResolveInteger(keymap->ctx, value, &val))
487 return ReportMismatch(keymap->ctx, action->type, field, "integer");
489 if (val < 0 || val > 255) {
491 "The count field must have a value in the range 0..255; "
492 "Illegal count %d ignored\n", val);
496 act->count = (uint8_t) val;
500 return ReportIllegal(keymap->ctx, action->type, field);
503 static const LookupEntry ptrDflts[] = {
505 { "defaultbutton", 1 },
511 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
512 enum action_field field, const ExprDef *array_ndx,
513 const ExprDef *value)
515 struct xkb_pointer_default_action *act = &action->dflt;
517 if (field == ACTION_FIELD_AFFECT) {
521 return ReportActionNotArray(keymap->ctx, action->type, field);
523 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
524 return ReportMismatch(keymap->ctx, action->type, field,
525 "pointer component");
528 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
529 const ExprDef *button;
533 return ReportActionNotArray(keymap->ctx, action->type, field);
535 if (value->expr.op == EXPR_NEGATE ||
536 value->expr.op == EXPR_UNARY_PLUS) {
537 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
538 button = value->unary.child;
541 act->flags |= ACTION_ABSOLUTE_SWITCH;
545 if (!ExprResolveButton(keymap->ctx, button, &btn))
546 return ReportMismatch(keymap->ctx, action->type, field,
547 "integer (range 1..5)");
549 if (btn < 0 || btn > 5) {
551 "New default button value must be in the range 1..5; "
552 "Illegal default button value %d ignored\n", btn);
557 "Cannot set default pointer button to \"default\"; "
558 "Illegal default button setting ignored\n");
562 act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn);
566 return ReportIllegal(keymap->ctx, action->type, field);
570 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
571 enum action_field field, const ExprDef *array_ndx,
572 const ExprDef *value)
574 struct xkb_switch_screen_action *act = &action->screen;
576 if (field == ACTION_FIELD_SCREEN) {
581 return ReportActionNotArray(keymap->ctx, action->type, field);
583 if (value->expr.op == EXPR_NEGATE ||
584 value->expr.op == EXPR_UNARY_PLUS) {
585 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
586 scrn = value->unary.child;
589 act->flags |= ACTION_ABSOLUTE_SWITCH;
593 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
594 return ReportMismatch(keymap->ctx, action->type, field,
597 if (val < 0 || val > 255) {
599 "Screen index must be in the range 1..255; "
600 "Illegal screen value %d ignored\n", val);
604 act->screen = (value->expr.op == EXPR_NEGATE ? -val : val);
607 else if (field == ACTION_FIELD_SAME) {
608 return CheckBooleanFlag(keymap->ctx, action->type, field,
609 ACTION_SAME_SCREEN, array_ndx, value,
613 return ReportIllegal(keymap->ctx, action->type, field);
617 HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
618 enum action_field field, const ExprDef *array_ndx,
619 const ExprDef *value)
621 struct xkb_controls_action *act = &action->ctrls;
623 if (field == ACTION_FIELD_CONTROLS) {
624 enum xkb_action_controls mask;
627 return ReportActionNotArray(keymap->ctx, action->type, field);
629 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
630 return ReportMismatch(keymap->ctx, action->type, field,
636 else if (field == ACTION_FIELD_AFFECT) {
637 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
641 return ReportIllegal(keymap->ctx, action->type, field);
645 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
646 enum action_field field, const ExprDef *array_ndx,
647 const ExprDef *value)
649 struct xkb_private_action *act = &action->priv;
651 if (field == ACTION_FIELD_TYPE) {
655 return ReportActionNotArray(keymap->ctx, action->type, field);
657 if (!ExprResolveInteger(keymap->ctx, value, &type))
658 return ReportMismatch(keymap->ctx, ACTION_TYPE_PRIVATE, field, "integer");
660 if (type < 0 || type > 255) {
662 "Private action type must be in the range 0..255; "
663 "Illegal type %d ignored\n", type);
668 * It's possible for someone to write something like this:
669 * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
670 * where the type refers to some existing action type, e.g. LockMods.
671 * This assumes that this action's struct is laid out in memory
672 * exactly as described in the XKB specification and libraries.
673 * We, however, have changed these structs in various ways, so this
674 * assumption is no longer true. Since this is a lousy "feature", we
675 * make actions like these no-ops for now.
677 if (type < ACTION_TYPE_PRIVATE) {
678 log_info(keymap->ctx,
679 "Private actions of type %s are not supported; Ignored\n",
680 ActionTypeText(type));
681 act->type = ACTION_TYPE_NONE;
684 act->type = (enum xkb_action_type) type;
689 else if (field == ACTION_FIELD_DATA) {
690 if (array_ndx == NULL) {
695 if (!ExprResolveString(keymap->ctx, value, &val))
696 return ReportMismatch(keymap->ctx, action->type, field, "string");
698 str = xkb_atom_text(keymap->ctx, val);
700 if (len < 1 || len > 7) {
701 log_warn(keymap->ctx,
702 "A private action has 7 data bytes; "
703 "Illegal data ignored\n");
707 strncpy((char *) act->data, str, sizeof(act->data));
713 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
715 "Array subscript must be integer; "
716 "Illegal subscript ignored\n");
720 if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
722 "The data for a private action is %lu bytes long; "
723 "Attempt to use data[%d] ignored\n",
724 (unsigned long) sizeof(act->data), ndx);
728 if (!ExprResolveInteger(keymap->ctx, value, &datum))
729 return ReportMismatch(keymap->ctx, act->type, field, "integer");
731 if (datum < 0 || datum > 255) {
733 "All data for a private action must be 0..255; "
734 "Illegal datum %d ignored\n", datum);
738 act->data[ndx] = (uint8_t) datum;
743 return ReportIllegal(keymap->ctx, ACTION_TYPE_NONE, field);
746 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
747 union xkb_action *action,
748 enum action_field field,
749 const ExprDef *array_ndx,
750 const ExprDef *value);
752 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
753 [ACTION_TYPE_NONE] = HandleNoAction,
754 [ACTION_TYPE_MOD_SET] = HandleSetLatchLockMods,
755 [ACTION_TYPE_MOD_LATCH] = HandleSetLatchLockMods,
756 [ACTION_TYPE_MOD_LOCK] = HandleSetLatchLockMods,
757 [ACTION_TYPE_GROUP_SET] = HandleSetLatchLockGroup,
758 [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchLockGroup,
759 [ACTION_TYPE_GROUP_LOCK] = HandleSetLatchLockGroup,
760 [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
761 [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
762 [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
763 [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
764 [ACTION_TYPE_TERMINATE] = HandleNoAction,
765 [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
766 [ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
767 [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
768 [ACTION_TYPE_PRIVATE] = HandlePrivate,
771 /***====================================================================***/
774 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
775 union xkb_action *action, ActionsInfo *info)
779 unsigned handler_type;
781 if (def->expr.op != EXPR_ACTION_DECL) {
782 log_err(keymap->ctx, "Expected an action definition, found %s\n",
783 expr_op_type_to_string(def->expr.op));
787 str = xkb_atom_text(keymap->ctx, def->action.name);
788 if (!stringToAction(str, &handler_type)) {
789 log_err(keymap->ctx, "Unknown action %s\n", str);
794 * Get the default values for this action type, as modified by
795 * statements such as:
796 * latchMods.clearLocks = True;
798 *action = info->actions[handler_type];
801 * Now change the action properties as specified for this
802 * particular instance, e.g. "modifiers" and "clearLocks" in:
803 * SetMods(modifiers=Alt,clearLocks);
805 for (arg = def->action.args; arg != NULL;
806 arg = (ExprDef *) arg->common.next) {
807 const ExprDef *value;
808 ExprDef *field, *arrayRtrn;
809 const char *elemRtrn, *fieldRtrn;
810 enum action_field fieldNdx;
812 if (arg->expr.op == EXPR_ASSIGN) {
813 field = arg->binary.left;
814 value = arg->binary.right;
816 else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) {
817 field = arg->unary.child;
818 value = (const ExprDef *) &constFalse;
822 value = (const ExprDef *) &constTrue;
825 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
831 "Cannot change defaults in an action definition; "
832 "Ignoring attempt to change %s.%s\n",
833 elemRtrn, fieldRtrn);
837 if (!stringToField(fieldRtrn, &fieldNdx)) {
838 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
842 if (!handleAction[handler_type](keymap, action, fieldNdx, arrayRtrn,
851 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
852 ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
854 enum xkb_action_type action;
855 enum action_field action_field;
857 if (!stringToAction(elem, &action))
860 if (!stringToField(field, &action_field)) {
861 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
865 return handleAction[action](keymap, &info->actions[action],
866 action_field, array_ndx, value);