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;
121 info->actions[ACTION_TYPE_SWITCH_VT].screen.flags = ACTION_SAME_SCREEN;
127 FreeActionsInfo(ActionsInfo *info)
132 static const LookupEntry fieldStrings[] = {
133 { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
134 { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
135 { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
136 { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
137 { "report", ACTION_FIELD_REPORT },
138 { "default", ACTION_FIELD_DEFAULT },
139 { "affect", ACTION_FIELD_AFFECT },
140 { "increment", ACTION_FIELD_INCREMENT },
141 { "modifiers", ACTION_FIELD_MODIFIERS },
142 { "mods", ACTION_FIELD_MODIFIERS },
143 { "group", ACTION_FIELD_GROUP },
144 { "x", ACTION_FIELD_X },
145 { "y", ACTION_FIELD_Y },
146 { "accel", ACTION_FIELD_ACCEL },
147 { "accelerate", ACTION_FIELD_ACCEL },
148 { "repeat", ACTION_FIELD_ACCEL },
149 { "button", ACTION_FIELD_BUTTON },
150 { "value", ACTION_FIELD_VALUE },
151 { "controls", ACTION_FIELD_CONTROLS },
152 { "ctrls", ACTION_FIELD_CONTROLS },
153 { "type", ACTION_FIELD_TYPE },
154 { "count", ACTION_FIELD_COUNT },
155 { "screen", ACTION_FIELD_SCREEN },
156 { "same", ACTION_FIELD_SAME },
157 { "sameServer", ACTION_FIELD_SAME },
158 { "data", ACTION_FIELD_DATA },
159 { "device", ACTION_FIELD_DEVICE },
160 { "dev", ACTION_FIELD_DEVICE },
161 { "key", ACTION_FIELD_KEYCODE },
162 { "keycode", ACTION_FIELD_KEYCODE },
163 { "kc", ACTION_FIELD_KEYCODE },
164 { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
165 { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
170 stringToAction(const char *str, unsigned *type_rtrn)
172 return LookupString(actionTypeNames, str, type_rtrn);
176 stringToField(const char *str, enum action_field *field_rtrn)
178 return LookupString(fieldStrings, str, field_rtrn);
182 fieldText(enum action_field field)
184 return LookupValue(fieldStrings, field);
187 /***====================================================================***/
190 ReportMismatch(struct xkb_context *ctx, enum xkb_action_type action,
191 enum action_field field, const char *type)
194 "Value of %s field must be of type %s; "
195 "Action %s definition ignored\n",
196 fieldText(field), type, ActionTypeText(action));
201 ReportIllegal(struct xkb_context *ctx, enum xkb_action_type action,
202 enum action_field field)
205 "Field %s is not defined for an action of type %s; "
206 "Action definition ignored\n",
207 fieldText(field), ActionTypeText(action));
212 ReportActionNotArray(struct xkb_context *ctx, enum xkb_action_type action,
213 enum action_field field)
216 "The %s field in the %s action is not an array; "
217 "Action definition ignored\n",
218 fieldText(field), ActionTypeText(action));
223 HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
224 enum action_field field, const ExprDef *array_ndx,
225 const ExprDef *value)
232 CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
233 enum action_field field, const ExprDef *array_ndx,
234 const ExprDef *value, enum xkb_action_flags *flags_inout)
236 enum xkb_action_flags tmp;
240 return ReportActionNotArray(ctx, action, field);
242 if (field == ACTION_FIELD_CLEAR_LOCKS)
243 tmp = ACTION_LOCK_CLEAR;
244 else if (field == ACTION_FIELD_LATCH_TO_LOCK)
245 tmp = ACTION_LATCH_TO_LOCK;
247 return false; /* WSGO! */
249 if (!ExprResolveBoolean(ctx, value, &result))
250 return ReportMismatch(ctx, action, field, "boolean");
255 *flags_inout &= ~tmp;
261 CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
262 const ExprDef *array_ndx, const ExprDef *value,
263 enum xkb_action_flags *flags_inout, xkb_mod_mask_t *mods_rtrn)
266 return ReportActionNotArray(keymap->ctx, action, ACTION_FIELD_MODIFIERS);
268 if (value->expr.op == EXPR_IDENT) {
270 valStr = xkb_atom_text(keymap->ctx, value->ident.ident);
271 if (valStr && (istreq(valStr, "usemodmapmods") ||
272 istreq(valStr, "modmapmods"))) {
274 *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
279 if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
280 return ReportMismatch(keymap->ctx, action,
281 ACTION_FIELD_MODIFIERS, "modifier mask");
283 *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
288 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
289 enum action_field field, const ExprDef *array_ndx,
290 const ExprDef *value)
292 struct xkb_mod_action *act = &action->mods;
294 if (field == ACTION_FIELD_CLEAR_LOCKS ||
295 field == ACTION_FIELD_LATCH_TO_LOCK)
296 return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
298 else if (field == ACTION_FIELD_MODIFIERS)
299 return CheckModifierField(keymap, action->type, array_ndx, value,
300 &act->flags, &act->mods.mods);
302 return ReportIllegal(keymap->ctx, action->type, field);
305 static const LookupEntry lockWhich[] = {
307 { "lock", ACTION_LOCK_NO_UNLOCK },
308 { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
309 { "unlock", ACTION_LOCK_NO_LOCK },
314 CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
315 const ExprDef *array_ndx, const ExprDef *value,
316 enum xkb_action_flags *flags_inout)
318 enum xkb_action_flags flags;
321 return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
323 if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
324 return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
325 "lock, unlock, both, neither");
327 *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
328 *flags_inout |= flags;
333 HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
334 enum action_field field, const ExprDef *array_ndx,
335 const ExprDef *value)
337 struct xkb_mod_action *act = &action->mods;
339 if (field == ACTION_FIELD_MODIFIERS)
340 return CheckModifierField(keymap, action->type, array_ndx, value,
341 &act->flags, &act->mods.mods);
342 else if (field == ACTION_FIELD_AFFECT)
343 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
346 return ReportIllegal(keymap->ctx, action->type, field);
350 CheckGroupField(struct xkb_context *ctx, unsigned action,
351 const ExprDef *array_ndx, const ExprDef *value,
352 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
355 xkb_layout_index_t idx;
356 enum xkb_action_flags flags = *flags_inout;
359 return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP);
361 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
362 flags &= ~ACTION_ABSOLUTE_SWITCH;
363 spec = value->unary.child;
366 flags |= ACTION_ABSOLUTE_SWITCH;
370 if (!ExprResolveGroup(ctx, spec, &idx))
371 return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
372 "integer (range 1..8)");
374 /* +n, -n are relative, n is absolute. */
375 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
376 *group_rtrn = (int32_t) idx;
377 if (value->expr.op == EXPR_NEGATE)
378 *group_rtrn = -*group_rtrn;
381 *group_rtrn = (int32_t) (idx - 1);
383 *flags_inout = flags;
388 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
389 enum action_field field, const ExprDef *array_ndx,
390 const ExprDef *value)
392 struct xkb_group_action *act = &action->group;
394 if (field == ACTION_FIELD_CLEAR_LOCKS ||
395 field == ACTION_FIELD_LATCH_TO_LOCK)
396 return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
398 else if (field == ACTION_FIELD_GROUP)
399 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
400 &act->flags, &act->group);
402 return ReportIllegal(keymap->ctx, action->type, field);
406 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
407 enum action_field field, const ExprDef *array_ndx,
408 const ExprDef *value)
410 struct xkb_group_action *act = &action->group;
412 if (field == ACTION_FIELD_GROUP)
413 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
414 &act->flags, &act->group);
416 return ReportIllegal(keymap->ctx, action->type, field);
420 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
421 enum action_field field, const ExprDef *array_ndx,
422 const ExprDef *value)
424 struct xkb_pointer_action *act = &action->ptr;
426 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
428 const bool absolute = (value->expr.op != EXPR_NEGATE &&
429 value->expr.op != EXPR_UNARY_PLUS);
432 return ReportActionNotArray(keymap->ctx, action->type, field);
434 if (!ExprResolveInteger(keymap->ctx, value, &val))
435 return ReportMismatch(keymap->ctx, action->type, field, "integer");
437 if (val < INT16_MIN || val > INT16_MAX) {
439 "The %s field in the %s action must be in range %d..%d; "
440 "Action definition ignored\n",
441 fieldText(field), ActionTypeText(action->type),
442 INT16_MIN, INT16_MAX);
446 if (field == ACTION_FIELD_X) {
448 act->flags |= ACTION_ABSOLUTE_X;
449 act->x = (int16_t) val;
453 act->flags |= ACTION_ABSOLUTE_Y;
454 act->y = (int16_t) val;
459 else if (field == ACTION_FIELD_ACCEL) {
463 return ReportActionNotArray(keymap->ctx, action->type, field);
465 if (!ExprResolveBoolean(keymap->ctx, value, &set))
466 return ReportMismatch(keymap->ctx, action->type, field, "boolean");
469 act->flags &= ~ACTION_NO_ACCEL;
471 act->flags |= ACTION_NO_ACCEL;
474 return ReportIllegal(keymap->ctx, action->type, field);
478 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
479 enum action_field field, const ExprDef *array_ndx,
480 const ExprDef *value)
482 struct xkb_pointer_button_action *act = &action->btn;
484 if (field == ACTION_FIELD_BUTTON) {
488 return ReportActionNotArray(keymap->ctx, action->type, field);
490 if (!ExprResolveButton(keymap->ctx, value, &btn))
491 return ReportMismatch(keymap->ctx, action->type, field,
492 "integer (range 1..5)");
494 if (btn < 0 || btn > 5) {
496 "Button must specify default or be in the range 1..5; "
497 "Illegal button value %d ignored\n", btn);
504 else if (action->type == ACTION_TYPE_PTR_LOCK &&
505 field == ACTION_FIELD_AFFECT) {
506 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
509 else if (field == ACTION_FIELD_COUNT) {
513 return ReportActionNotArray(keymap->ctx, action->type, field);
515 if (!ExprResolveInteger(keymap->ctx, value, &val))
516 return ReportMismatch(keymap->ctx, action->type, field, "integer");
518 if (val < 0 || val > 255) {
520 "The count field must have a value in the range 0..255; "
521 "Illegal count %d ignored\n", val);
525 act->count = (uint8_t) val;
529 return ReportIllegal(keymap->ctx, action->type, field);
532 static const LookupEntry ptrDflts[] = {
534 { "defaultbutton", 1 },
540 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
541 enum action_field field, const ExprDef *array_ndx,
542 const ExprDef *value)
544 struct xkb_pointer_default_action *act = &action->dflt;
546 if (field == ACTION_FIELD_AFFECT) {
550 return ReportActionNotArray(keymap->ctx, action->type, field);
552 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
553 return ReportMismatch(keymap->ctx, action->type, field,
554 "pointer component");
557 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
558 const ExprDef *button;
562 return ReportActionNotArray(keymap->ctx, action->type, field);
564 if (value->expr.op == EXPR_NEGATE ||
565 value->expr.op == EXPR_UNARY_PLUS) {
566 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
567 button = value->unary.child;
570 act->flags |= ACTION_ABSOLUTE_SWITCH;
574 if (!ExprResolveButton(keymap->ctx, button, &btn))
575 return ReportMismatch(keymap->ctx, action->type, field,
576 "integer (range 1..5)");
578 if (btn < 0 || btn > 5) {
580 "New default button value must be in the range 1..5; "
581 "Illegal default button value %d ignored\n", btn);
586 "Cannot set default pointer button to \"default\"; "
587 "Illegal default button setting ignored\n");
591 act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn);
595 return ReportIllegal(keymap->ctx, action->type, field);
599 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
600 enum action_field field, const ExprDef *array_ndx,
601 const ExprDef *value)
603 struct xkb_switch_screen_action *act = &action->screen;
605 if (field == ACTION_FIELD_SCREEN) {
610 return ReportActionNotArray(keymap->ctx, action->type, field);
612 if (value->expr.op == EXPR_NEGATE ||
613 value->expr.op == EXPR_UNARY_PLUS) {
614 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
615 scrn = value->unary.child;
618 act->flags |= ACTION_ABSOLUTE_SWITCH;
622 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
623 return ReportMismatch(keymap->ctx, action->type, field,
626 if (val < 0 || val > 255) {
628 "Screen index must be in the range 1..255; "
629 "Illegal screen value %d ignored\n", val);
633 act->screen = (value->expr.op == EXPR_NEGATE ? -val : val);
636 else if (field == ACTION_FIELD_SAME) {
640 return ReportActionNotArray(keymap->ctx, action->type, field);
642 if (!ExprResolveBoolean(keymap->ctx, value, &set))
643 return ReportMismatch(keymap->ctx, action->type, field, "boolean");
646 act->flags |= ACTION_SAME_SCREEN;
648 act->flags &= ~ACTION_SAME_SCREEN;
653 return ReportIllegal(keymap->ctx, action->type, field);
657 HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
658 enum action_field field, const ExprDef *array_ndx,
659 const ExprDef *value)
661 struct xkb_controls_action *act = &action->ctrls;
663 if (field == ACTION_FIELD_CONTROLS) {
667 return ReportActionNotArray(keymap->ctx, action->type, field);
669 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
670 return ReportMismatch(keymap->ctx, action->type, field,
676 else if (field == ACTION_FIELD_AFFECT) {
677 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
681 return ReportIllegal(keymap->ctx, action->type, field);
685 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
686 enum action_field field, const ExprDef *array_ndx,
687 const ExprDef *value)
689 struct xkb_private_action *act = &action->priv;
691 if (field == ACTION_FIELD_TYPE) {
695 return ReportActionNotArray(keymap->ctx, action->type, field);
697 if (!ExprResolveInteger(keymap->ctx, value, &type))
698 return ReportMismatch(keymap->ctx, ACTION_TYPE_PRIVATE, field, "integer");
700 if (type < 0 || type > 255) {
702 "Private action type must be in the range 0..255; "
703 "Illegal type %d ignored\n", type);
708 * It's possible for someone to write something like this:
709 * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
710 * where the type refers to some existing action type, e.g. LockMods.
711 * This assumes that this action's struct is laid out in memory
712 * exactly as described in the XKB specification and libraries.
713 * We, however, have changed these structs in various ways, so this
714 * assumption is no longer true. Since this is a lousy "feature", we
715 * make actions like these no-ops for now.
717 if (type < ACTION_TYPE_PRIVATE) {
718 log_info(keymap->ctx,
719 "Private actions of type %s are not supported; Ignored\n",
720 ActionTypeText(type));
721 act->type = ACTION_TYPE_NONE;
724 act->type = (enum xkb_action_type) type;
729 else if (field == ACTION_FIELD_DATA) {
730 if (array_ndx == NULL) {
735 if (!ExprResolveString(keymap->ctx, value, &val))
736 return ReportMismatch(keymap->ctx, action->type, field, "string");
738 str = xkb_atom_text(keymap->ctx, val);
740 if (len < 1 || len > 7) {
741 log_warn(keymap->ctx,
742 "A private action has 7 data bytes; "
743 "Illegal data ignored\n");
747 strncpy((char *) act->data, str, sizeof(act->data));
753 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
755 "Array subscript must be integer; "
756 "Illegal subscript ignored\n");
760 if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
762 "The data for a private action is %lu bytes long; "
763 "Attempt to use data[%d] ignored\n",
764 (unsigned long) sizeof(act->data), ndx);
768 if (!ExprResolveInteger(keymap->ctx, value, &datum))
769 return ReportMismatch(keymap->ctx, act->type, field, "integer");
771 if (datum < 0 || datum > 255) {
773 "All data for a private action must be 0..255; "
774 "Illegal datum %d ignored\n", datum);
778 act->data[ndx] = (uint8_t) datum;
783 return ReportIllegal(keymap->ctx, ACTION_TYPE_NONE, field);
786 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
787 union xkb_action *action,
788 enum action_field field,
789 const ExprDef *array_ndx,
790 const ExprDef *value);
792 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
793 [ACTION_TYPE_NONE] = HandleNoAction,
794 [ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
795 [ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
796 [ACTION_TYPE_MOD_LOCK] = HandleLockMods,
797 [ACTION_TYPE_GROUP_SET] = HandleSetLatchGroup,
798 [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchGroup,
799 [ACTION_TYPE_GROUP_LOCK] = HandleLockGroup,
800 [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
801 [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
802 [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
803 [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
804 [ACTION_TYPE_TERMINATE] = HandleNoAction,
805 [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
806 [ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
807 [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
808 [ACTION_TYPE_PRIVATE] = HandlePrivate,
811 /***====================================================================***/
814 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
815 union xkb_action *action, ActionsInfo *info)
819 unsigned handler_type;
821 if (def->expr.op != EXPR_ACTION_DECL) {
822 log_err(keymap->ctx, "Expected an action definition, found %s\n",
823 expr_op_type_to_string(def->expr.op));
827 str = xkb_atom_text(keymap->ctx, def->action.name);
828 if (!stringToAction(str, &handler_type)) {
829 log_err(keymap->ctx, "Unknown action %s\n", str);
834 * Get the default values for this action type, as modified by
835 * statements such as:
836 * latchMods.clearLocks = True;
838 *action = info->actions[handler_type];
841 * Now change the action properties as specified for this
842 * particular instance, e.g. "modifiers" and "clearLocks" in:
843 * SetMods(modifiers=Alt,clearLocks);
845 for (arg = def->action.args; arg != NULL;
846 arg = (ExprDef *) arg->common.next) {
847 const ExprDef *value;
848 ExprDef *field, *arrayRtrn;
849 const char *elemRtrn, *fieldRtrn;
850 enum action_field fieldNdx;
852 if (arg->expr.op == EXPR_ASSIGN) {
853 field = arg->binary.left;
854 value = arg->binary.right;
856 else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) {
857 field = arg->unary.child;
858 value = (const ExprDef *) &constFalse;
862 value = (const ExprDef *) &constTrue;
865 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
871 "Cannot change defaults in an action definition; "
872 "Ignoring attempt to change %s.%s\n",
873 elemRtrn, fieldRtrn);
877 if (!stringToField(fieldRtrn, &fieldNdx)) {
878 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
882 if (!handleAction[handler_type](keymap, action, fieldNdx, arrayRtrn,
891 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
892 ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
895 enum action_field action_field;
897 if (!stringToAction(elem, &action))
900 if (!stringToField(field, &action_field)) {
901 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
905 return handleAction[action](keymap, &info->actions[action],
906 action_field, array_ndx, value);