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)
247 if (value->op == ExprIdent) {
249 valStr = xkb_atom_text(keymap->ctx, value->value.str);
250 if (valStr && (istreq(valStr, "usemodmapmods") ||
251 istreq(valStr, "modmapmods"))) {
254 *flags_inout |= XkbSA_UseModMapMods;
259 if (!ExprResolveVModMask(keymap, value, &rtrn))
260 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
262 *mods_rtrn = (xkb_mod_mask_t) rtrn.ival;
263 *flags_inout &= ~XkbSA_UseModMapMods;
268 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
269 unsigned field, ExprDef *array_ndx, ExprDef *value)
271 struct xkb_mod_action *act;
276 act = (struct xkb_mod_action *) action;
277 if (array_ndx != NULL) {
282 return ReportActionNotArray(keymap, action->type, field);
289 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
297 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
299 act->real_mods = act->mask = (t2 & 0xff);
300 act->vmods = (t2 >> 8) & 0xffff;
305 return ReportIllegal(keymap, action->type, field);
309 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
310 unsigned field, ExprDef *array_ndx, ExprDef *value)
312 struct xkb_mod_action *act;
316 act = (struct xkb_mod_action *) action;
317 if ((array_ndx != NULL) && (field == F_Modifiers))
318 return ReportActionNotArray(keymap, action->type, field);
322 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
324 act->real_mods = act->mask = (t2 & 0xff);
325 act->vmods = (t2 >> 8) & 0xffff;
330 return ReportIllegal(keymap, action->type, field);
334 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
335 ExprDef * value, unsigned *flags_inout,
336 xkb_group_index_t *grp_rtrn)
341 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
342 *flags_inout &= ~XkbSA_GroupAbsolute;
343 spec = value->value.child;
346 *flags_inout |= XkbSA_GroupAbsolute;
350 if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
351 return ReportMismatch(keymap, action, F_Group,
352 "integer (range 1..8)");
353 if (value->op == OpNegate)
354 *grp_rtrn = -rtrn.ival;
355 else if (value->op == OpUnaryPlus)
356 *grp_rtrn = rtrn.ival;
358 *grp_rtrn = rtrn.ival - 1;
363 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
364 unsigned field, ExprDef *array_ndx, ExprDef *value)
366 struct xkb_group_action *act;
369 xkb_group_index_t t2;
371 act = (struct xkb_group_action *) action;
372 if (array_ndx != NULL) {
377 return ReportActionNotArray(keymap, action->type, field);
384 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
392 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
399 return ReportIllegal(keymap, action->type, field);
403 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
404 unsigned field, ExprDef *array_ndx, ExprDef *value)
406 struct xkb_group_action *act;
408 xkb_group_index_t t2;
410 act = (struct xkb_group_action *) action;
411 if ((array_ndx != NULL) && (field == F_Group))
412 return ReportActionNotArray(keymap, action->type, field);
413 if (field == F_Group) {
415 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
422 return ReportIllegal(keymap, action->type, field);
426 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
427 unsigned field, ExprDef *array_ndx, ExprDef *value)
430 struct xkb_pointer_action *act;
433 act = (struct xkb_pointer_action *) action;
434 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
435 return ReportActionNotArray(keymap, action->type, field);
437 if ((field == F_X) || (field == F_Y)) {
438 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
442 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
443 return ReportMismatch(keymap, action->type, field, "integer");
446 act->flags |= XkbSA_MoveAbsoluteX;
451 act->flags |= XkbSA_MoveAbsoluteY;
456 else if (field == F_Accel) {
457 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
458 return ReportMismatch(keymap, action->type, field, "boolean");
460 act->flags &= ~XkbSA_NoAcceleration;
462 act->flags |= XkbSA_NoAcceleration;
464 return ReportIllegal(keymap, action->type, field);
467 static const LookupEntry lockWhich[] = {
469 { "lock", XkbSA_LockNoUnlock },
470 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
471 { "unlock", XkbSA_LockNoLock },
476 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
477 unsigned field, ExprDef *array_ndx, ExprDef *value)
480 struct xkb_pointer_button_action *act;
482 act = (struct xkb_pointer_button_action *) action;
483 if (field == F_Button) {
484 if (array_ndx != NULL)
485 return ReportActionNotArray(keymap, action->type, field);
486 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
487 return ReportMismatch(keymap, action->type, field,
488 "integer (range 1..5)");
489 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
491 "Button must specify default or be in the range 1..5; "
492 "Illegal button value %d ignored\n", rtrn.ival);
495 act->button = rtrn.ival;
498 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
499 if (array_ndx != NULL)
500 return ReportActionNotArray(keymap, action->type, field);
501 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
502 return ReportMismatch(keymap, action->type, field,
504 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
505 act->flags |= rtrn.ival;
508 else if (field == F_Count) {
509 if (array_ndx != NULL)
510 return ReportActionNotArray(keymap, action->type, field);
511 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
512 return ReportMismatch(keymap, action->type, field, "integer");
513 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
515 "The count field must have a value in the range 0..255; "
516 "Illegal count %d ignored\n", rtrn.ival);
519 act->count = rtrn.ival;
522 return ReportIllegal(keymap, action->type, field);
525 static const LookupEntry ptrDflts[] = {
526 { "dfltbtn", XkbSA_AffectDfltBtn },
527 { "defaultbutton", XkbSA_AffectDfltBtn },
528 { "button", XkbSA_AffectDfltBtn },
533 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
534 unsigned field, ExprDef *array_ndx, ExprDef *value)
537 struct xkb_pointer_default_action *act;
539 act = (struct xkb_pointer_default_action *) action;
540 if (field == F_Affect) {
541 if (array_ndx != NULL)
542 return ReportActionNotArray(keymap, action->type, field);
543 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
544 return ReportMismatch(keymap, action->type, field,
545 "pointer component");
546 act->affect = rtrn.uval;
549 else if ((field == F_Button) || (field == F_Value)) {
551 if (array_ndx != NULL)
552 return ReportActionNotArray(keymap, action->type, field);
553 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
554 act->flags &= ~XkbSA_DfltBtnAbsolute;
555 btn = value->value.child;
558 act->flags |= XkbSA_DfltBtnAbsolute;
562 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
563 return ReportMismatch(keymap, action->type, field,
564 "integer (range 1..5)");
565 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
567 "New default button value must be in the range 1..5; "
568 "Illegal default button value %d ignored\n", rtrn.ival);
571 if (rtrn.ival == 0) {
573 "Cannot set default pointer button to \"default\"; "
574 "Illegal default button setting ignored\n");
577 if (value->op == OpNegate)
578 act->value = -rtrn.ival;
580 act->value = rtrn.ival;
583 return ReportIllegal(keymap, action->type, field);
586 static const LookupEntry isoNames[] = {
587 { "mods", XkbSA_ISONoAffectMods },
588 { "modifiers", XkbSA_ISONoAffectMods },
589 { "group", XkbSA_ISONoAffectGroup },
590 { "groups", XkbSA_ISONoAffectGroup },
591 { "ptr", XkbSA_ISONoAffectPtr },
592 { "pointer", XkbSA_ISONoAffectPtr },
593 { "ctrls", XkbSA_ISONoAffectCtrls },
594 { "controls", XkbSA_ISONoAffectCtrls },
595 { "all", ~((unsigned) 0) },
601 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
602 unsigned field, ExprDef *array_ndx, ExprDef *value)
605 struct xkb_iso_action *act;
608 xkb_group_index_t group;
610 act = (struct xkb_iso_action *) action;
613 if (array_ndx != NULL)
614 return ReportActionNotArray(keymap, action->type, field);
616 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
617 act->flags = flags & (~XkbSA_ISODfltIsGroup);
618 act->real_mods = mods & 0xff;
619 act->vmods = (mods >> 8) & 0xff;
625 if (array_ndx != NULL)
626 return ReportActionNotArray(keymap, action->type, field);
628 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
629 act->flags = flags | XkbSA_ISODfltIsGroup;
636 if (array_ndx != NULL)
637 return ReportActionNotArray(keymap, action->type, field);
638 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
639 return ReportMismatch(keymap, action->type, field,
640 "keyboard component");
641 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
644 return ReportIllegal(keymap, action->type, field);
648 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
649 unsigned field, ExprDef *array_ndx, ExprDef *value)
652 struct xkb_switch_screen_action *act;
654 act = (struct xkb_switch_screen_action *) action;
655 if (field == F_Screen) {
657 if (array_ndx != NULL)
658 return ReportActionNotArray(keymap, action->type, field);
659 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
660 act->flags &= ~XkbSA_SwitchAbsolute;
661 scrn = value->value.child;
664 act->flags |= XkbSA_SwitchAbsolute;
668 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
669 return ReportMismatch(keymap, action->type, field,
671 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
673 "Screen index must be in the range 1..255; "
674 "Illegal screen value %d ignored\n", rtrn.ival);
677 if (value->op == OpNegate)
678 act->screen = -rtrn.ival;
680 act->screen = rtrn.ival;
683 else if (field == F_Same) {
684 if (array_ndx != NULL)
685 return ReportActionNotArray(keymap, action->type, field);
686 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
687 return ReportMismatch(keymap, action->type, field, "boolean");
689 act->flags &= ~XkbSA_SwitchApplication;
691 act->flags |= XkbSA_SwitchApplication;
694 return ReportIllegal(keymap, action->type, field);
697 const LookupEntry ctrlNames[] = {
698 { "repeatkeys", XkbRepeatKeysMask },
699 { "repeat", XkbRepeatKeysMask },
700 { "autorepeat", XkbRepeatKeysMask },
701 { "slowkeys", XkbSlowKeysMask },
702 { "bouncekeys", XkbBounceKeysMask },
703 { "stickykeys", XkbStickyKeysMask },
704 { "mousekeys", XkbMouseKeysMask },
705 { "mousekeysaccel", XkbMouseKeysAccelMask },
706 { "accessxkeys", XkbAccessXKeysMask },
707 { "accessxtimeout", XkbAccessXTimeoutMask },
708 { "accessxfeedback", XkbAccessXFeedbackMask },
709 { "audiblebell", XkbAudibleBellMask },
710 { "ignoregrouplock", XkbIgnoreGroupLockMask },
711 { "all", XkbAllBooleanCtrlsMask },
719 HandleSetLockControls(struct xkb_keymap *keymap,
720 struct xkb_any_action *action,
721 unsigned field, ExprDef *array_ndx,
725 struct xkb_controls_action *act;
727 act = (struct xkb_controls_action *) action;
728 if (field == F_Controls) {
729 if (array_ndx != NULL)
730 return ReportActionNotArray(keymap, action->type, field);
731 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
732 return ReportMismatch(keymap, action->type, field,
734 act->ctrls = rtrn.uval;
737 return ReportIllegal(keymap, action->type, field);
740 static const LookupEntry evNames[] = {
741 { "press", XkbSA_MessageOnPress },
742 { "keypress", XkbSA_MessageOnPress },
743 { "release", XkbSA_MessageOnRelease },
744 { "keyrelease", XkbSA_MessageOnRelease },
745 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
751 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
752 unsigned field, ExprDef *array_ndx, ExprDef *value)
755 struct xkb_message_action *act;
757 act = (struct xkb_message_action *) action;
760 if (array_ndx != NULL)
761 return ReportActionNotArray(keymap, action->type, field);
762 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
763 return ReportMismatch(keymap, action->type, field,
765 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
767 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
771 if (array_ndx != NULL)
772 return ReportActionNotArray(keymap, action->type, field);
773 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
774 return ReportMismatch(keymap, action->type, field, "boolean");
776 act->flags |= XkbSA_MessageGenKeyEvent;
778 act->flags &= ~XkbSA_MessageGenKeyEvent;
782 if (array_ndx == NULL) {
783 if (!ExprResolveString(keymap->ctx, value, &rtrn))
784 return ReportMismatch(keymap, action->type, field, "string");
786 int len = strlen(rtrn.str);
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);
792 strncpy((char *) act->message, rtrn.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)
832 struct xkb_redirect_key_action *act;
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, &rtrn))
844 return ReportMismatch(keymap, action->type, field, "key name");
846 tmp = KeyNameToLong(rtrn.name);
847 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
849 return ReportNotFound(keymap, action->type, field, "Key",
850 KeyNameText(rtrn.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) {
977 if (!ExprResolveString(keymap->ctx, value, &rtrn))
978 return ReportMismatch(keymap, action->type, field, "string");
980 int len = strlen(rtrn.str);
981 if ((len < 1) || (len > 7)) {
982 log_warn(keymap->ctx,
983 "A private action has 7 data bytes; "
984 "Extra %d bytes ignored\n", len - 6);
987 strncpy((char *) action->data, rtrn.str, sizeof action->data);
993 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
995 "Array subscript must be integer; "
996 "Illegal subscript ignored\n");
1000 if (ndx >= sizeof action->data) {
1001 log_err(keymap->ctx,
1002 "The data for a private action is 18 bytes long; "
1003 "Attempt to use data[%d] ignored\n", ndx);
1006 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1007 return ReportMismatch(keymap, action->type, field, "integer");
1008 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1009 log_err(keymap->ctx,
1010 "All data for a private action must be 0..255; "
1011 "Illegal datum %d ignored\n", rtrn.ival);
1014 action->data[ndx] = rtrn.uval;
1018 return ReportIllegal(keymap, PrivateAction, field);
1021 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1022 struct xkb_any_action *action, unsigned field,
1023 ExprDef *array_ndx, ExprDef *value);
1025 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1026 [XkbSA_NoAction] = HandleNoAction,
1027 [XkbSA_SetMods] = HandleSetLatchMods,
1028 [XkbSA_LatchMods] = HandleSetLatchMods,
1029 [XkbSA_LockMods] = HandleLockMods,
1030 [XkbSA_SetGroup] = HandleSetLatchGroup,
1031 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1032 [XkbSA_LockGroup] = HandleLockGroup,
1033 [XkbSA_MovePtr] = HandleMovePtr,
1034 [XkbSA_PtrBtn] = HandlePtrBtn,
1035 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1036 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1037 [XkbSA_ISOLock] = HandleISOLock,
1038 [XkbSA_Terminate] = HandleNoAction,
1039 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1040 [XkbSA_SetControls] = HandleSetLockControls,
1041 [XkbSA_LockControls] = HandleSetLockControls,
1042 [XkbSA_ActionMessage] = HandleActionMessage,
1043 [XkbSA_RedirectKey] = HandleRedirectKey,
1044 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1045 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1046 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1047 [PrivateAction] = HandlePrivate,
1050 /***====================================================================***/
1053 ApplyActionFactoryDefaults(union xkb_action * action)
1055 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1056 action->dflt.affect = XkbSA_AffectDfltBtn;
1057 action->dflt.flags = 0;
1058 action->dflt.value = 1;
1060 else if (action->type == XkbSA_ISOLock) {
1061 action->iso.real_mods = LockMask;
1066 ActionsInit(struct xkb_context *ctx);
1069 HandleActionDef(ExprDef * def,
1070 struct xkb_keymap *keymap,
1071 struct xkb_any_action *action, ActionInfo *info)
1075 unsigned tmp, hndlrType;
1077 if (!actionsInitialized)
1078 ActionsInit(keymap->ctx);
1080 if (def->op != ExprActionDecl) {
1081 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1082 exprOpText(def->op));
1085 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1087 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1090 if (!stringToAction(str, &tmp)) {
1091 log_err(keymap->ctx, "Unknown action %s\n", str);
1094 action->type = hndlrType = tmp;
1095 if (action->type != XkbSA_NoAction) {
1096 ApplyActionFactoryDefaults((union xkb_action *) action);
1099 if ((info->action == XkbSA_NoAction)
1100 || (info->action == hndlrType)) {
1101 if (!(*handleAction[hndlrType])(keymap, action,
1111 for (arg = def->value.action.args; arg != NULL;
1112 arg = (ExprDef *) arg->common.next) {
1113 ExprDef *field, *value, *arrayRtrn;
1114 ExprResult elemRtrn, fieldRtrn;
1117 if (arg->op == OpAssign) {
1118 field = arg->value.binary.left;
1119 value = arg->value.binary.right;
1122 if ((arg->op == OpNot) || (arg->op == OpInvert)) {
1123 field = arg->value.child;
1124 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1125 value = &constFalse;
1129 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1133 if (!ExprResolveLhs(keymap, field, &elemRtrn, &fieldRtrn, &arrayRtrn))
1134 return false; /* internal error -- already reported */
1136 if (elemRtrn.str != NULL) {
1137 log_err(keymap->ctx,
1138 "Cannot change defaults in an action definition; "
1139 "Ignoring attempt to change %s.%s\n",
1140 elemRtrn.str, fieldRtrn.str);
1143 if (!stringToField(fieldRtrn.str, &fieldNdx)) {
1144 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn.str);
1147 if (!(*handleAction[hndlrType])(keymap, action, fieldNdx, arrayRtrn,
1154 /***====================================================================***/
1157 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1158 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1160 ActionInfo *new, *old;
1162 if (!actionsInitialized)
1163 ActionsInit(keymap->ctx);
1165 new = malloc(sizeof(*new));
1167 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1171 if (istreq(elem, "action"))
1172 new->action = XkbSA_NoAction;
1174 if (!stringToAction(elem, &new->action)) {
1178 if (new->action == XkbSA_NoAction) {
1179 log_err(keymap->ctx,
1180 "\"%s\" is not a valid field in a NoAction action\n",
1186 if (!stringToField(field, &new->field)) {
1187 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1191 new->array_ndx = array_ndx;
1195 while ((old) && (old->next))
1204 /***====================================================================***/
1207 ActionsInit(struct xkb_context *ctx)
1209 if (!actionsInitialized) {
1210 memset(&constTrue, 0, sizeof(constTrue));
1211 memset(&constFalse, 0, sizeof(constFalse));
1212 constTrue.common.stmtType = StmtExpr;
1213 constTrue.common.next = NULL;
1214 constTrue.op = ExprIdent;
1215 constTrue.type = TypeBoolean;
1216 constTrue.value.str = xkb_atom_intern(ctx, "true");
1217 constFalse.common.stmtType = StmtExpr;
1218 constFalse.common.next = NULL;
1219 constFalse.op = ExprIdent;
1220 constFalse.type = TypeBoolean;
1221 constFalse.value.str = xkb_atom_intern(ctx, "false");
1222 actionsInitialized = 1;
1227 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1230 size_t old_ndx, old_num_acts, new_ndx;
1233 key->acts_index = 0;
1237 if (XkbKeyHasActions(key) && key->width >= needed)
1238 return XkbKeyActionsPtr(keymap, key);
1241 * The key may already be in the array, but without enough space.
1242 * This should not happen often, so in order to avoid moving and
1243 * copying stuff from acts and key_acts, we just allocate new
1244 * space for the key at the end, and leave the old space alone.
1247 old_ndx = key->acts_index;
1248 old_num_acts = XkbKeyNumActions(key);
1249 new_ndx = darray_size(keymap->acts);
1251 darray_resize0(keymap->acts, new_ndx + needed);
1252 key->acts_index = new_ndx;
1255 * The key was already in the array, copy the old actions to the
1259 memcpy(darray_mem(keymap->acts, new_ndx),
1260 darray_mem(keymap->acts, old_ndx),
1261 old_num_acts * sizeof(union xkb_action));
1263 return XkbKeyActionsPtr(keymap, key);