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 ********************************************************/
29 static bool actionsInitialized;
30 static ExprDef constTrue;
31 static ExprDef constFalse;
33 /***====================================================================***/
35 static const LookupEntry actionStrings[] = {
36 { "noaction", XkbSA_NoAction },
37 { "setmods", XkbSA_SetMods },
38 { "latchmods", XkbSA_LatchMods },
39 { "lockmods", XkbSA_LockMods },
40 { "setgroup", XkbSA_SetGroup },
41 { "latchgroup", XkbSA_LatchGroup },
42 { "lockgroup", XkbSA_LockGroup },
43 { "moveptr", XkbSA_MovePtr },
44 { "movepointer", XkbSA_MovePtr },
45 { "ptrbtn", XkbSA_PtrBtn },
46 { "pointerbutton", XkbSA_PtrBtn },
47 { "lockptrbtn", XkbSA_LockPtrBtn },
48 { "lockpointerbutton", XkbSA_LockPtrBtn },
49 { "lockptrbutton", XkbSA_LockPtrBtn },
50 { "lockpointerbtn", XkbSA_LockPtrBtn },
51 { "setptrdflt", XkbSA_SetPtrDflt },
52 { "setpointerdefault", XkbSA_SetPtrDflt },
53 { "isolock", XkbSA_ISOLock },
54 { "terminate", XkbSA_Terminate },
55 { "terminateserver", XkbSA_Terminate },
56 { "switchscreen", XkbSA_SwitchScreen },
57 { "setcontrols", XkbSA_SetControls },
58 { "lockcontrols", XkbSA_LockControls },
59 { "actionmessage", XkbSA_ActionMessage },
60 { "messageaction", XkbSA_ActionMessage },
61 { "message", XkbSA_ActionMessage },
62 { "redirect", XkbSA_RedirectKey },
63 { "redirectkey", XkbSA_RedirectKey },
64 { "devbtn", XkbSA_DeviceBtn },
65 { "devicebtn", XkbSA_DeviceBtn },
66 { "devbutton", XkbSA_DeviceBtn },
67 { "devicebutton", XkbSA_DeviceBtn },
68 { "lockdevbtn", XkbSA_DeviceBtn },
69 { "lockdevicebtn", XkbSA_LockDeviceBtn },
70 { "lockdevbutton", XkbSA_LockDeviceBtn },
71 { "lockdevicebutton", XkbSA_LockDeviceBtn },
72 { "devval", XkbSA_DeviceValuator },
73 { "deviceval", XkbSA_DeviceValuator },
74 { "devvaluator", XkbSA_DeviceValuator },
75 { "devicevaluator", XkbSA_DeviceValuator },
76 { "private", PrivateAction },
80 static const LookupEntry fieldStrings[] = {
81 { "clearLocks", F_ClearLocks },
82 { "latchToLock", F_LatchToLock },
83 { "genKeyEvent", F_GenKeyEvent },
84 { "generateKeyEvent", F_GenKeyEvent },
85 { "report", F_Report },
86 { "default", F_Default },
87 { "affect", F_Affect },
88 { "increment", F_Increment },
89 { "modifiers", F_Modifiers },
90 { "mods", F_Modifiers },
95 { "accelerate", F_Accel },
96 { "repeat", F_Accel },
97 { "button", F_Button },
99 { "controls", F_Controls },
100 { "ctrls", F_Controls },
102 { "count", F_Count },
103 { "screen", F_Screen },
105 { "sameServer", F_Same },
107 { "device", F_Device },
109 { "key", F_Keycode },
110 { "keycode", F_Keycode },
112 { "clearmods", F_ModsToClear },
113 { "clearmodifiers", F_ModsToClear },
118 stringToValue(const LookupEntry tab[], const char *string,
119 unsigned *value_rtrn)
121 const LookupEntry *entry;
126 for (entry = tab; entry->name != NULL; entry++) {
127 if (istreq(entry->name, string)) {
128 *value_rtrn = entry->result;
137 valueToString(const LookupEntry tab[], unsigned value)
139 const LookupEntry *entry;
141 for (entry = tab; entry->name != NULL; entry++)
142 if (entry->result == value)
149 stringToAction(const char *str, unsigned *type_rtrn)
151 return stringToValue(actionStrings, str, type_rtrn);
155 stringToField(const char *str, unsigned *field_rtrn)
157 return stringToValue(fieldStrings, str, field_rtrn);
161 fieldText(unsigned field)
163 return valueToString(fieldStrings, field);
166 /***====================================================================***/
169 ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
173 "Value of %s field must be of type %s; "
174 "Action %s definition ignored\n",
175 fieldText(field), type, ActionTypeText(action));
180 ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
183 "Field %s is not defined for an action of type %s; "
184 "Action definition ignored\n",
185 fieldText(field), ActionTypeText(action));
190 ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
194 "The %s field in the %s action is not an array; "
195 "Action definition ignored\n",
196 fieldText(field), ActionTypeText(action));
201 ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
202 const char *what, const char *bad)
205 "%s named %s not found; "
206 "Ignoring the %s field of an %s action\n",
207 what, bad, fieldText(field), ActionTypeText(action));
212 HandleNoAction(struct xkb_keymap *keymap, struct xkb_any_action *action,
213 unsigned field, ExprDef *array_ndx, ExprDef *value)
216 return ReportIllegal(keymap, action->type, field);
220 CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
221 unsigned field, ExprDef * value, unsigned *flags_inout)
226 if (field == F_ClearLocks)
227 tmp = XkbSA_ClearLocks;
228 else if (field == F_LatchToLock)
229 tmp = XkbSA_LatchToLock;
231 return false; /* WSGO! */
232 if (!ExprResolveBoolean(keymap->ctx, value, &result))
233 return ReportMismatch(keymap, action, field, "boolean");
237 *flags_inout &= ~tmp;
242 CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
243 unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn)
246 if (value->op == EXPR_IDENT) {
248 valStr = xkb_atom_text(keymap->ctx, value->value.str);
249 if (valStr && (istreq(valStr, "usemodmapmods") ||
250 istreq(valStr, "modmapmods"))) {
253 *flags_inout |= XkbSA_UseModMapMods;
258 if (!ExprResolveVModMask(keymap, value, &rtrn))
259 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
261 *mods_rtrn = (xkb_mod_mask_t) rtrn.ival;
262 *flags_inout &= ~XkbSA_UseModMapMods;
267 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
268 unsigned field, ExprDef *array_ndx, ExprDef *value)
270 struct xkb_mod_action *act;
275 act = (struct xkb_mod_action *) action;
276 if (array_ndx != NULL) {
281 return ReportActionNotArray(keymap, action->type, field);
288 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
296 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
298 act->real_mods = act->mask = (t2 & 0xff);
299 act->vmods = (t2 >> 8) & 0xffff;
304 return ReportIllegal(keymap, action->type, field);
308 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
309 unsigned field, ExprDef *array_ndx, ExprDef *value)
311 struct xkb_mod_action *act;
315 act = (struct xkb_mod_action *) action;
316 if ((array_ndx != NULL) && (field == F_Modifiers))
317 return ReportActionNotArray(keymap, action->type, field);
321 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
323 act->real_mods = act->mask = (t2 & 0xff);
324 act->vmods = (t2 >> 8) & 0xffff;
329 return ReportIllegal(keymap, action->type, field);
333 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
334 ExprDef * value, unsigned *flags_inout,
335 xkb_group_index_t *grp_rtrn)
340 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
341 *flags_inout &= ~XkbSA_GroupAbsolute;
342 spec = value->value.child;
345 *flags_inout |= XkbSA_GroupAbsolute;
349 if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
350 return ReportMismatch(keymap, action, F_Group,
351 "integer (range 1..8)");
352 if (value->op == EXPR_NEGATE)
353 *grp_rtrn = -rtrn.ival;
354 else if (value->op == EXPR_UNARY_PLUS)
355 *grp_rtrn = rtrn.ival;
357 *grp_rtrn = rtrn.ival - 1;
362 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
363 unsigned field, ExprDef *array_ndx, ExprDef *value)
365 struct xkb_group_action *act;
368 xkb_group_index_t t2;
370 act = (struct xkb_group_action *) action;
371 if (array_ndx != NULL) {
376 return ReportActionNotArray(keymap, action->type, field);
383 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
391 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
398 return ReportIllegal(keymap, action->type, field);
402 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
403 unsigned field, ExprDef *array_ndx, ExprDef *value)
405 struct xkb_group_action *act;
407 xkb_group_index_t t2;
409 act = (struct xkb_group_action *) action;
410 if ((array_ndx != NULL) && (field == F_Group))
411 return ReportActionNotArray(keymap, action->type, field);
412 if (field == F_Group) {
414 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
421 return ReportIllegal(keymap, action->type, field);
425 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
426 unsigned field, ExprDef *array_ndx, ExprDef *value)
429 struct xkb_pointer_action *act;
432 act = (struct xkb_pointer_action *) action;
433 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
434 return ReportActionNotArray(keymap, action->type, field);
436 if ((field == F_X) || (field == F_Y)) {
437 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
441 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
442 return ReportMismatch(keymap, action->type, field, "integer");
445 act->flags |= XkbSA_MoveAbsoluteX;
450 act->flags |= XkbSA_MoveAbsoluteY;
455 else if (field == F_Accel) {
456 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
457 return ReportMismatch(keymap, action->type, field, "boolean");
459 act->flags &= ~XkbSA_NoAcceleration;
461 act->flags |= XkbSA_NoAcceleration;
463 return ReportIllegal(keymap, action->type, field);
466 static const LookupEntry lockWhich[] = {
468 { "lock", XkbSA_LockNoUnlock },
469 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
470 { "unlock", XkbSA_LockNoLock },
475 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
476 unsigned field, ExprDef *array_ndx, ExprDef *value)
479 struct xkb_pointer_button_action *act;
481 act = (struct xkb_pointer_button_action *) action;
482 if (field == F_Button) {
483 if (array_ndx != NULL)
484 return ReportActionNotArray(keymap, action->type, field);
485 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
486 return ReportMismatch(keymap, action->type, field,
487 "integer (range 1..5)");
488 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
490 "Button must specify default or be in the range 1..5; "
491 "Illegal button value %d ignored\n", rtrn.ival);
494 act->button = rtrn.ival;
497 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
498 if (array_ndx != NULL)
499 return ReportActionNotArray(keymap, action->type, field);
500 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
501 return ReportMismatch(keymap, action->type, field,
503 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
504 act->flags |= rtrn.ival;
507 else if (field == F_Count) {
508 if (array_ndx != NULL)
509 return ReportActionNotArray(keymap, action->type, field);
510 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
511 return ReportMismatch(keymap, action->type, field, "integer");
512 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
514 "The count field must have a value in the range 0..255; "
515 "Illegal count %d ignored\n", rtrn.ival);
518 act->count = rtrn.ival;
521 return ReportIllegal(keymap, action->type, field);
524 static const LookupEntry ptrDflts[] = {
525 { "dfltbtn", XkbSA_AffectDfltBtn },
526 { "defaultbutton", XkbSA_AffectDfltBtn },
527 { "button", XkbSA_AffectDfltBtn },
532 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
533 unsigned field, ExprDef *array_ndx, ExprDef *value)
536 struct xkb_pointer_default_action *act;
538 act = (struct xkb_pointer_default_action *) action;
539 if (field == F_Affect) {
540 if (array_ndx != NULL)
541 return ReportActionNotArray(keymap, action->type, field);
542 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
543 return ReportMismatch(keymap, action->type, field,
544 "pointer component");
545 act->affect = rtrn.uval;
548 else if ((field == F_Button) || (field == F_Value)) {
550 if (array_ndx != NULL)
551 return ReportActionNotArray(keymap, action->type, field);
552 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
553 act->flags &= ~XkbSA_DfltBtnAbsolute;
554 btn = value->value.child;
557 act->flags |= XkbSA_DfltBtnAbsolute;
561 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
562 return ReportMismatch(keymap, action->type, field,
563 "integer (range 1..5)");
564 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
566 "New default button value must be in the range 1..5; "
567 "Illegal default button value %d ignored\n", rtrn.ival);
570 if (rtrn.ival == 0) {
572 "Cannot set default pointer button to \"default\"; "
573 "Illegal default button setting ignored\n");
577 act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival);
580 return ReportIllegal(keymap, action->type, field);
583 static const LookupEntry isoNames[] = {
584 { "mods", XkbSA_ISONoAffectMods },
585 { "modifiers", XkbSA_ISONoAffectMods },
586 { "group", XkbSA_ISONoAffectGroup },
587 { "groups", XkbSA_ISONoAffectGroup },
588 { "ptr", XkbSA_ISONoAffectPtr },
589 { "pointer", XkbSA_ISONoAffectPtr },
590 { "ctrls", XkbSA_ISONoAffectCtrls },
591 { "controls", XkbSA_ISONoAffectCtrls },
592 { "all", ~((unsigned) 0) },
598 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
599 unsigned field, ExprDef *array_ndx, ExprDef *value)
602 struct xkb_iso_action *act;
605 xkb_group_index_t group;
607 act = (struct xkb_iso_action *) action;
610 if (array_ndx != NULL)
611 return ReportActionNotArray(keymap, action->type, field);
613 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
614 act->flags = flags & (~XkbSA_ISODfltIsGroup);
615 act->real_mods = mods & 0xff;
616 act->vmods = (mods >> 8) & 0xff;
622 if (array_ndx != NULL)
623 return ReportActionNotArray(keymap, action->type, field);
625 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
626 act->flags = flags | XkbSA_ISODfltIsGroup;
633 if (array_ndx != NULL)
634 return ReportActionNotArray(keymap, action->type, field);
635 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
636 return ReportMismatch(keymap, action->type, field,
637 "keyboard component");
638 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
641 return ReportIllegal(keymap, action->type, field);
645 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
646 unsigned field, ExprDef *array_ndx, ExprDef *value)
649 struct xkb_switch_screen_action *act;
651 act = (struct xkb_switch_screen_action *) action;
652 if (field == F_Screen) {
654 if (array_ndx != NULL)
655 return ReportActionNotArray(keymap, action->type, field);
656 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
657 act->flags &= ~XkbSA_SwitchAbsolute;
658 scrn = value->value.child;
661 act->flags |= XkbSA_SwitchAbsolute;
665 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
666 return ReportMismatch(keymap, action->type, field,
668 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
670 "Screen index must be in the range 1..255; "
671 "Illegal screen value %d ignored\n", rtrn.ival);
674 if (value->op == EXPR_NEGATE)
675 act->screen = -rtrn.ival;
677 act->screen = rtrn.ival;
680 else if (field == F_Same) {
681 if (array_ndx != NULL)
682 return ReportActionNotArray(keymap, action->type, field);
683 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
684 return ReportMismatch(keymap, action->type, field, "boolean");
686 act->flags &= ~XkbSA_SwitchApplication;
688 act->flags |= XkbSA_SwitchApplication;
691 return ReportIllegal(keymap, action->type, field);
694 const LookupEntry ctrlNames[] = {
695 { "repeatkeys", XkbRepeatKeysMask },
696 { "repeat", XkbRepeatKeysMask },
697 { "autorepeat", XkbRepeatKeysMask },
698 { "slowkeys", XkbSlowKeysMask },
699 { "bouncekeys", XkbBounceKeysMask },
700 { "stickykeys", XkbStickyKeysMask },
701 { "mousekeys", XkbMouseKeysMask },
702 { "mousekeysaccel", XkbMouseKeysAccelMask },
703 { "accessxkeys", XkbAccessXKeysMask },
704 { "accessxtimeout", XkbAccessXTimeoutMask },
705 { "accessxfeedback", XkbAccessXFeedbackMask },
706 { "audiblebell", XkbAudibleBellMask },
707 { "ignoregrouplock", XkbIgnoreGroupLockMask },
708 { "all", XkbAllBooleanCtrlsMask },
716 HandleSetLockControls(struct xkb_keymap *keymap,
717 struct xkb_any_action *action,
718 unsigned field, ExprDef *array_ndx,
722 struct xkb_controls_action *act;
724 act = (struct xkb_controls_action *) action;
725 if (field == F_Controls) {
726 if (array_ndx != NULL)
727 return ReportActionNotArray(keymap, action->type, field);
728 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
729 return ReportMismatch(keymap, action->type, field,
731 act->ctrls = rtrn.uval;
734 return ReportIllegal(keymap, action->type, field);
737 static const LookupEntry evNames[] = {
738 { "press", XkbSA_MessageOnPress },
739 { "keypress", XkbSA_MessageOnPress },
740 { "release", XkbSA_MessageOnRelease },
741 { "keyrelease", XkbSA_MessageOnRelease },
742 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
748 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
749 unsigned field, ExprDef *array_ndx, ExprDef *value)
753 struct xkb_message_action *act;
755 act = (struct xkb_message_action *) action;
758 if (array_ndx != NULL)
759 return ReportActionNotArray(keymap, action->type, field);
760 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
761 return ReportMismatch(keymap, action->type, field,
763 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
765 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
769 if (array_ndx != NULL)
770 return ReportActionNotArray(keymap, action->type, field);
771 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
772 return ReportMismatch(keymap, action->type, field, "boolean");
774 act->flags |= XkbSA_MessageGenKeyEvent;
776 act->flags &= ~XkbSA_MessageGenKeyEvent;
780 if (array_ndx == NULL) {
783 if (!ExprResolveString(keymap->ctx, value, &str))
784 return ReportMismatch(keymap, action->type, field, "string");
787 if (len < 1 || len > 6) {
788 log_warn(keymap->ctx,
789 "An action message can hold only 6 bytes; "
790 "Extra %d bytes ignored\n", len - 6);
793 strncpy((char *) act->message, str, 6);
798 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
800 "Array subscript must be integer; "
801 "Illegal subscript ignored\n");
807 "An action message is at most 6 bytes long; "
808 "Attempt to use data[%d] ignored\n", ndx);
811 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
812 return ReportMismatch(keymap, action->type, field, "integer");
813 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
815 "Message data must be in the range 0..255; "
816 "Illegal datum %d ignored\n", rtrn.ival);
819 act->message[ndx] = rtrn.uval;
823 return ReportIllegal(keymap, action->type, field);
827 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
828 unsigned field, ExprDef *array_ndx, ExprDef *value)
831 struct xkb_redirect_key_action *act;
835 char key_name[XkbKeyNameLength];
837 if (array_ndx != NULL)
838 return ReportActionNotArray(keymap, action->type, field);
840 act = (struct xkb_redirect_key_action *) action;
843 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
844 return ReportMismatch(keymap, action->type, field, "key name");
846 tmp = KeyNameToLong(key_name);
847 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
849 return ReportNotFound(keymap, action->type, field, "Key",
850 KeyNameText(key_name));
851 act->new_kc = XkbKeyGetKeycode(keymap, key);
857 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
858 act->mods_mask |= (t2 & 0xff);
859 if (field == F_Modifiers)
860 act->mods |= (t2 & 0xff);
862 act->mods &= ~(t2 & 0xff);
864 t2 = (t2 >> 8) & 0xffff;
865 act->vmods_mask |= t2;
866 if (field == F_Modifiers)
874 return ReportIllegal(keymap, action->type, field);
878 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
879 unsigned field, ExprDef *array_ndx, ExprDef *value)
882 struct xkb_device_button_action *act;
884 act = (struct xkb_device_button_action *) action;
885 if (field == F_Button) {
886 if (array_ndx != NULL)
887 return ReportActionNotArray(keymap, action->type, field);
888 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
889 return ReportMismatch(keymap, action->type, field,
890 "integer (range 1..255)");
891 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
893 "Button must specify default or be in the range 1..255; "
894 "Illegal button value %d ignored\n", rtrn.ival);
897 act->button = rtrn.ival;
900 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
901 if (array_ndx != NULL)
902 return ReportActionNotArray(keymap, action->type, field);
903 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
904 return ReportMismatch(keymap, action->type, field,
906 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
907 act->flags |= rtrn.ival;
910 else if (field == F_Count) {
911 if (array_ndx != NULL)
912 return ReportActionNotArray(keymap, action->type, field);
913 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
914 return ReportMismatch(keymap, action->type, field, "integer");
915 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
917 "The count field must have a value in the range 0..255; "
918 "Illegal count %d ignored\n", rtrn.ival);
921 act->count = rtrn.ival;
924 else if (field == F_Device) {
925 if (array_ndx != NULL)
926 return ReportActionNotArray(keymap, action->type, field);
927 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
928 return ReportMismatch(keymap, action->type, field,
929 "integer (range 1..255)");
930 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
932 "Device must specify default or be in the range 1..255; "
933 "Illegal device value %d ignored\n", rtrn.ival);
936 act->device = rtrn.ival;
939 return ReportIllegal(keymap, action->type, field);
943 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
944 unsigned field, ExprDef *array_ndx, ExprDef *value)
948 struct xkb_device_valuator_action *act;
950 act = (struct xkb_device_valuator_action *) action;
951 /* XXX - Not yet implemented */
957 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
958 unsigned field, ExprDef *array_ndx, ExprDef *value)
964 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
965 return ReportMismatch(keymap, PrivateAction, field, "integer");
966 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
968 "Private action type must be in the range 0..255; "
969 "Illegal type %d ignored\n", rtrn.ival);
972 action->type = rtrn.uval;
976 if (array_ndx == NULL) {
980 if (!ExprResolveString(keymap->ctx, value, &str))
981 return ReportMismatch(keymap, action->type, field, "string");
984 if (len < 1 || len > 7) {
985 log_warn(keymap->ctx,
986 "A private action has 7 data bytes; "
987 "Extra %d bytes ignored\n", len - 6);
991 strncpy((char *) action->data, str, sizeof(action->data));
996 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
998 "Array subscript must be integer; "
999 "Illegal subscript ignored\n");
1003 if (ndx >= sizeof action->data) {
1004 log_err(keymap->ctx,
1005 "The data for a private action is 18 bytes long; "
1006 "Attempt to use data[%d] ignored\n", ndx);
1009 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1010 return ReportMismatch(keymap, action->type, field, "integer");
1011 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1012 log_err(keymap->ctx,
1013 "All data for a private action must be 0..255; "
1014 "Illegal datum %d ignored\n", rtrn.ival);
1017 action->data[ndx] = rtrn.uval;
1021 return ReportIllegal(keymap, PrivateAction, field);
1024 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1025 struct xkb_any_action *action, unsigned field,
1026 ExprDef *array_ndx, ExprDef *value);
1028 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1029 [XkbSA_NoAction] = HandleNoAction,
1030 [XkbSA_SetMods] = HandleSetLatchMods,
1031 [XkbSA_LatchMods] = HandleSetLatchMods,
1032 [XkbSA_LockMods] = HandleLockMods,
1033 [XkbSA_SetGroup] = HandleSetLatchGroup,
1034 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1035 [XkbSA_LockGroup] = HandleLockGroup,
1036 [XkbSA_MovePtr] = HandleMovePtr,
1037 [XkbSA_PtrBtn] = HandlePtrBtn,
1038 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1039 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1040 [XkbSA_ISOLock] = HandleISOLock,
1041 [XkbSA_Terminate] = HandleNoAction,
1042 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1043 [XkbSA_SetControls] = HandleSetLockControls,
1044 [XkbSA_LockControls] = HandleSetLockControls,
1045 [XkbSA_ActionMessage] = HandleActionMessage,
1046 [XkbSA_RedirectKey] = HandleRedirectKey,
1047 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1048 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1049 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1050 [PrivateAction] = HandlePrivate,
1053 /***====================================================================***/
1056 ApplyActionFactoryDefaults(union xkb_action * action)
1058 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1059 action->dflt.affect = XkbSA_AffectDfltBtn;
1060 action->dflt.flags = 0;
1061 action->dflt.value = 1;
1063 else if (action->type == XkbSA_ISOLock) {
1064 action->iso.real_mods = LockMask;
1069 ActionsInit(struct xkb_context *ctx);
1072 HandleActionDef(ExprDef * def,
1073 struct xkb_keymap *keymap,
1074 struct xkb_any_action *action, ActionInfo *info)
1078 unsigned tmp, hndlrType;
1080 if (!actionsInitialized)
1081 ActionsInit(keymap->ctx);
1083 if (def->op != EXPR_ACTION_DECL) {
1084 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1085 exprOpText(def->op));
1088 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1090 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1093 if (!stringToAction(str, &tmp)) {
1094 log_err(keymap->ctx, "Unknown action %s\n", str);
1097 action->type = hndlrType = tmp;
1098 if (action->type != XkbSA_NoAction) {
1099 ApplyActionFactoryDefaults((union xkb_action *) action);
1102 if ((info->action == XkbSA_NoAction)
1103 || (info->action == hndlrType)) {
1104 if (!(*handleAction[hndlrType])(keymap, action,
1114 for (arg = def->value.action.args; arg != NULL;
1115 arg = (ExprDef *) arg->common.next) {
1116 ExprDef *field, *value, *arrayRtrn;
1117 const char *elemRtrn, *fieldRtrn;
1120 if (arg->op == EXPR_ASSIGN) {
1121 field = arg->value.binary.left;
1122 value = arg->value.binary.right;
1125 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1126 field = arg->value.child;
1127 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1128 value = &constFalse;
1132 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1136 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1138 return false; /* internal error -- already reported */
1140 if (elemRtrn != NULL) {
1141 log_err(keymap->ctx,
1142 "Cannot change defaults in an action definition; "
1143 "Ignoring attempt to change %s.%s\n",
1144 elemRtrn, fieldRtrn);
1147 if (!stringToField(fieldRtrn, &fieldNdx)) {
1148 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1151 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1158 /***====================================================================***/
1161 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1162 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1164 ActionInfo *new, *old;
1166 if (!actionsInitialized)
1167 ActionsInit(keymap->ctx);
1169 new = malloc(sizeof(*new));
1171 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1175 if (istreq(elem, "action"))
1176 new->action = XkbSA_NoAction;
1178 if (!stringToAction(elem, &new->action)) {
1182 if (new->action == XkbSA_NoAction) {
1183 log_err(keymap->ctx,
1184 "\"%s\" is not a valid field in a NoAction action\n",
1190 if (!stringToField(field, &new->field)) {
1191 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1195 new->array_ndx = array_ndx;
1199 while ((old) && (old->next))
1208 /***====================================================================***/
1211 ActionsInit(struct xkb_context *ctx)
1213 if (!actionsInitialized) {
1214 memset(&constTrue, 0, sizeof(constTrue));
1215 memset(&constFalse, 0, sizeof(constFalse));
1216 constTrue.common.type = STMT_EXPR;
1217 constTrue.common.next = NULL;
1218 constTrue.op = EXPR_IDENT;
1219 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1220 constTrue.value.str = xkb_atom_intern(ctx, "true");
1221 constFalse.common.type = STMT_EXPR;
1222 constFalse.common.next = NULL;
1223 constFalse.op = EXPR_IDENT;
1224 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1225 constFalse.value.str = xkb_atom_intern(ctx, "false");
1226 actionsInitialized = 1;
1231 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1234 size_t old_ndx, old_num_acts, new_ndx;
1237 key->acts_index = 0;
1241 if (XkbKeyHasActions(key) && key->width >= needed)
1242 return XkbKeyActionsPtr(keymap, key);
1245 * The key may already be in the array, but without enough space.
1246 * This should not happen often, so in order to avoid moving and
1247 * copying stuff from acts and key_acts, we just allocate new
1248 * space for the key at the end, and leave the old space alone.
1251 old_ndx = key->acts_index;
1252 old_num_acts = XkbKeyNumActions(key);
1253 new_ndx = darray_size(keymap->acts);
1255 darray_resize0(keymap->acts, new_ndx + needed);
1256 key->acts_index = new_ndx;
1259 * The key was already in the array, copy the old actions to the
1263 memcpy(darray_mem(keymap->acts, new_ndx),
1264 darray_mem(keymap->acts, old_ndx),
1265 old_num_acts * sizeof(union xkb_action));
1267 return XkbKeyActionsPtr(keymap, key);