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! */
233 if (!ExprResolveBoolean(keymap->ctx, value, &result))
234 return ReportMismatch(keymap, action, field, "boolean");
239 *flags_inout &= ~tmp;
245 CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
246 unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn)
249 if (value->op == EXPR_IDENT) {
251 valStr = xkb_atom_text(keymap->ctx, value->value.str);
252 if (valStr && (istreq(valStr, "usemodmapmods") ||
253 istreq(valStr, "modmapmods"))) {
256 *flags_inout |= XkbSA_UseModMapMods;
261 if (!ExprResolveVModMask(keymap, value, &rtrn))
262 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
264 *mods_rtrn = (xkb_mod_mask_t) rtrn.ival;
265 *flags_inout &= ~XkbSA_UseModMapMods;
270 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
271 unsigned field, ExprDef *array_ndx, ExprDef *value)
273 struct xkb_mod_action *act;
278 act = (struct xkb_mod_action *) action;
279 if (array_ndx != NULL) {
284 return ReportActionNotArray(keymap, action->type, field);
291 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
299 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
301 act->real_mods = act->mask = (t2 & 0xff);
302 act->vmods = (t2 >> 8) & 0xffff;
307 return ReportIllegal(keymap, action->type, field);
311 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
312 unsigned field, ExprDef *array_ndx, ExprDef *value)
314 struct xkb_mod_action *act;
318 act = (struct xkb_mod_action *) action;
319 if ((array_ndx != NULL) && (field == F_Modifiers))
320 return ReportActionNotArray(keymap, action->type, field);
324 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
326 act->real_mods = act->mask = (t2 & 0xff);
327 act->vmods = (t2 >> 8) & 0xffff;
332 return ReportIllegal(keymap, action->type, field);
336 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
337 ExprDef * value, unsigned *flags_inout,
338 xkb_group_index_t *grp_rtrn)
343 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
344 *flags_inout &= ~XkbSA_GroupAbsolute;
345 spec = value->value.child;
348 *flags_inout |= XkbSA_GroupAbsolute;
352 if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
353 return ReportMismatch(keymap, action, F_Group,
354 "integer (range 1..8)");
355 if (value->op == EXPR_NEGATE)
356 *grp_rtrn = -rtrn.ival;
357 else if (value->op == EXPR_UNARY_PLUS)
358 *grp_rtrn = rtrn.ival;
360 *grp_rtrn = rtrn.ival - 1;
365 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
366 unsigned field, ExprDef *array_ndx, ExprDef *value)
368 struct xkb_group_action *act;
371 xkb_group_index_t t2;
373 act = (struct xkb_group_action *) action;
374 if (array_ndx != NULL) {
379 return ReportActionNotArray(keymap, action->type, field);
386 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
394 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
401 return ReportIllegal(keymap, action->type, field);
405 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
406 unsigned field, ExprDef *array_ndx, ExprDef *value)
408 struct xkb_group_action *act;
410 xkb_group_index_t t2;
412 act = (struct xkb_group_action *) action;
413 if ((array_ndx != NULL) && (field == F_Group))
414 return ReportActionNotArray(keymap, action->type, field);
415 if (field == F_Group) {
417 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
424 return ReportIllegal(keymap, action->type, field);
428 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
429 unsigned field, ExprDef *array_ndx, ExprDef *value)
432 struct xkb_pointer_action *act;
435 act = (struct xkb_pointer_action *) action;
436 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
437 return ReportActionNotArray(keymap, action->type, field);
439 if ((field == F_X) || (field == F_Y)) {
440 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
444 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
445 return ReportMismatch(keymap, action->type, field, "integer");
448 act->flags |= XkbSA_MoveAbsoluteX;
453 act->flags |= XkbSA_MoveAbsoluteY;
458 else if (field == F_Accel) {
461 if (!ExprResolveBoolean(keymap->ctx, value, &set))
462 return ReportMismatch(keymap, action->type, field, "boolean");
465 act->flags &= ~XkbSA_NoAcceleration;
467 act->flags |= XkbSA_NoAcceleration;
470 return ReportIllegal(keymap, action->type, field);
473 static const LookupEntry lockWhich[] = {
475 { "lock", XkbSA_LockNoUnlock },
476 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
477 { "unlock", XkbSA_LockNoLock },
482 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
483 unsigned field, ExprDef *array_ndx, ExprDef *value)
486 struct xkb_pointer_button_action *act;
488 act = (struct xkb_pointer_button_action *) action;
489 if (field == F_Button) {
490 if (array_ndx != NULL)
491 return ReportActionNotArray(keymap, action->type, field);
492 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
493 return ReportMismatch(keymap, action->type, field,
494 "integer (range 1..5)");
495 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
497 "Button must specify default or be in the range 1..5; "
498 "Illegal button value %d ignored\n", rtrn.ival);
501 act->button = rtrn.ival;
504 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
505 if (array_ndx != NULL)
506 return ReportActionNotArray(keymap, action->type, field);
507 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
508 return ReportMismatch(keymap, action->type, field,
510 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
511 act->flags |= rtrn.ival;
514 else if (field == F_Count) {
515 if (array_ndx != NULL)
516 return ReportActionNotArray(keymap, action->type, field);
517 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
518 return ReportMismatch(keymap, action->type, field, "integer");
519 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
521 "The count field must have a value in the range 0..255; "
522 "Illegal count %d ignored\n", rtrn.ival);
525 act->count = rtrn.ival;
528 return ReportIllegal(keymap, action->type, field);
531 static const LookupEntry ptrDflts[] = {
532 { "dfltbtn", XkbSA_AffectDfltBtn },
533 { "defaultbutton", XkbSA_AffectDfltBtn },
534 { "button", XkbSA_AffectDfltBtn },
539 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
540 unsigned field, ExprDef *array_ndx, ExprDef *value)
543 struct xkb_pointer_default_action *act;
545 act = (struct xkb_pointer_default_action *) action;
546 if (field == F_Affect) {
547 if (array_ndx != NULL)
548 return ReportActionNotArray(keymap, action->type, field);
549 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
550 return ReportMismatch(keymap, action->type, field,
551 "pointer component");
552 act->affect = rtrn.uval;
555 else if ((field == F_Button) || (field == F_Value)) {
557 if (array_ndx != NULL)
558 return ReportActionNotArray(keymap, action->type, field);
559 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
560 act->flags &= ~XkbSA_DfltBtnAbsolute;
561 btn = value->value.child;
564 act->flags |= XkbSA_DfltBtnAbsolute;
568 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
569 return ReportMismatch(keymap, action->type, field,
570 "integer (range 1..5)");
571 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
573 "New default button value must be in the range 1..5; "
574 "Illegal default button value %d ignored\n", rtrn.ival);
577 if (rtrn.ival == 0) {
579 "Cannot set default pointer button to \"default\"; "
580 "Illegal default button setting ignored\n");
584 act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival);
587 return ReportIllegal(keymap, action->type, field);
590 static const LookupEntry isoNames[] = {
591 { "mods", XkbSA_ISONoAffectMods },
592 { "modifiers", XkbSA_ISONoAffectMods },
593 { "group", XkbSA_ISONoAffectGroup },
594 { "groups", XkbSA_ISONoAffectGroup },
595 { "ptr", XkbSA_ISONoAffectPtr },
596 { "pointer", XkbSA_ISONoAffectPtr },
597 { "ctrls", XkbSA_ISONoAffectCtrls },
598 { "controls", XkbSA_ISONoAffectCtrls },
599 { "all", ~((unsigned) 0) },
605 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
606 unsigned field, ExprDef *array_ndx, ExprDef *value)
609 struct xkb_iso_action *act;
612 xkb_group_index_t group;
614 act = (struct xkb_iso_action *) action;
617 if (array_ndx != NULL)
618 return ReportActionNotArray(keymap, action->type, field);
620 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
621 act->flags = flags & (~XkbSA_ISODfltIsGroup);
622 act->real_mods = mods & 0xff;
623 act->vmods = (mods >> 8) & 0xff;
629 if (array_ndx != NULL)
630 return ReportActionNotArray(keymap, action->type, field);
632 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
633 act->flags = flags | XkbSA_ISODfltIsGroup;
640 if (array_ndx != NULL)
641 return ReportActionNotArray(keymap, action->type, field);
642 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
643 return ReportMismatch(keymap, action->type, field,
644 "keyboard component");
645 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
648 return ReportIllegal(keymap, action->type, field);
652 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
653 unsigned field, ExprDef *array_ndx, ExprDef *value)
656 struct xkb_switch_screen_action *act;
658 act = (struct xkb_switch_screen_action *) action;
659 if (field == F_Screen) {
661 if (array_ndx != NULL)
662 return ReportActionNotArray(keymap, action->type, field);
663 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
664 act->flags &= ~XkbSA_SwitchAbsolute;
665 scrn = value->value.child;
668 act->flags |= XkbSA_SwitchAbsolute;
672 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
673 return ReportMismatch(keymap, action->type, field,
675 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
677 "Screen index must be in the range 1..255; "
678 "Illegal screen value %d ignored\n", rtrn.ival);
681 if (value->op == EXPR_NEGATE)
682 act->screen = -rtrn.ival;
684 act->screen = rtrn.ival;
687 else if (field == F_Same) {
691 return ReportActionNotArray(keymap, action->type, field);
693 if (!ExprResolveBoolean(keymap->ctx, value, &set))
694 return ReportMismatch(keymap, action->type, field, "boolean");
697 act->flags &= ~XkbSA_SwitchApplication;
699 act->flags |= XkbSA_SwitchApplication;
704 return ReportIllegal(keymap, action->type, field);
707 const LookupEntry ctrlNames[] = {
708 { "repeatkeys", XkbRepeatKeysMask },
709 { "repeat", XkbRepeatKeysMask },
710 { "autorepeat", XkbRepeatKeysMask },
711 { "slowkeys", XkbSlowKeysMask },
712 { "bouncekeys", XkbBounceKeysMask },
713 { "stickykeys", XkbStickyKeysMask },
714 { "mousekeys", XkbMouseKeysMask },
715 { "mousekeysaccel", XkbMouseKeysAccelMask },
716 { "accessxkeys", XkbAccessXKeysMask },
717 { "accessxtimeout", XkbAccessXTimeoutMask },
718 { "accessxfeedback", XkbAccessXFeedbackMask },
719 { "audiblebell", XkbAudibleBellMask },
720 { "ignoregrouplock", XkbIgnoreGroupLockMask },
721 { "all", XkbAllBooleanCtrlsMask },
729 HandleSetLockControls(struct xkb_keymap *keymap,
730 struct xkb_any_action *action,
731 unsigned field, ExprDef *array_ndx,
735 struct xkb_controls_action *act;
737 act = (struct xkb_controls_action *) action;
738 if (field == F_Controls) {
739 if (array_ndx != NULL)
740 return ReportActionNotArray(keymap, action->type, field);
741 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
742 return ReportMismatch(keymap, action->type, field,
744 act->ctrls = rtrn.uval;
747 return ReportIllegal(keymap, action->type, field);
750 static const LookupEntry evNames[] = {
751 { "press", XkbSA_MessageOnPress },
752 { "keypress", XkbSA_MessageOnPress },
753 { "release", XkbSA_MessageOnRelease },
754 { "keyrelease", XkbSA_MessageOnRelease },
755 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
761 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
762 unsigned field, ExprDef *array_ndx, ExprDef *value)
767 struct xkb_message_action *act;
769 act = (struct xkb_message_action *) action;
772 if (array_ndx != NULL)
773 return ReportActionNotArray(keymap, action->type, field);
774 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
775 return ReportMismatch(keymap, action->type, field,
777 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
779 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
784 return ReportActionNotArray(keymap, action->type, field);
786 if (!ExprResolveBoolean(keymap->ctx, value, &set))
787 return ReportMismatch(keymap, action->type, field, "boolean");
790 act->flags |= XkbSA_MessageGenKeyEvent;
792 act->flags &= ~XkbSA_MessageGenKeyEvent;
797 if (array_ndx == NULL) {
800 if (!ExprResolveString(keymap->ctx, value, &str))
801 return ReportMismatch(keymap, action->type, field, "string");
804 if (len < 1 || len > 6) {
805 log_warn(keymap->ctx,
806 "An action message can hold only 6 bytes; "
807 "Extra %d bytes ignored\n", len - 6);
810 strncpy((char *) act->message, str, 6);
815 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
817 "Array subscript must be integer; "
818 "Illegal subscript ignored\n");
824 "An action message is at most 6 bytes long; "
825 "Attempt to use data[%d] ignored\n", ndx);
828 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
829 return ReportMismatch(keymap, action->type, field, "integer");
830 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
832 "Message data must be in the range 0..255; "
833 "Illegal datum %d ignored\n", rtrn.ival);
836 act->message[ndx] = rtrn.uval;
840 return ReportIllegal(keymap, action->type, field);
844 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
845 unsigned field, ExprDef *array_ndx, ExprDef *value)
848 struct xkb_redirect_key_action *act;
852 char key_name[XkbKeyNameLength];
854 if (array_ndx != NULL)
855 return ReportActionNotArray(keymap, action->type, field);
857 act = (struct xkb_redirect_key_action *) action;
860 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
861 return ReportMismatch(keymap, action->type, field, "key name");
863 tmp = KeyNameToLong(key_name);
864 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
866 return ReportNotFound(keymap, action->type, field, "Key",
867 KeyNameText(key_name));
868 act->new_kc = XkbKeyGetKeycode(keymap, key);
874 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
875 act->mods_mask |= (t2 & 0xff);
876 if (field == F_Modifiers)
877 act->mods |= (t2 & 0xff);
879 act->mods &= ~(t2 & 0xff);
881 t2 = (t2 >> 8) & 0xffff;
882 act->vmods_mask |= t2;
883 if (field == F_Modifiers)
891 return ReportIllegal(keymap, action->type, field);
895 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
896 unsigned field, ExprDef *array_ndx, ExprDef *value)
899 struct xkb_device_button_action *act;
901 act = (struct xkb_device_button_action *) action;
902 if (field == F_Button) {
903 if (array_ndx != NULL)
904 return ReportActionNotArray(keymap, action->type, field);
905 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
906 return ReportMismatch(keymap, action->type, field,
907 "integer (range 1..255)");
908 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
910 "Button must specify default or be in the range 1..255; "
911 "Illegal button value %d ignored\n", rtrn.ival);
914 act->button = rtrn.ival;
917 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
918 if (array_ndx != NULL)
919 return ReportActionNotArray(keymap, action->type, field);
920 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
921 return ReportMismatch(keymap, action->type, field,
923 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
924 act->flags |= rtrn.ival;
927 else if (field == F_Count) {
928 if (array_ndx != NULL)
929 return ReportActionNotArray(keymap, action->type, field);
930 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
931 return ReportMismatch(keymap, action->type, field, "integer");
932 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
934 "The count field must have a value in the range 0..255; "
935 "Illegal count %d ignored\n", rtrn.ival);
938 act->count = rtrn.ival;
941 else if (field == F_Device) {
942 if (array_ndx != NULL)
943 return ReportActionNotArray(keymap, action->type, field);
944 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
945 return ReportMismatch(keymap, action->type, field,
946 "integer (range 1..255)");
947 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
949 "Device must specify default or be in the range 1..255; "
950 "Illegal device value %d ignored\n", rtrn.ival);
953 act->device = rtrn.ival;
956 return ReportIllegal(keymap, action->type, field);
960 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
961 unsigned field, ExprDef *array_ndx, ExprDef *value)
965 struct xkb_device_valuator_action *act;
967 act = (struct xkb_device_valuator_action *) action;
968 /* XXX - Not yet implemented */
974 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
975 unsigned field, ExprDef *array_ndx, ExprDef *value)
981 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
982 return ReportMismatch(keymap, PrivateAction, field, "integer");
983 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
985 "Private action type must be in the range 0..255; "
986 "Illegal type %d ignored\n", rtrn.ival);
989 action->type = rtrn.uval;
993 if (array_ndx == NULL) {
997 if (!ExprResolveString(keymap->ctx, value, &str))
998 return ReportMismatch(keymap, action->type, field, "string");
1001 if (len < 1 || len > 7) {
1002 log_warn(keymap->ctx,
1003 "A private action has 7 data bytes; "
1004 "Extra %d bytes ignored\n", len - 6);
1008 strncpy((char *) action->data, str, sizeof(action->data));
1013 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
1014 log_err(keymap->ctx,
1015 "Array subscript must be integer; "
1016 "Illegal subscript ignored\n");
1020 if (ndx >= sizeof action->data) {
1021 log_err(keymap->ctx,
1022 "The data for a private action is 18 bytes long; "
1023 "Attempt to use data[%d] ignored\n", ndx);
1026 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1027 return ReportMismatch(keymap, action->type, field, "integer");
1028 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1029 log_err(keymap->ctx,
1030 "All data for a private action must be 0..255; "
1031 "Illegal datum %d ignored\n", rtrn.ival);
1034 action->data[ndx] = rtrn.uval;
1038 return ReportIllegal(keymap, PrivateAction, field);
1041 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1042 struct xkb_any_action *action, unsigned field,
1043 ExprDef *array_ndx, ExprDef *value);
1045 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1046 [XkbSA_NoAction] = HandleNoAction,
1047 [XkbSA_SetMods] = HandleSetLatchMods,
1048 [XkbSA_LatchMods] = HandleSetLatchMods,
1049 [XkbSA_LockMods] = HandleLockMods,
1050 [XkbSA_SetGroup] = HandleSetLatchGroup,
1051 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1052 [XkbSA_LockGroup] = HandleLockGroup,
1053 [XkbSA_MovePtr] = HandleMovePtr,
1054 [XkbSA_PtrBtn] = HandlePtrBtn,
1055 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1056 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1057 [XkbSA_ISOLock] = HandleISOLock,
1058 [XkbSA_Terminate] = HandleNoAction,
1059 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1060 [XkbSA_SetControls] = HandleSetLockControls,
1061 [XkbSA_LockControls] = HandleSetLockControls,
1062 [XkbSA_ActionMessage] = HandleActionMessage,
1063 [XkbSA_RedirectKey] = HandleRedirectKey,
1064 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1065 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1066 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1067 [PrivateAction] = HandlePrivate,
1070 /***====================================================================***/
1073 ApplyActionFactoryDefaults(union xkb_action * action)
1075 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1076 action->dflt.affect = XkbSA_AffectDfltBtn;
1077 action->dflt.flags = 0;
1078 action->dflt.value = 1;
1080 else if (action->type == XkbSA_ISOLock) {
1081 action->iso.real_mods = LockMask;
1086 ActionsInit(struct xkb_context *ctx);
1089 HandleActionDef(ExprDef * def,
1090 struct xkb_keymap *keymap,
1091 struct xkb_any_action *action, ActionInfo *info)
1095 unsigned tmp, hndlrType;
1097 if (!actionsInitialized)
1098 ActionsInit(keymap->ctx);
1100 if (def->op != EXPR_ACTION_DECL) {
1101 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1102 exprOpText(def->op));
1105 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1107 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1110 if (!stringToAction(str, &tmp)) {
1111 log_err(keymap->ctx, "Unknown action %s\n", str);
1114 action->type = hndlrType = tmp;
1115 if (action->type != XkbSA_NoAction) {
1116 ApplyActionFactoryDefaults((union xkb_action *) action);
1119 if ((info->action == XkbSA_NoAction)
1120 || (info->action == hndlrType)) {
1121 if (!(*handleAction[hndlrType])(keymap, action,
1131 for (arg = def->value.action.args; arg != NULL;
1132 arg = (ExprDef *) arg->common.next) {
1133 ExprDef *field, *value, *arrayRtrn;
1134 const char *elemRtrn, *fieldRtrn;
1137 if (arg->op == EXPR_ASSIGN) {
1138 field = arg->value.binary.left;
1139 value = arg->value.binary.right;
1142 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1143 field = arg->value.child;
1144 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1145 value = &constFalse;
1149 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1153 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1155 return false; /* internal error -- already reported */
1157 if (elemRtrn != NULL) {
1158 log_err(keymap->ctx,
1159 "Cannot change defaults in an action definition; "
1160 "Ignoring attempt to change %s.%s\n",
1161 elemRtrn, fieldRtrn);
1164 if (!stringToField(fieldRtrn, &fieldNdx)) {
1165 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1168 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1175 /***====================================================================***/
1178 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1179 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1181 ActionInfo *new, *old;
1183 if (!actionsInitialized)
1184 ActionsInit(keymap->ctx);
1186 new = malloc(sizeof(*new));
1188 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1192 if (istreq(elem, "action"))
1193 new->action = XkbSA_NoAction;
1195 if (!stringToAction(elem, &new->action)) {
1199 if (new->action == XkbSA_NoAction) {
1200 log_err(keymap->ctx,
1201 "\"%s\" is not a valid field in a NoAction action\n",
1207 if (!stringToField(field, &new->field)) {
1208 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1212 new->array_ndx = array_ndx;
1216 while ((old) && (old->next))
1225 /***====================================================================***/
1228 ActionsInit(struct xkb_context *ctx)
1230 if (!actionsInitialized) {
1231 memset(&constTrue, 0, sizeof(constTrue));
1232 memset(&constFalse, 0, sizeof(constFalse));
1233 constTrue.common.type = STMT_EXPR;
1234 constTrue.common.next = NULL;
1235 constTrue.op = EXPR_IDENT;
1236 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1237 constTrue.value.str = xkb_atom_intern(ctx, "true");
1238 constFalse.common.type = STMT_EXPR;
1239 constFalse.common.next = NULL;
1240 constFalse.op = EXPR_IDENT;
1241 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1242 constFalse.value.str = xkb_atom_intern(ctx, "false");
1243 actionsInitialized = 1;
1248 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1251 size_t old_ndx, old_num_acts, new_ndx;
1254 key->acts_index = 0;
1258 if (XkbKeyHasActions(key) && key->width >= needed)
1259 return XkbKeyActionsPtr(keymap, key);
1262 * The key may already be in the array, but without enough space.
1263 * This should not happen often, so in order to avoid moving and
1264 * copying stuff from acts and key_acts, we just allocate new
1265 * space for the key at the end, and leave the old space alone.
1268 old_ndx = key->acts_index;
1269 old_num_acts = XkbKeyNumActions(key);
1270 new_ndx = darray_size(keymap->acts);
1272 darray_resize0(keymap->acts, new_ndx + needed);
1273 key->acts_index = new_ndx;
1276 * The key was already in the array, copy the old actions to the
1280 memcpy(darray_mem(keymap->acts, new_ndx),
1281 darray_mem(keymap->acts, old_ndx),
1282 old_num_acts * sizeof(union xkb_action));
1284 return XkbKeyActionsPtr(keymap, key);