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 (strcasecmp(entry->name, string) == 0) {
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, XkbcActionTypeText(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), XkbcActionTypeText(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), XkbcActionTypeText(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), XkbcActionTypeText(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, unsigned *mods_rtrn)
247 if (value->op == ExprIdent) {
249 valStr = xkb_atom_text(keymap->ctx, value->value.str);
250 if (valStr && ((strcasecmp(valStr, "usemodmapmods") == 0) ||
251 (strcasecmp(valStr, "modmapmods") == 0))) {
254 *flags_inout |= XkbSA_UseModMapMods;
258 if (!ExprResolveVModMask(keymap, value, &rtrn))
259 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
260 *mods_rtrn = rtrn.uval;
261 *flags_inout &= ~XkbSA_UseModMapMods;
266 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
267 unsigned field, ExprDef *array_ndx, ExprDef *value)
269 struct xkb_mod_action *act;
273 act = (struct xkb_mod_action *) action;
274 if (array_ndx != NULL) {
279 return ReportActionNotArray(keymap, action->type, field);
286 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
294 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
296 act->real_mods = act->mask = (t2 & 0xff);
297 act->vmods = (t2 >> 8) & 0xffff;
302 return ReportIllegal(keymap, action->type, field);
306 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
307 unsigned field, ExprDef *array_ndx, ExprDef *value)
309 struct xkb_mod_action *act;
312 act = (struct xkb_mod_action *) action;
313 if ((array_ndx != NULL) && (field == F_Modifiers))
314 return ReportActionNotArray(keymap, action->type, field);
318 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
320 act->real_mods = act->mask = (t2 & 0xff);
321 act->vmods = (t2 >> 8) & 0xffff;
326 return ReportIllegal(keymap, action->type, field);
330 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
331 ExprDef * value, unsigned *flags_inout,
332 xkb_group_index_t *grp_rtrn)
337 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
338 *flags_inout &= ~XkbSA_GroupAbsolute;
339 spec = value->value.child;
342 *flags_inout |= XkbSA_GroupAbsolute;
346 if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
347 return ReportMismatch(keymap, action, F_Group,
348 "integer (range 1..8)");
349 if (value->op == OpNegate)
350 *grp_rtrn = -rtrn.ival;
351 else if (value->op == OpUnaryPlus)
352 *grp_rtrn = rtrn.ival;
354 *grp_rtrn = rtrn.ival - 1;
359 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
360 unsigned field, ExprDef *array_ndx, ExprDef *value)
362 struct xkb_group_action *act;
365 xkb_group_index_t t2;
367 act = (struct xkb_group_action *) action;
368 if (array_ndx != NULL) {
373 return ReportActionNotArray(keymap, action->type, field);
380 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
388 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
395 return ReportIllegal(keymap, action->type, field);
399 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
400 unsigned field, ExprDef *array_ndx, ExprDef *value)
402 struct xkb_group_action *act;
404 xkb_group_index_t t2;
406 act = (struct xkb_group_action *) action;
407 if ((array_ndx != NULL) && (field == F_Group))
408 return ReportActionNotArray(keymap, action->type, field);
409 if (field == F_Group) {
411 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
418 return ReportIllegal(keymap, action->type, field);
422 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
423 unsigned field, ExprDef *array_ndx, ExprDef *value)
426 struct xkb_pointer_action *act;
429 act = (struct xkb_pointer_action *) action;
430 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
431 return ReportActionNotArray(keymap, action->type, field);
433 if ((field == F_X) || (field == F_Y)) {
434 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
438 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
439 return ReportMismatch(keymap, action->type, field, "integer");
442 act->flags |= XkbSA_MoveAbsoluteX;
447 act->flags |= XkbSA_MoveAbsoluteY;
452 else if (field == F_Accel) {
453 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
454 return ReportMismatch(keymap, action->type, field, "boolean");
456 act->flags &= ~XkbSA_NoAcceleration;
458 act->flags |= XkbSA_NoAcceleration;
460 return ReportIllegal(keymap, action->type, field);
463 static const LookupEntry lockWhich[] = {
465 { "lock", XkbSA_LockNoUnlock },
466 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
467 { "unlock", XkbSA_LockNoLock },
472 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
473 unsigned field, ExprDef *array_ndx, ExprDef *value)
476 struct xkb_pointer_button_action *act;
478 act = (struct xkb_pointer_button_action *) action;
479 if (field == F_Button) {
480 if (array_ndx != NULL)
481 return ReportActionNotArray(keymap, action->type, field);
482 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
483 return ReportMismatch(keymap, action->type, field,
484 "integer (range 1..5)");
485 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
487 "Button must specify default or be in the range 1..5; "
488 "Illegal button value %d ignored\n", rtrn.ival);
491 act->button = rtrn.ival;
494 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
495 if (array_ndx != NULL)
496 return ReportActionNotArray(keymap, action->type, field);
497 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
498 return ReportMismatch(keymap, action->type, field,
500 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
501 act->flags |= rtrn.ival;
504 else if (field == F_Count) {
505 if (array_ndx != NULL)
506 return ReportActionNotArray(keymap, action->type, field);
507 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
508 return ReportMismatch(keymap, action->type, field, "integer");
509 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
511 "The count field must have a value in the range 0..255; "
512 "Illegal count %d ignored\n", rtrn.ival);
515 act->count = rtrn.ival;
518 return ReportIllegal(keymap, action->type, field);
521 static const LookupEntry ptrDflts[] = {
522 { "dfltbtn", XkbSA_AffectDfltBtn },
523 { "defaultbutton", XkbSA_AffectDfltBtn },
524 { "button", XkbSA_AffectDfltBtn },
529 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
530 unsigned field, ExprDef *array_ndx, ExprDef *value)
533 struct xkb_pointer_default_action *act;
535 act = (struct xkb_pointer_default_action *) action;
536 if (field == F_Affect) {
537 if (array_ndx != NULL)
538 return ReportActionNotArray(keymap, action->type, field);
539 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
540 return ReportMismatch(keymap, action->type, field,
541 "pointer component");
542 act->affect = rtrn.uval;
545 else if ((field == F_Button) || (field == F_Value)) {
547 if (array_ndx != NULL)
548 return ReportActionNotArray(keymap, action->type, field);
549 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
550 act->flags &= ~XkbSA_DfltBtnAbsolute;
551 btn = value->value.child;
554 act->flags |= XkbSA_DfltBtnAbsolute;
558 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
559 return ReportMismatch(keymap, action->type, field,
560 "integer (range 1..5)");
561 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
563 "New default button value must be in the range 1..5; "
564 "Illegal default button value %d ignored\n", rtrn.ival);
567 if (rtrn.ival == 0) {
569 "Cannot set default pointer button to \"default\"; "
570 "Illegal default button setting ignored\n");
573 if (value->op == OpNegate)
574 act->value = -rtrn.ival;
576 act->value = rtrn.ival;
579 return ReportIllegal(keymap, action->type, field);
582 static const LookupEntry isoNames[] = {
583 { "mods", XkbSA_ISONoAffectMods },
584 { "modifiers", XkbSA_ISONoAffectMods },
585 { "group", XkbSA_ISONoAffectGroup },
586 { "groups", XkbSA_ISONoAffectGroup },
587 { "ptr", XkbSA_ISONoAffectPtr },
588 { "pointer", XkbSA_ISONoAffectPtr },
589 { "ctrls", XkbSA_ISONoAffectCtrls },
590 { "controls", XkbSA_ISONoAffectCtrls },
591 { "all", ~((unsigned) 0) },
597 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
598 unsigned field, ExprDef *array_ndx, ExprDef *value)
601 struct xkb_iso_action *act;
602 unsigned flags, mods;
603 xkb_group_index_t group;
605 act = (struct xkb_iso_action *) action;
608 if (array_ndx != NULL)
609 return ReportActionNotArray(keymap, action->type, field);
611 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
612 act->flags = flags & (~XkbSA_ISODfltIsGroup);
613 act->real_mods = mods & 0xff;
614 act->vmods = (mods >> 8) & 0xff;
620 if (array_ndx != NULL)
621 return ReportActionNotArray(keymap, action->type, field);
623 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
624 act->flags = flags | XkbSA_ISODfltIsGroup;
631 if (array_ndx != NULL)
632 return ReportActionNotArray(keymap, action->type, field);
633 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
634 return ReportMismatch(keymap, action->type, field,
635 "keyboard component");
636 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
639 return ReportIllegal(keymap, action->type, field);
643 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
644 unsigned field, ExprDef *array_ndx, ExprDef *value)
647 struct xkb_switch_screen_action *act;
649 act = (struct xkb_switch_screen_action *) action;
650 if (field == F_Screen) {
652 if (array_ndx != NULL)
653 return ReportActionNotArray(keymap, action->type, field);
654 if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) {
655 act->flags &= ~XkbSA_SwitchAbsolute;
656 scrn = value->value.child;
659 act->flags |= XkbSA_SwitchAbsolute;
663 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
664 return ReportMismatch(keymap, action->type, field,
666 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
668 "Screen index must be in the range 1..255; "
669 "Illegal screen value %d ignored\n", rtrn.ival);
672 if (value->op == OpNegate)
673 act->screen = -rtrn.ival;
675 act->screen = rtrn.ival;
678 else if (field == F_Same) {
679 if (array_ndx != NULL)
680 return ReportActionNotArray(keymap, action->type, field);
681 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
682 return ReportMismatch(keymap, action->type, field, "boolean");
684 act->flags &= ~XkbSA_SwitchApplication;
686 act->flags |= XkbSA_SwitchApplication;
689 return ReportIllegal(keymap, action->type, field);
692 const LookupEntry ctrlNames[] = {
693 { "repeatkeys", XkbRepeatKeysMask },
694 { "repeat", XkbRepeatKeysMask },
695 { "autorepeat", XkbRepeatKeysMask },
696 { "slowkeys", XkbSlowKeysMask },
697 { "bouncekeys", XkbBounceKeysMask },
698 { "stickykeys", XkbStickyKeysMask },
699 { "mousekeys", XkbMouseKeysMask },
700 { "mousekeysaccel", XkbMouseKeysAccelMask },
701 { "accessxkeys", XkbAccessXKeysMask },
702 { "accessxtimeout", XkbAccessXTimeoutMask },
703 { "accessxfeedback", XkbAccessXFeedbackMask },
704 { "audiblebell", XkbAudibleBellMask },
705 { "ignoregrouplock", XkbIgnoreGroupLockMask },
706 { "all", XkbAllBooleanCtrlsMask },
714 HandleSetLockControls(struct xkb_keymap *keymap,
715 struct xkb_any_action *action,
716 unsigned field, ExprDef *array_ndx,
720 struct xkb_controls_action *act;
722 act = (struct xkb_controls_action *) action;
723 if (field == F_Controls) {
724 if (array_ndx != NULL)
725 return ReportActionNotArray(keymap, action->type, field);
726 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
727 return ReportMismatch(keymap, action->type, field,
729 act->ctrls = rtrn.uval;
732 return ReportIllegal(keymap, action->type, field);
735 static const LookupEntry evNames[] = {
736 { "press", XkbSA_MessageOnPress },
737 { "keypress", XkbSA_MessageOnPress },
738 { "release", XkbSA_MessageOnRelease },
739 { "keyrelease", XkbSA_MessageOnRelease },
740 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
746 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
747 unsigned field, ExprDef *array_ndx, ExprDef *value)
750 struct xkb_message_action *act;
752 act = (struct xkb_message_action *) action;
755 if (array_ndx != NULL)
756 return ReportActionNotArray(keymap, action->type, field);
757 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
758 return ReportMismatch(keymap, action->type, field,
760 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
762 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
766 if (array_ndx != NULL)
767 return ReportActionNotArray(keymap, action->type, field);
768 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
769 return ReportMismatch(keymap, action->type, field, "boolean");
771 act->flags |= XkbSA_MessageGenKeyEvent;
773 act->flags &= ~XkbSA_MessageGenKeyEvent;
777 if (array_ndx == NULL) {
778 if (!ExprResolveString(keymap->ctx, value, &rtrn))
779 return ReportMismatch(keymap, action->type, field, "string");
781 int len = strlen(rtrn.str);
782 if ((len < 1) || (len > 6)) {
783 log_warn(keymap->ctx,
784 "An action message can hold only 6 bytes; "
785 "Extra %d bytes ignored\n", len - 6);
787 strncpy((char *) act->message, rtrn.str, 6);
793 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
795 "Array subscript must be integer; "
796 "Illegal subscript ignored\n");
802 "An action message is at most 6 bytes long; "
803 "Attempt to use data[%d] ignored\n", ndx);
806 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
807 return ReportMismatch(keymap, action->type, field, "integer");
808 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
810 "Message data must be in the range 0..255; "
811 "Illegal datum %d ignored\n", rtrn.ival);
814 act->message[ndx] = rtrn.uval;
818 return ReportIllegal(keymap, action->type, field);
822 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
823 unsigned field, ExprDef *array_ndx, ExprDef *value)
827 struct xkb_redirect_key_action *act;
831 if (array_ndx != NULL)
832 return ReportActionNotArray(keymap, action->type, field);
834 act = (struct xkb_redirect_key_action *) action;
837 if (!ExprResolveKeyName(keymap->ctx, value, &rtrn))
838 return ReportMismatch(keymap, action->type, field, "key name");
840 tmp = KeyNameToLong(rtrn.name);
841 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
843 return ReportNotFound(keymap, action->type, field, "Key",
844 XkbcKeyNameText(rtrn.name));
845 act->new_kc = XkbKeyGetKeycode(keymap, key);
851 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
852 act->mods_mask |= (t2 & 0xff);
853 if (field == F_Modifiers)
854 act->mods |= (t2 & 0xff);
856 act->mods &= ~(t2 & 0xff);
858 t2 = (t2 >> 8) & 0xffff;
859 act->vmods_mask |= t2;
860 if (field == F_Modifiers)
868 return ReportIllegal(keymap, action->type, field);
872 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
873 unsigned field, ExprDef *array_ndx, ExprDef *value)
876 struct xkb_device_button_action *act;
878 act = (struct xkb_device_button_action *) action;
879 if (field == F_Button) {
880 if (array_ndx != NULL)
881 return ReportActionNotArray(keymap, action->type, field);
882 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
883 return ReportMismatch(keymap, action->type, field,
884 "integer (range 1..255)");
885 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
887 "Button must specify default or be in the range 1..255; "
888 "Illegal button value %d ignored\n", rtrn.ival);
891 act->button = rtrn.ival;
894 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
895 if (array_ndx != NULL)
896 return ReportActionNotArray(keymap, action->type, field);
897 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
898 return ReportMismatch(keymap, action->type, field,
900 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
901 act->flags |= rtrn.ival;
904 else if (field == F_Count) {
905 if (array_ndx != NULL)
906 return ReportActionNotArray(keymap, action->type, field);
907 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
908 return ReportMismatch(keymap, action->type, field, "integer");
909 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
911 "The count field must have a value in the range 0..255; "
912 "Illegal count %d ignored\n", rtrn.ival);
915 act->count = rtrn.ival;
918 else if (field == F_Device) {
919 if (array_ndx != NULL)
920 return ReportActionNotArray(keymap, action->type, field);
921 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
922 return ReportMismatch(keymap, action->type, field,
923 "integer (range 1..255)");
924 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
926 "Device must specify default or be in the range 1..255; "
927 "Illegal device value %d ignored\n", rtrn.ival);
930 act->device = rtrn.ival;
933 return ReportIllegal(keymap, action->type, field);
937 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
938 unsigned field, ExprDef *array_ndx, ExprDef *value)
942 struct xkb_device_valuator_action *act;
944 act = (struct xkb_device_valuator_action *) action;
945 /* XXX - Not yet implemented */
951 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
952 unsigned field, ExprDef *array_ndx, ExprDef *value)
958 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
959 return ReportMismatch(keymap, PrivateAction, field, "integer");
960 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
962 "Private action type must be in the range 0..255; "
963 "Illegal type %d ignored\n", rtrn.ival);
966 action->type = rtrn.uval;
970 if (array_ndx == NULL) {
971 if (!ExprResolveString(keymap->ctx, value, &rtrn))
972 return ReportMismatch(keymap, action->type, field, "string");
974 int len = strlen(rtrn.str);
975 if ((len < 1) || (len > 7)) {
976 log_warn(keymap->ctx,
977 "A private action has 7 data bytes; "
978 "Extra %d bytes ignored\n", len - 6);
981 strncpy((char *) action->data, rtrn.str, sizeof action->data);
987 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
989 "Array subscript must be integer; "
990 "Illegal subscript ignored\n");
994 if (ndx >= sizeof action->data) {
996 "The data for a private action is 18 bytes long; "
997 "Attempt to use data[%d] ignored\n", ndx);
1000 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1001 return ReportMismatch(keymap, action->type, field, "integer");
1002 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1003 log_err(keymap->ctx,
1004 "All data for a private action must be 0..255; "
1005 "Illegal datum %d ignored\n", rtrn.ival);
1008 action->data[ndx] = rtrn.uval;
1012 return ReportIllegal(keymap, PrivateAction, field);
1015 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1016 struct xkb_any_action *action, unsigned field,
1017 ExprDef *array_ndx, ExprDef *value);
1019 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1020 [XkbSA_NoAction] = HandleNoAction,
1021 [XkbSA_SetMods] = HandleSetLatchMods,
1022 [XkbSA_LatchMods] = HandleSetLatchMods,
1023 [XkbSA_LockMods] = HandleLockMods,
1024 [XkbSA_SetGroup] = HandleSetLatchGroup,
1025 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1026 [XkbSA_LockGroup] = HandleLockGroup,
1027 [XkbSA_MovePtr] = HandleMovePtr,
1028 [XkbSA_PtrBtn] = HandlePtrBtn,
1029 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1030 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1031 [XkbSA_ISOLock] = HandleISOLock,
1032 [XkbSA_Terminate] = HandleNoAction,
1033 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1034 [XkbSA_SetControls] = HandleSetLockControls,
1035 [XkbSA_LockControls] = HandleSetLockControls,
1036 [XkbSA_ActionMessage] = HandleActionMessage,
1037 [XkbSA_RedirectKey] = HandleRedirectKey,
1038 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1039 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1040 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1041 [PrivateAction] = HandlePrivate,
1044 /***====================================================================***/
1047 ApplyActionFactoryDefaults(union xkb_action * action)
1049 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1050 action->dflt.affect = XkbSA_AffectDfltBtn;
1051 action->dflt.flags = 0;
1052 action->dflt.value = 1;
1054 else if (action->type == XkbSA_ISOLock) {
1055 action->iso.real_mods = LockMask;
1060 ActionsInit(struct xkb_context *ctx);
1063 HandleActionDef(ExprDef * def,
1064 struct xkb_keymap *keymap,
1065 struct xkb_any_action *action, ActionInfo *info)
1069 unsigned tmp, hndlrType;
1071 if (!actionsInitialized)
1072 ActionsInit(keymap->ctx);
1074 if (def->op != ExprActionDecl) {
1075 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1076 exprOpText(def->op));
1079 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1081 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1084 if (!stringToAction(str, &tmp)) {
1085 log_err(keymap->ctx, "Unknown action %s\n", str);
1088 action->type = hndlrType = tmp;
1089 if (action->type != XkbSA_NoAction) {
1090 ApplyActionFactoryDefaults((union xkb_action *) action);
1093 if ((info->action == XkbSA_NoAction)
1094 || (info->action == hndlrType)) {
1095 if (!(*handleAction[hndlrType])(keymap, action,
1105 for (arg = def->value.action.args; arg != NULL;
1106 arg = (ExprDef *) arg->common.next) {
1107 ExprDef *field, *value, *arrayRtrn;
1108 ExprResult elemRtrn, fieldRtrn;
1111 if (arg->op == OpAssign) {
1112 field = arg->value.binary.left;
1113 value = arg->value.binary.right;
1116 if ((arg->op == OpNot) || (arg->op == OpInvert)) {
1117 field = arg->value.child;
1118 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1119 value = &constFalse;
1123 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1127 if (!ExprResolveLhs(keymap, field, &elemRtrn, &fieldRtrn, &arrayRtrn))
1128 return false; /* internal error -- already reported */
1130 if (elemRtrn.str != NULL) {
1131 log_err(keymap->ctx,
1132 "Cannot change defaults in an action definition; "
1133 "Ignoring attempt to change %s.%s\n",
1134 elemRtrn.str, fieldRtrn.str);
1137 if (!stringToField(fieldRtrn.str, &fieldNdx)) {
1138 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn.str);
1141 if (!(*handleAction[hndlrType])(keymap, action, fieldNdx, arrayRtrn,
1148 /***====================================================================***/
1151 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1152 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1154 ActionInfo *new, *old;
1156 if (!actionsInitialized)
1157 ActionsInit(keymap->ctx);
1159 new = malloc(sizeof(*new));
1161 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1165 if (strcasecmp(elem, "action") == 0)
1166 new->action = XkbSA_NoAction;
1168 if (!stringToAction(elem, &new->action)) {
1172 if (new->action == XkbSA_NoAction) {
1173 log_err(keymap->ctx,
1174 "\"%s\" is not a valid field in a NoAction action\n",
1180 if (!stringToField(field, &new->field)) {
1181 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1185 new->array_ndx = array_ndx;
1189 while ((old) && (old->next))
1198 /***====================================================================***/
1201 ActionsInit(struct xkb_context *ctx)
1203 if (!actionsInitialized) {
1204 memset(&constTrue, 0, sizeof(constTrue));
1205 memset(&constFalse, 0, sizeof(constFalse));
1206 constTrue.common.stmtType = StmtExpr;
1207 constTrue.common.next = NULL;
1208 constTrue.op = ExprIdent;
1209 constTrue.type = TypeBoolean;
1210 constTrue.value.str = xkb_atom_intern(ctx, "true");
1211 constFalse.common.stmtType = StmtExpr;
1212 constFalse.common.next = NULL;
1213 constFalse.op = ExprIdent;
1214 constFalse.type = TypeBoolean;
1215 constFalse.value.str = xkb_atom_intern(ctx, "false");
1216 actionsInitialized = 1;