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,
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;
126 FreeActionsInfo(ActionsInfo *info)
131 static const LookupEntry fieldStrings[] = {
132 { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
133 { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
134 { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
135 { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
136 { "report", ACTION_FIELD_REPORT },
137 { "default", ACTION_FIELD_DEFAULT },
138 { "affect", ACTION_FIELD_AFFECT },
139 { "increment", ACTION_FIELD_INCREMENT },
140 { "modifiers", ACTION_FIELD_MODIFIERS },
141 { "mods", ACTION_FIELD_MODIFIERS },
142 { "group", ACTION_FIELD_GROUP },
143 { "x", ACTION_FIELD_X },
144 { "y", ACTION_FIELD_Y },
145 { "accel", ACTION_FIELD_ACCEL },
146 { "accelerate", ACTION_FIELD_ACCEL },
147 { "repeat", ACTION_FIELD_ACCEL },
148 { "button", ACTION_FIELD_BUTTON },
149 { "value", ACTION_FIELD_VALUE },
150 { "controls", ACTION_FIELD_CONTROLS },
151 { "ctrls", ACTION_FIELD_CONTROLS },
152 { "type", ACTION_FIELD_TYPE },
153 { "count", ACTION_FIELD_COUNT },
154 { "screen", ACTION_FIELD_SCREEN },
155 { "same", ACTION_FIELD_SAME },
156 { "sameServer", ACTION_FIELD_SAME },
157 { "data", ACTION_FIELD_DATA },
158 { "device", ACTION_FIELD_DEVICE },
159 { "dev", ACTION_FIELD_DEVICE },
160 { "key", ACTION_FIELD_KEYCODE },
161 { "keycode", ACTION_FIELD_KEYCODE },
162 { "kc", ACTION_FIELD_KEYCODE },
163 { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
164 { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
169 stringToAction(const char *str, unsigned *type_rtrn)
171 return LookupString(actionTypeNames, str, type_rtrn);
175 stringToField(const char *str, enum action_field *field_rtrn)
177 return LookupString(fieldStrings, str, field_rtrn);
181 fieldText(enum action_field field)
183 return LookupValue(fieldStrings, field);
186 /***====================================================================***/
189 ReportMismatch(struct xkb_context *ctx, enum xkb_action_type action,
190 enum action_field field, const char *type)
193 "Value of %s field must be of type %s; "
194 "Action %s definition ignored\n",
195 fieldText(field), type, ActionTypeText(action));
200 ReportIllegal(struct xkb_context *ctx, enum xkb_action_type action,
201 enum action_field field)
204 "Field %s is not defined for an action of type %s; "
205 "Action definition ignored\n",
206 fieldText(field), ActionTypeText(action));
211 ReportActionNotArray(struct xkb_context *ctx, enum xkb_action_type action,
212 enum action_field field)
215 "The %s field in the %s action is not an array; "
216 "Action definition ignored\n",
217 fieldText(field), ActionTypeText(action));
222 HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
223 enum action_field field, const ExprDef *array_ndx,
224 const ExprDef *value)
231 CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
232 enum action_field field, const ExprDef *array_ndx,
233 const ExprDef *value, enum xkb_action_flags *flags_inout)
235 enum xkb_action_flags tmp;
239 return ReportActionNotArray(ctx, action, field);
241 if (field == ACTION_FIELD_CLEAR_LOCKS)
242 tmp = ACTION_LOCK_CLEAR;
243 else if (field == ACTION_FIELD_LATCH_TO_LOCK)
244 tmp = ACTION_LATCH_TO_LOCK;
246 return false; /* WSGO! */
248 if (!ExprResolveBoolean(ctx, value, &result))
249 return ReportMismatch(ctx, action, field, "boolean");
254 *flags_inout &= ~tmp;
260 CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
261 const ExprDef *array_ndx, const ExprDef *value,
262 enum xkb_action_flags *flags_inout, xkb_mod_mask_t *mods_rtrn)
265 return ReportActionNotArray(keymap->ctx, action, ACTION_FIELD_MODIFIERS);
267 if (value->expr.op == EXPR_IDENT) {
269 valStr = xkb_atom_text(keymap->ctx, value->ident.ident);
270 if (valStr && (istreq(valStr, "usemodmapmods") ||
271 istreq(valStr, "modmapmods"))) {
273 *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
278 if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
279 return ReportMismatch(keymap->ctx, action,
280 ACTION_FIELD_MODIFIERS, "modifier mask");
282 *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
287 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
288 enum action_field field, const ExprDef *array_ndx,
289 const ExprDef *value)
291 struct xkb_mod_action *act = &action->mods;
293 if (field == ACTION_FIELD_CLEAR_LOCKS ||
294 field == ACTION_FIELD_LATCH_TO_LOCK)
295 return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
297 else if (field == ACTION_FIELD_MODIFIERS)
298 return CheckModifierField(keymap, action->type, array_ndx, value,
299 &act->flags, &act->mods.mods);
301 return ReportIllegal(keymap->ctx, action->type, field);
304 static const LookupEntry lockWhich[] = {
306 { "lock", ACTION_LOCK_NO_UNLOCK },
307 { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
308 { "unlock", ACTION_LOCK_NO_LOCK },
313 CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
314 const ExprDef *array_ndx, const ExprDef *value,
315 enum xkb_action_flags *flags_inout)
317 enum xkb_action_flags flags;
320 return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
322 if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
323 return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
324 "lock, unlock, both, neither");
326 *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
327 *flags_inout |= flags;
332 HandleLockMods(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;
338 if (field == ACTION_FIELD_MODIFIERS)
339 return CheckModifierField(keymap, action->type, array_ndx, value,
340 &act->flags, &act->mods.mods);
341 else if (field == ACTION_FIELD_AFFECT)
342 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
345 return ReportIllegal(keymap->ctx, action->type, field);
349 CheckGroupField(struct xkb_context *ctx, unsigned action,
350 const ExprDef *array_ndx, const ExprDef *value,
351 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
354 xkb_layout_index_t idx;
355 enum xkb_action_flags flags = *flags_inout;
358 return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP);
360 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
361 flags &= ~ACTION_ABSOLUTE_SWITCH;
362 spec = value->unary.child;
365 flags |= ACTION_ABSOLUTE_SWITCH;
369 if (!ExprResolveGroup(ctx, spec, &idx))
370 return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
371 "integer (range 1..8)");
373 /* +n, -n are relative, n is absolute. */
374 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
375 *group_rtrn = (int32_t) idx;
376 if (value->expr.op == EXPR_NEGATE)
377 *group_rtrn = -*group_rtrn;
380 *group_rtrn = (int32_t) (idx - 1);
382 *flags_inout = flags;
387 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
388 enum action_field field, const ExprDef *array_ndx,
389 const ExprDef *value)
391 struct xkb_group_action *act = &action->group;
393 if (field == ACTION_FIELD_CLEAR_LOCKS ||
394 field == ACTION_FIELD_LATCH_TO_LOCK)
395 return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
397 else if (field == ACTION_FIELD_GROUP)
398 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
399 &act->flags, &act->group);
401 return ReportIllegal(keymap->ctx, action->type, field);
405 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
406 enum action_field field, const ExprDef *array_ndx,
407 const ExprDef *value)
409 struct xkb_group_action *act = &action->group;
411 if (field == ACTION_FIELD_GROUP)
412 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
413 &act->flags, &act->group);
415 return ReportIllegal(keymap->ctx, action->type, field);
419 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
420 enum action_field field, const ExprDef *array_ndx,
421 const ExprDef *value)
423 struct xkb_pointer_action *act = &action->ptr;
425 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
427 const bool absolute = (value->expr.op != EXPR_NEGATE &&
428 value->expr.op != EXPR_UNARY_PLUS);
431 return ReportActionNotArray(keymap->ctx, action->type, field);
433 if (!ExprResolveInteger(keymap->ctx, value, &val))
434 return ReportMismatch(keymap->ctx, action->type, field, "integer");
436 if (val < INT16_MIN || val > INT16_MAX) {
438 "The %s field in the %s action must be in range %d..%d; "
439 "Action definition ignored\n",
440 fieldText(field), ActionTypeText(action->type),
441 INT16_MIN, INT16_MAX);
445 if (field == ACTION_FIELD_X) {
447 act->flags |= ACTION_ABSOLUTE_X;
448 act->x = (int16_t) val;
452 act->flags |= ACTION_ABSOLUTE_Y;
453 act->y = (int16_t) val;
458 else if (field == ACTION_FIELD_ACCEL) {
462 return ReportActionNotArray(keymap->ctx, action->type, field);
464 if (!ExprResolveBoolean(keymap->ctx, value, &set))
465 return ReportMismatch(keymap->ctx, action->type, field, "boolean");
468 act->flags &= ~ACTION_NO_ACCEL;
470 act->flags |= ACTION_NO_ACCEL;
473 return ReportIllegal(keymap->ctx, action->type, field);
477 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
478 enum action_field field, const ExprDef *array_ndx,
479 const ExprDef *value)
481 struct xkb_pointer_button_action *act = &action->btn;
483 if (field == ACTION_FIELD_BUTTON) {
487 return ReportActionNotArray(keymap->ctx, action->type, field);
489 if (!ExprResolveButton(keymap->ctx, value, &btn))
490 return ReportMismatch(keymap->ctx, action->type, field,
491 "integer (range 1..5)");
493 if (btn < 0 || btn > 5) {
495 "Button must specify default or be in the range 1..5; "
496 "Illegal button value %d ignored\n", btn);
503 else if (action->type == ACTION_TYPE_PTR_LOCK &&
504 field == ACTION_FIELD_AFFECT) {
505 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
508 else if (field == ACTION_FIELD_COUNT) {
512 return ReportActionNotArray(keymap->ctx, action->type, field);
514 if (!ExprResolveInteger(keymap->ctx, value, &val))
515 return ReportMismatch(keymap->ctx, action->type, field, "integer");
517 if (val < 0 || val > 255) {
519 "The count field must have a value in the range 0..255; "
520 "Illegal count %d ignored\n", val);
524 act->count = (uint8_t) val;
528 return ReportIllegal(keymap->ctx, action->type, field);
531 static const LookupEntry ptrDflts[] = {
533 { "defaultbutton", 1 },
539 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
540 enum action_field field, const ExprDef *array_ndx,
541 const ExprDef *value)
543 struct xkb_pointer_default_action *act = &action->dflt;
545 if (field == ACTION_FIELD_AFFECT) {
549 return ReportActionNotArray(keymap->ctx, action->type, field);
551 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
552 return ReportMismatch(keymap->ctx, action->type, field,
553 "pointer component");
556 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
557 const ExprDef *button;
561 return ReportActionNotArray(keymap->ctx, action->type, field);
563 if (value->expr.op == EXPR_NEGATE ||
564 value->expr.op == EXPR_UNARY_PLUS) {
565 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
566 button = value->unary.child;
569 act->flags |= ACTION_ABSOLUTE_SWITCH;
573 if (!ExprResolveButton(keymap->ctx, button, &btn))
574 return ReportMismatch(keymap->ctx, action->type, field,
575 "integer (range 1..5)");
577 if (btn < 0 || btn > 5) {
579 "New default button value must be in the range 1..5; "
580 "Illegal default button value %d ignored\n", btn);
585 "Cannot set default pointer button to \"default\"; "
586 "Illegal default button setting ignored\n");
590 act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn);
594 return ReportIllegal(keymap->ctx, action->type, field);
598 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
599 enum action_field field, const ExprDef *array_ndx,
600 const ExprDef *value)
602 struct xkb_switch_screen_action *act = &action->screen;
604 if (field == ACTION_FIELD_SCREEN) {
609 return ReportActionNotArray(keymap->ctx, action->type, field);
611 if (value->expr.op == EXPR_NEGATE ||
612 value->expr.op == EXPR_UNARY_PLUS) {
613 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
614 scrn = value->unary.child;
617 act->flags |= ACTION_ABSOLUTE_SWITCH;
621 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
622 return ReportMismatch(keymap->ctx, action->type, field,
625 if (val < 0 || val > 255) {
627 "Screen index must be in the range 1..255; "
628 "Illegal screen value %d ignored\n", val);
632 act->screen = (value->expr.op == EXPR_NEGATE ? -val : val);
635 else if (field == ACTION_FIELD_SAME) {
639 return ReportActionNotArray(keymap->ctx, action->type, field);
641 if (!ExprResolveBoolean(keymap->ctx, value, &set))
642 return ReportMismatch(keymap->ctx, action->type, field, "boolean");
645 act->flags &= ~ACTION_SAME_SCREEN;
647 act->flags |= ACTION_SAME_SCREEN;
652 return ReportIllegal(keymap->ctx, action->type, field);
656 HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
657 enum action_field field, const ExprDef *array_ndx,
658 const ExprDef *value)
660 struct xkb_controls_action *act = &action->ctrls;
662 if (field == ACTION_FIELD_CONTROLS) {
666 return ReportActionNotArray(keymap->ctx, action->type, field);
668 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
669 return ReportMismatch(keymap->ctx, action->type, field,
675 else if (field == ACTION_FIELD_AFFECT) {
676 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
680 return ReportIllegal(keymap->ctx, action->type, field);
684 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
685 enum action_field field, const ExprDef *array_ndx,
686 const ExprDef *value)
688 struct xkb_private_action *act = &action->priv;
690 if (field == ACTION_FIELD_TYPE) {
694 return ReportActionNotArray(keymap->ctx, action->type, field);
696 if (!ExprResolveInteger(keymap->ctx, value, &type))
697 return ReportMismatch(keymap->ctx, ACTION_TYPE_PRIVATE, field, "integer");
699 if (type < 0 || type > 255) {
701 "Private action type must be in the range 0..255; "
702 "Illegal type %d ignored\n", type);
707 * It's possible for someone to write something like this:
708 * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
709 * where the type refers to some existing action type, e.g. LockMods.
710 * This assumes that this action's struct is laid out in memory
711 * exactly as described in the XKB specification and libraries.
712 * We, however, have changed these structs in various ways, so this
713 * assumption is no longer true. Since this is a lousy "feature", we
714 * make actions like these no-ops for now.
716 if (type < ACTION_TYPE_PRIVATE) {
717 log_info(keymap->ctx,
718 "Private actions of type %s are not supported; Ignored\n",
719 ActionTypeText(type));
720 act->type = ACTION_TYPE_NONE;
723 act->type = (enum xkb_action_type) type;
728 else if (field == ACTION_FIELD_DATA) {
729 if (array_ndx == NULL) {
734 if (!ExprResolveString(keymap->ctx, value, &val))
735 return ReportMismatch(keymap->ctx, action->type, field, "string");
737 str = xkb_atom_text(keymap->ctx, val);
739 if (len < 1 || len > 7) {
740 log_warn(keymap->ctx,
741 "A private action has 7 data bytes; "
742 "Illegal data ignored\n");
746 strncpy((char *) act->data, str, sizeof(act->data));
752 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
754 "Array subscript must be integer; "
755 "Illegal subscript ignored\n");
759 if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
761 "The data for a private action is %lu bytes long; "
762 "Attempt to use data[%d] ignored\n",
763 (unsigned long) sizeof(act->data), ndx);
767 if (!ExprResolveInteger(keymap->ctx, value, &datum))
768 return ReportMismatch(keymap->ctx, act->type, field, "integer");
770 if (datum < 0 || datum > 255) {
772 "All data for a private action must be 0..255; "
773 "Illegal datum %d ignored\n", datum);
777 act->data[ndx] = (uint8_t) datum;
782 return ReportIllegal(keymap->ctx, ACTION_TYPE_NONE, field);
785 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
786 union xkb_action *action,
787 enum action_field field,
788 const ExprDef *array_ndx,
789 const ExprDef *value);
791 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
792 [ACTION_TYPE_NONE] = HandleNoAction,
793 [ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
794 [ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
795 [ACTION_TYPE_MOD_LOCK] = HandleLockMods,
796 [ACTION_TYPE_GROUP_SET] = HandleSetLatchGroup,
797 [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchGroup,
798 [ACTION_TYPE_GROUP_LOCK] = HandleLockGroup,
799 [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
800 [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
801 [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
802 [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
803 [ACTION_TYPE_TERMINATE] = HandleNoAction,
804 [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
805 [ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
806 [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
807 [ACTION_TYPE_PRIVATE] = HandlePrivate,
810 /***====================================================================***/
813 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
814 union xkb_action *action, ActionsInfo *info)
818 unsigned handler_type;
820 if (def->expr.op != EXPR_ACTION_DECL) {
821 log_err(keymap->ctx, "Expected an action definition, found %s\n",
822 expr_op_type_to_string(def->expr.op));
826 str = xkb_atom_text(keymap->ctx, def->action.name);
827 if (!stringToAction(str, &handler_type)) {
828 log_err(keymap->ctx, "Unknown action %s\n", str);
833 * Get the default values for this action type, as modified by
834 * statements such as:
835 * latchMods.clearLocks = True;
837 *action = info->actions[handler_type];
840 * Now change the action properties as specified for this
841 * particular instance, e.g. "modifiers" and "clearLocks" in:
842 * SetMods(modifiers=Alt,clearLocks);
844 for (arg = def->action.args; arg != NULL;
845 arg = (ExprDef *) arg->common.next) {
846 const ExprDef *value;
847 ExprDef *field, *arrayRtrn;
848 const char *elemRtrn, *fieldRtrn;
849 enum action_field fieldNdx;
851 if (arg->expr.op == EXPR_ASSIGN) {
852 field = arg->binary.left;
853 value = arg->binary.right;
855 else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) {
856 field = arg->unary.child;
857 value = (const ExprDef *) &constFalse;
861 value = (const ExprDef *) &constTrue;
864 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
870 "Cannot change defaults in an action definition; "
871 "Ignoring attempt to change %s.%s\n",
872 elemRtrn, fieldRtrn);
876 if (!stringToField(fieldRtrn, &fieldNdx)) {
877 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
881 if (!handleAction[handler_type](keymap, action, fieldNdx, arrayRtrn,
890 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
891 ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
894 enum action_field action_field;
896 if (!stringToAction(elem, &action))
899 if (!stringToField(field, &action_field)) {
900 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
904 return handleAction[action](keymap, &info->actions[action],
905 action_field, array_ndx, value);