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_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, unsigned *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 CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
234 enum action_field field, const ExprDef *array_ndx,
235 const ExprDef *value, enum xkb_action_flags *flags_inout)
237 enum xkb_action_flags tmp;
241 return ReportActionNotArray(ctx, action, field);
243 if (field == ACTION_FIELD_CLEAR_LOCKS)
244 tmp = ACTION_LOCK_CLEAR;
245 else if (field == ACTION_FIELD_LATCH_TO_LOCK)
246 tmp = ACTION_LATCH_TO_LOCK;
248 return false; /* WSGO! */
250 if (!ExprResolveBoolean(ctx, value, &result))
251 return ReportMismatch(ctx, action, field, "boolean");
256 *flags_inout &= ~tmp;
262 CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
263 const ExprDef *array_ndx, const ExprDef *value,
264 enum xkb_action_flags *flags_inout, xkb_mod_mask_t *mods_rtrn)
267 return ReportActionNotArray(keymap->ctx, action, ACTION_FIELD_MODIFIERS);
269 if (value->expr.op == EXPR_IDENT) {
271 valStr = xkb_atom_text(keymap->ctx, value->ident.ident);
272 if (valStr && (istreq(valStr, "usemodmapmods") ||
273 istreq(valStr, "modmapmods"))) {
275 *flags_inout |= ACTION_MODS_LOOKUP_MODMAP;
280 if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
281 return ReportMismatch(keymap->ctx, action,
282 ACTION_FIELD_MODIFIERS, "modifier mask");
284 *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
289 HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
290 enum action_field field, const ExprDef *array_ndx,
291 const ExprDef *value)
293 struct xkb_mod_action *act = &action->mods;
295 if (field == ACTION_FIELD_CLEAR_LOCKS ||
296 field == ACTION_FIELD_LATCH_TO_LOCK)
297 return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
299 else if (field == ACTION_FIELD_MODIFIERS)
300 return CheckModifierField(keymap, action->type, array_ndx, value,
301 &act->flags, &act->mods.mods);
303 return ReportIllegal(keymap->ctx, action->type, field);
306 static const LookupEntry lockWhich[] = {
308 { "lock", ACTION_LOCK_NO_UNLOCK },
309 { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) },
310 { "unlock", ACTION_LOCK_NO_LOCK },
315 CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
316 const ExprDef *array_ndx, const ExprDef *value,
317 enum xkb_action_flags *flags_inout)
319 enum xkb_action_flags flags;
322 return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
324 if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
325 return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
326 "lock, unlock, both, neither");
328 *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
329 *flags_inout |= flags;
334 HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
335 enum action_field field, const ExprDef *array_ndx,
336 const ExprDef *value)
338 struct xkb_mod_action *act = &action->mods;
340 if (field == ACTION_FIELD_MODIFIERS)
341 return CheckModifierField(keymap, action->type, array_ndx, value,
342 &act->flags, &act->mods.mods);
343 else if (field == ACTION_FIELD_AFFECT)
344 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
347 return ReportIllegal(keymap->ctx, action->type, field);
351 CheckGroupField(struct xkb_context *ctx, unsigned action,
352 const ExprDef *array_ndx, const ExprDef *value,
353 enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
356 xkb_layout_index_t idx;
357 enum xkb_action_flags flags = *flags_inout;
360 return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP);
362 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
363 flags &= ~ACTION_ABSOLUTE_SWITCH;
364 spec = value->unary.child;
367 flags |= ACTION_ABSOLUTE_SWITCH;
371 if (!ExprResolveGroup(ctx, spec, &idx))
372 return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
373 "integer (range 1..8)");
375 /* +n, -n are relative, n is absolute. */
376 if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
377 *group_rtrn = (int32_t) idx;
378 if (value->expr.op == EXPR_NEGATE)
379 *group_rtrn = -*group_rtrn;
382 *group_rtrn = (int32_t) (idx - 1);
384 *flags_inout = flags;
389 HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
390 enum action_field field, const ExprDef *array_ndx,
391 const ExprDef *value)
393 struct xkb_group_action *act = &action->group;
395 if (field == ACTION_FIELD_CLEAR_LOCKS ||
396 field == ACTION_FIELD_LATCH_TO_LOCK)
397 return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
399 else if (field == ACTION_FIELD_GROUP)
400 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
401 &act->flags, &act->group);
403 return ReportIllegal(keymap->ctx, action->type, field);
407 HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
408 enum action_field field, const ExprDef *array_ndx,
409 const ExprDef *value)
411 struct xkb_group_action *act = &action->group;
413 if (field == ACTION_FIELD_GROUP)
414 return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
415 &act->flags, &act->group);
417 return ReportIllegal(keymap->ctx, action->type, field);
421 HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
422 enum action_field field, const ExprDef *array_ndx,
423 const ExprDef *value)
425 struct xkb_pointer_action *act = &action->ptr;
427 if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
429 const bool absolute = (value->expr.op != EXPR_NEGATE &&
430 value->expr.op != EXPR_UNARY_PLUS);
433 return ReportActionNotArray(keymap->ctx, action->type, field);
435 if (!ExprResolveInteger(keymap->ctx, value, &val))
436 return ReportMismatch(keymap->ctx, action->type, field, "integer");
438 if (val < INT16_MIN || val > INT16_MAX) {
440 "The %s field in the %s action must be in range %d..%d; "
441 "Action definition ignored\n",
442 fieldText(field), ActionTypeText(action->type),
443 INT16_MIN, INT16_MAX);
447 if (field == ACTION_FIELD_X) {
449 act->flags |= ACTION_ABSOLUTE_X;
450 act->x = (int16_t) val;
454 act->flags |= ACTION_ABSOLUTE_Y;
455 act->y = (int16_t) val;
460 else if (field == ACTION_FIELD_ACCEL) {
464 return ReportActionNotArray(keymap->ctx, action->type, field);
466 if (!ExprResolveBoolean(keymap->ctx, value, &set))
467 return ReportMismatch(keymap->ctx, action->type, field, "boolean");
470 act->flags |= ACTION_ACCEL;
472 act->flags &= ~ACTION_ACCEL;
475 return ReportIllegal(keymap->ctx, action->type, field);
479 HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
480 enum action_field field, const ExprDef *array_ndx,
481 const ExprDef *value)
483 struct xkb_pointer_button_action *act = &action->btn;
485 if (field == ACTION_FIELD_BUTTON) {
489 return ReportActionNotArray(keymap->ctx, action->type, field);
491 if (!ExprResolveButton(keymap->ctx, value, &btn))
492 return ReportMismatch(keymap->ctx, action->type, field,
493 "integer (range 1..5)");
495 if (btn < 0 || btn > 5) {
497 "Button must specify default or be in the range 1..5; "
498 "Illegal button value %d ignored\n", btn);
505 else if (action->type == ACTION_TYPE_PTR_LOCK &&
506 field == ACTION_FIELD_AFFECT) {
507 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
510 else if (field == ACTION_FIELD_COUNT) {
514 return ReportActionNotArray(keymap->ctx, action->type, field);
516 if (!ExprResolveInteger(keymap->ctx, value, &val))
517 return ReportMismatch(keymap->ctx, action->type, field, "integer");
519 if (val < 0 || val > 255) {
521 "The count field must have a value in the range 0..255; "
522 "Illegal count %d ignored\n", val);
526 act->count = (uint8_t) val;
530 return ReportIllegal(keymap->ctx, action->type, field);
533 static const LookupEntry ptrDflts[] = {
535 { "defaultbutton", 1 },
541 HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
542 enum action_field field, const ExprDef *array_ndx,
543 const ExprDef *value)
545 struct xkb_pointer_default_action *act = &action->dflt;
547 if (field == ACTION_FIELD_AFFECT) {
551 return ReportActionNotArray(keymap->ctx, action->type, field);
553 if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts))
554 return ReportMismatch(keymap->ctx, action->type, field,
555 "pointer component");
558 else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
559 const ExprDef *button;
563 return ReportActionNotArray(keymap->ctx, action->type, field);
565 if (value->expr.op == EXPR_NEGATE ||
566 value->expr.op == EXPR_UNARY_PLUS) {
567 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
568 button = value->unary.child;
571 act->flags |= ACTION_ABSOLUTE_SWITCH;
575 if (!ExprResolveButton(keymap->ctx, button, &btn))
576 return ReportMismatch(keymap->ctx, action->type, field,
577 "integer (range 1..5)");
579 if (btn < 0 || btn > 5) {
581 "New default button value must be in the range 1..5; "
582 "Illegal default button value %d ignored\n", btn);
587 "Cannot set default pointer button to \"default\"; "
588 "Illegal default button setting ignored\n");
592 act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn);
596 return ReportIllegal(keymap->ctx, action->type, field);
600 HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
601 enum action_field field, const ExprDef *array_ndx,
602 const ExprDef *value)
604 struct xkb_switch_screen_action *act = &action->screen;
606 if (field == ACTION_FIELD_SCREEN) {
611 return ReportActionNotArray(keymap->ctx, action->type, field);
613 if (value->expr.op == EXPR_NEGATE ||
614 value->expr.op == EXPR_UNARY_PLUS) {
615 act->flags &= ~ACTION_ABSOLUTE_SWITCH;
616 scrn = value->unary.child;
619 act->flags |= ACTION_ABSOLUTE_SWITCH;
623 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
624 return ReportMismatch(keymap->ctx, action->type, field,
627 if (val < 0 || val > 255) {
629 "Screen index must be in the range 1..255; "
630 "Illegal screen value %d ignored\n", val);
634 act->screen = (value->expr.op == EXPR_NEGATE ? -val : val);
637 else if (field == ACTION_FIELD_SAME) {
641 return ReportActionNotArray(keymap->ctx, action->type, field);
643 if (!ExprResolveBoolean(keymap->ctx, value, &set))
644 return ReportMismatch(keymap->ctx, action->type, field, "boolean");
647 act->flags |= ACTION_SAME_SCREEN;
649 act->flags &= ~ACTION_SAME_SCREEN;
654 return ReportIllegal(keymap->ctx, action->type, field);
658 HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
659 enum action_field field, const ExprDef *array_ndx,
660 const ExprDef *value)
662 struct xkb_controls_action *act = &action->ctrls;
664 if (field == ACTION_FIELD_CONTROLS) {
668 return ReportActionNotArray(keymap->ctx, action->type, field);
670 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
671 return ReportMismatch(keymap->ctx, action->type, field,
677 else if (field == ACTION_FIELD_AFFECT) {
678 return CheckAffectField(keymap->ctx, action->type, array_ndx, value,
682 return ReportIllegal(keymap->ctx, action->type, field);
686 HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
687 enum action_field field, const ExprDef *array_ndx,
688 const ExprDef *value)
690 struct xkb_private_action *act = &action->priv;
692 if (field == ACTION_FIELD_TYPE) {
696 return ReportActionNotArray(keymap->ctx, action->type, field);
698 if (!ExprResolveInteger(keymap->ctx, value, &type))
699 return ReportMismatch(keymap->ctx, ACTION_TYPE_PRIVATE, field, "integer");
701 if (type < 0 || type > 255) {
703 "Private action type must be in the range 0..255; "
704 "Illegal type %d ignored\n", type);
709 * It's possible for someone to write something like this:
710 * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ]
711 * where the type refers to some existing action type, e.g. LockMods.
712 * This assumes that this action's struct is laid out in memory
713 * exactly as described in the XKB specification and libraries.
714 * We, however, have changed these structs in various ways, so this
715 * assumption is no longer true. Since this is a lousy "feature", we
716 * make actions like these no-ops for now.
718 if (type < ACTION_TYPE_PRIVATE) {
719 log_info(keymap->ctx,
720 "Private actions of type %s are not supported; Ignored\n",
721 ActionTypeText(type));
722 act->type = ACTION_TYPE_NONE;
725 act->type = (enum xkb_action_type) type;
730 else if (field == ACTION_FIELD_DATA) {
731 if (array_ndx == NULL) {
736 if (!ExprResolveString(keymap->ctx, value, &val))
737 return ReportMismatch(keymap->ctx, action->type, field, "string");
739 str = xkb_atom_text(keymap->ctx, val);
741 if (len < 1 || len > 7) {
742 log_warn(keymap->ctx,
743 "A private action has 7 data bytes; "
744 "Illegal data ignored\n");
748 strncpy((char *) act->data, str, sizeof(act->data));
754 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
756 "Array subscript must be integer; "
757 "Illegal subscript ignored\n");
761 if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
763 "The data for a private action is %lu bytes long; "
764 "Attempt to use data[%d] ignored\n",
765 (unsigned long) sizeof(act->data), ndx);
769 if (!ExprResolveInteger(keymap->ctx, value, &datum))
770 return ReportMismatch(keymap->ctx, act->type, field, "integer");
772 if (datum < 0 || datum > 255) {
774 "All data for a private action must be 0..255; "
775 "Illegal datum %d ignored\n", datum);
779 act->data[ndx] = (uint8_t) datum;
784 return ReportIllegal(keymap->ctx, ACTION_TYPE_NONE, field);
787 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
788 union xkb_action *action,
789 enum action_field field,
790 const ExprDef *array_ndx,
791 const ExprDef *value);
793 static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = {
794 [ACTION_TYPE_NONE] = HandleNoAction,
795 [ACTION_TYPE_MOD_SET] = HandleSetLatchMods,
796 [ACTION_TYPE_MOD_LATCH] = HandleSetLatchMods,
797 [ACTION_TYPE_MOD_LOCK] = HandleLockMods,
798 [ACTION_TYPE_GROUP_SET] = HandleSetLatchGroup,
799 [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchGroup,
800 [ACTION_TYPE_GROUP_LOCK] = HandleLockGroup,
801 [ACTION_TYPE_PTR_MOVE] = HandleMovePtr,
802 [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn,
803 [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn,
804 [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt,
805 [ACTION_TYPE_TERMINATE] = HandleNoAction,
806 [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen,
807 [ACTION_TYPE_CTRL_SET] = HandleSetLockControls,
808 [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls,
809 [ACTION_TYPE_PRIVATE] = HandlePrivate,
812 /***====================================================================***/
815 HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,
816 union xkb_action *action, ActionsInfo *info)
820 unsigned handler_type;
822 if (def->expr.op != EXPR_ACTION_DECL) {
823 log_err(keymap->ctx, "Expected an action definition, found %s\n",
824 expr_op_type_to_string(def->expr.op));
828 str = xkb_atom_text(keymap->ctx, def->action.name);
829 if (!stringToAction(str, &handler_type)) {
830 log_err(keymap->ctx, "Unknown action %s\n", str);
835 * Get the default values for this action type, as modified by
836 * statements such as:
837 * latchMods.clearLocks = True;
839 *action = info->actions[handler_type];
842 * Now change the action properties as specified for this
843 * particular instance, e.g. "modifiers" and "clearLocks" in:
844 * SetMods(modifiers=Alt,clearLocks);
846 for (arg = def->action.args; arg != NULL;
847 arg = (ExprDef *) arg->common.next) {
848 const ExprDef *value;
849 ExprDef *field, *arrayRtrn;
850 const char *elemRtrn, *fieldRtrn;
851 enum action_field fieldNdx;
853 if (arg->expr.op == EXPR_ASSIGN) {
854 field = arg->binary.left;
855 value = arg->binary.right;
857 else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) {
858 field = arg->unary.child;
859 value = (const ExprDef *) &constFalse;
863 value = (const ExprDef *) &constTrue;
866 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
872 "Cannot change defaults in an action definition; "
873 "Ignoring attempt to change %s.%s\n",
874 elemRtrn, fieldRtrn);
878 if (!stringToField(fieldRtrn, &fieldNdx)) {
879 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
883 if (!handleAction[handler_type](keymap, action, fieldNdx, arrayRtrn,
892 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
893 ExprDef *array_ndx, ExprDef *value, ActionsInfo *info)
896 enum action_field action_field;
898 if (!stringToAction(elem, &action))
901 if (!stringToField(field, &action_field)) {
902 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
906 return handleAction[action](keymap, &info->actions[action],
907 action_field, array_ndx, value);