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 ********************************************************/
38 static Bool actionsInitialized;
39 static ExprDef constTrue;
40 static ExprDef constFalse;
42 /***====================================================================***/
45 stringToAction(const char *str, unsigned *type_rtrn)
50 if (uStrCaseCmp(str, "noaction") == 0)
51 *type_rtrn = XkbSA_NoAction;
52 else if (uStrCaseCmp(str, "setmods") == 0)
53 *type_rtrn = XkbSA_SetMods;
54 else if (uStrCaseCmp(str, "latchmods") == 0)
55 *type_rtrn = XkbSA_LatchMods;
56 else if (uStrCaseCmp(str, "lockmods") == 0)
57 *type_rtrn = XkbSA_LockMods;
58 else if (uStrCaseCmp(str, "setgroup") == 0)
59 *type_rtrn = XkbSA_SetGroup;
60 else if (uStrCaseCmp(str, "latchgroup") == 0)
61 *type_rtrn = XkbSA_LatchGroup;
62 else if (uStrCaseCmp(str, "lockgroup") == 0)
63 *type_rtrn = XkbSA_LockGroup;
64 else if (uStrCaseCmp(str, "moveptr") == 0)
65 *type_rtrn = XkbSA_MovePtr;
66 else if (uStrCaseCmp(str, "movepointer") == 0)
67 *type_rtrn = XkbSA_MovePtr;
68 else if (uStrCaseCmp(str, "ptrbtn") == 0)
69 *type_rtrn = XkbSA_PtrBtn;
70 else if (uStrCaseCmp(str, "pointerbutton") == 0)
71 *type_rtrn = XkbSA_PtrBtn;
72 else if (uStrCaseCmp(str, "lockptrbtn") == 0)
73 *type_rtrn = XkbSA_LockPtrBtn;
74 else if (uStrCaseCmp(str, "lockpointerbutton") == 0)
75 *type_rtrn = XkbSA_LockPtrBtn;
76 else if (uStrCaseCmp(str, "lockptrbutton") == 0)
77 *type_rtrn = XkbSA_LockPtrBtn;
78 else if (uStrCaseCmp(str, "lockpointerbtn") == 0)
79 *type_rtrn = XkbSA_LockPtrBtn;
80 else if (uStrCaseCmp(str, "setptrdflt") == 0)
81 *type_rtrn = XkbSA_SetPtrDflt;
82 else if (uStrCaseCmp(str, "setpointerdefault") == 0)
83 *type_rtrn = XkbSA_SetPtrDflt;
84 else if (uStrCaseCmp(str, "isolock") == 0)
85 *type_rtrn = XkbSA_ISOLock;
86 else if (uStrCaseCmp(str, "terminate") == 0)
87 *type_rtrn = XkbSA_Terminate;
88 else if (uStrCaseCmp(str, "terminateserver") == 0)
89 *type_rtrn = XkbSA_Terminate;
90 else if (uStrCaseCmp(str, "switchscreen") == 0)
91 *type_rtrn = XkbSA_SwitchScreen;
92 else if (uStrCaseCmp(str, "setcontrols") == 0)
93 *type_rtrn = XkbSA_SetControls;
94 else if (uStrCaseCmp(str, "lockcontrols") == 0)
95 *type_rtrn = XkbSA_LockControls;
96 else if (uStrCaseCmp(str, "actionmessage") == 0)
97 *type_rtrn = XkbSA_ActionMessage;
98 else if (uStrCaseCmp(str, "messageaction") == 0)
99 *type_rtrn = XkbSA_ActionMessage;
100 else if (uStrCaseCmp(str, "message") == 0)
101 *type_rtrn = XkbSA_ActionMessage;
102 else if (uStrCaseCmp(str, "redirect") == 0)
103 *type_rtrn = XkbSA_RedirectKey;
104 else if (uStrCaseCmp(str, "redirectkey") == 0)
105 *type_rtrn = XkbSA_RedirectKey;
106 else if (uStrCaseCmp(str, "devbtn") == 0)
107 *type_rtrn = XkbSA_DeviceBtn;
108 else if (uStrCaseCmp(str, "devicebtn") == 0)
109 *type_rtrn = XkbSA_DeviceBtn;
110 else if (uStrCaseCmp(str, "devbutton") == 0)
111 *type_rtrn = XkbSA_DeviceBtn;
112 else if (uStrCaseCmp(str, "devicebutton") == 0)
113 *type_rtrn = XkbSA_DeviceBtn;
114 else if (uStrCaseCmp(str, "lockdevbtn") == 0)
115 *type_rtrn = XkbSA_DeviceBtn;
116 else if (uStrCaseCmp(str, "lockdevicebtn") == 0)
117 *type_rtrn = XkbSA_LockDeviceBtn;
118 else if (uStrCaseCmp(str, "lockdevbutton") == 0)
119 *type_rtrn = XkbSA_LockDeviceBtn;
120 else if (uStrCaseCmp(str, "lockdevicebutton") == 0)
121 *type_rtrn = XkbSA_LockDeviceBtn;
122 else if (uStrCaseCmp(str, "devval") == 0)
123 *type_rtrn = XkbSA_DeviceValuator;
124 else if (uStrCaseCmp(str, "deviceval") == 0)
125 *type_rtrn = XkbSA_DeviceValuator;
126 else if (uStrCaseCmp(str, "devvaluator") == 0)
127 *type_rtrn = XkbSA_DeviceValuator;
128 else if (uStrCaseCmp(str, "devicevaluator") == 0)
129 *type_rtrn = XkbSA_DeviceValuator;
130 else if (uStrCaseCmp(str, "private") == 0)
131 *type_rtrn = PrivateAction;
138 stringToField(char *str, unsigned *field_rtrn)
144 if (uStrCaseCmp(str, "clearlocks") == 0)
145 *field_rtrn = F_ClearLocks;
146 else if (uStrCaseCmp(str, "latchtolock") == 0)
147 *field_rtrn = F_LatchToLock;
148 else if (uStrCaseCmp(str, "genkeyevent") == 0)
149 *field_rtrn = F_GenKeyEvent;
150 else if (uStrCaseCmp(str, "generatekeyevent") == 0)
151 *field_rtrn = F_GenKeyEvent;
152 else if (uStrCaseCmp(str, "report") == 0)
153 *field_rtrn = F_Report;
154 else if (uStrCaseCmp(str, "default") == 0)
155 *field_rtrn = F_Default;
156 else if (uStrCaseCmp(str, "affect") == 0)
157 *field_rtrn = F_Affect;
158 else if (uStrCaseCmp(str, "increment") == 0)
159 *field_rtrn = F_Increment;
160 else if (uStrCaseCmp(str, "mods") == 0)
161 *field_rtrn = F_Modifiers;
162 else if (uStrCaseCmp(str, "modifiers") == 0)
163 *field_rtrn = F_Modifiers;
164 else if (uStrCaseCmp(str, "group") == 0)
165 *field_rtrn = F_Group;
166 else if (uStrCaseCmp(str, "x") == 0)
168 else if (uStrCaseCmp(str, "y") == 0)
170 else if (uStrCaseCmp(str, "accel") == 0)
171 *field_rtrn = F_Accel;
172 else if (uStrCaseCmp(str, "accelerate") == 0)
173 *field_rtrn = F_Accel;
174 else if (uStrCaseCmp(str, "repeat") == 0)
175 *field_rtrn = F_Accel;
176 else if (uStrCaseCmp(str, "button") == 0)
177 *field_rtrn = F_Button;
178 else if (uStrCaseCmp(str, "value") == 0)
179 *field_rtrn = F_Value;
180 else if (uStrCaseCmp(str, "controls") == 0)
181 *field_rtrn = F_Controls;
182 else if (uStrCaseCmp(str, "ctrls") == 0)
183 *field_rtrn = F_Controls;
184 else if (uStrCaseCmp(str, "type") == 0)
185 *field_rtrn = F_Type;
186 else if (uStrCaseCmp(str, "count") == 0)
187 *field_rtrn = F_Count;
188 else if (uStrCaseCmp(str, "screen") == 0)
189 *field_rtrn = F_Screen;
190 else if (uStrCaseCmp(str, "same") == 0)
191 *field_rtrn = F_Same;
192 else if (uStrCaseCmp(str, "sameserver") == 0)
193 *field_rtrn = F_Same;
194 else if (uStrCaseCmp(str, "data") == 0)
195 *field_rtrn = F_Data;
196 else if (uStrCaseCmp(str, "device") == 0)
197 *field_rtrn = F_Device;
198 else if (uStrCaseCmp(str, "dev") == 0)
199 *field_rtrn = F_Device;
200 else if (uStrCaseCmp(str, "key") == 0)
201 *field_rtrn = F_Keycode;
202 else if (uStrCaseCmp(str, "keycode") == 0)
203 *field_rtrn = F_Keycode;
204 else if (uStrCaseCmp(str, "kc") == 0)
205 *field_rtrn = F_Keycode;
206 else if (uStrCaseCmp(str, "clearmods") == 0)
207 *field_rtrn = F_ModsToClear;
208 else if (uStrCaseCmp(str, "clearmodifiers") == 0)
209 *field_rtrn = F_ModsToClear;
216 fieldText(unsigned field)
223 strcpy(buf, "clearLocks");
226 strcpy(buf, "latchToLock");
229 strcpy(buf, "genKeyEvent");
232 strcpy(buf, "report");
235 strcpy(buf, "default");
238 strcpy(buf, "affect");
241 strcpy(buf, "increment");
244 strcpy(buf, "modifiers");
247 strcpy(buf, "group");
256 strcpy(buf, "accel");
259 strcpy(buf, "button");
262 strcpy(buf, "value");
265 strcpy(buf, "controls");
271 strcpy(buf, "count");
274 strcpy(buf, "screen");
277 strcpy(buf, "sameServer");
283 strcpy(buf, "device");
286 strcpy(buf, "keycode");
289 strcpy(buf, "clearmods");
292 strcpy(buf, "unknown");
298 /***====================================================================***/
301 ReportMismatch(unsigned action, unsigned field, const char *type)
303 ERROR("Value of %s field must be of type %s\n", fieldText(field), type);
304 ACTION("Action %s definition ignored\n", XkbcActionTypeText(action));
309 ReportIllegal(unsigned action, unsigned field)
311 ERROR("Field %s is not defined for an action of type %s\n",
312 fieldText(field), XkbcActionTypeText(action));
313 ACTION("Action definition ignored\n");
318 ReportActionNotArray(unsigned action, unsigned field)
320 ERROR("The %s field in the %s action is not an array\n",
321 fieldText(field), XkbcActionTypeText(action));
322 ACTION("Action definition ignored\n");
327 ReportNotFound(unsigned action, unsigned field, const char *what, char *bad)
329 ERROR("%s named %s not found\n", what, bad);
330 ACTION("Ignoring the %s field of an %s action\n", fieldText(field),
331 XkbcActionTypeText(action));
336 HandleNoAction(struct xkb_desc * xkb,
337 struct xkb_any_action * action,
338 unsigned field, ExprDef * array_ndx, ExprDef * value)
340 return ReportIllegal(action->type, field);
344 CheckLatchLockFlags(unsigned action,
345 unsigned field, ExprDef * value, unsigned *flags_inout)
350 if (field == F_ClearLocks)
351 tmp = XkbSA_ClearLocks;
352 else if (field == F_LatchToLock)
353 tmp = XkbSA_LatchToLock;
355 return False; /* WSGO! */
356 if (!ExprResolveBoolean(value, &result))
357 return ReportMismatch(action, field, "boolean");
361 *flags_inout &= ~tmp;
366 CheckModifierField(struct xkb_desc * xkb,
369 unsigned *flags_inout, unsigned *mods_rtrn)
373 if (value->op == ExprIdent)
376 valStr = XkbcAtomText(value->value.str);
377 if (valStr && ((uStrCaseCmp(valStr, "usemodmapmods") == 0) ||
378 (uStrCaseCmp(valStr, "modmapmods") == 0)))
382 *flags_inout |= XkbSA_UseModMapMods;
386 if (!ExprResolveVModMask(value, &rtrn, xkb))
387 return ReportMismatch(action, F_Modifiers, "modifier mask");
388 *mods_rtrn = rtrn.uval;
389 *flags_inout &= ~XkbSA_UseModMapMods;
394 HandleSetLatchMods(struct xkb_desc * xkb,
395 struct xkb_any_action * action,
396 unsigned field, ExprDef * array_ndx, ExprDef * value)
398 struct xkb_mod_action *act;
402 act = (struct xkb_mod_action *) action;
403 if (array_ndx != NULL)
410 return ReportActionNotArray(action->type, field);
418 if (CheckLatchLockFlags(action->type, field, value, &rtrn))
426 if (CheckModifierField(xkb, action->type, value, &t1, &t2))
429 act->real_mods = act->mask = (t2 & 0xff);
430 act->vmods = (t2 >> 8) & 0xffff;
435 return ReportIllegal(action->type, field);
439 HandleLockMods(struct xkb_desc * xkb,
440 struct xkb_any_action * action,
441 unsigned field, ExprDef * array_ndx, ExprDef * value)
443 struct xkb_mod_action *act;
446 act = (struct xkb_mod_action *) action;
447 if ((array_ndx != NULL) && (field == F_Modifiers))
448 return ReportActionNotArray(action->type, field);
453 if (CheckModifierField(xkb, action->type, value, &t1, &t2))
456 act->real_mods = act->mask = (t2 & 0xff);
457 act->vmods = (t2 >> 8) & 0xffff;
462 return ReportIllegal(action->type, field);
466 CheckGroupField(unsigned action,
467 ExprDef * value, unsigned *flags_inout, int *grp_rtrn)
472 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
474 *flags_inout &= ~XkbSA_GroupAbsolute;
475 spec = value->value.child;
479 *flags_inout |= XkbSA_GroupAbsolute;
483 if (!ExprResolveGroup(spec, &rtrn))
484 return ReportMismatch(action, F_Group, "integer (range 1..8)");
485 if ((rtrn.ival < 1) || (rtrn.ival > XkbNumKbdGroups))
487 ERROR("Illegal group %d (must be in the range 1..%d)\n", rtrn.ival,
489 ACTION("Action %s definition ignored\n", XkbcActionTypeText(action));
492 if (value->op == OpNegate)
493 *grp_rtrn = -rtrn.ival;
494 else if (value->op == OpUnaryPlus)
495 *grp_rtrn = rtrn.ival;
497 *grp_rtrn = rtrn.ival - 1;
502 HandleSetLatchGroup(struct xkb_desc * xkb,
503 struct xkb_any_action * action,
504 unsigned field, ExprDef * array_ndx, ExprDef * value)
506 struct xkb_group_action *act;
511 act = (struct xkb_group_action *) action;
512 if (array_ndx != NULL)
519 return ReportActionNotArray(action->type, field);
527 if (CheckLatchLockFlags(action->type, field, value, &rtrn))
535 if (CheckGroupField(action->type, value, &t1, &t2))
543 return ReportIllegal(action->type, field);
547 HandleLockGroup(struct xkb_desc * xkb,
548 struct xkb_any_action * action,
549 unsigned field, ExprDef * array_ndx, ExprDef * value)
551 struct xkb_group_action *act;
555 act = (struct xkb_group_action *) action;
556 if ((array_ndx != NULL) && (field == F_Group))
557 return ReportActionNotArray(action->type, field);
558 if (field == F_Group)
561 if (CheckGroupField(action->type, value, &t1, &t2))
569 return ReportIllegal(action->type, field);
573 HandleMovePtr(struct xkb_desc * xkb,
574 struct xkb_any_action * action,
575 unsigned field, ExprDef * array_ndx, ExprDef * value)
578 struct xkb_pointer_action *act;
581 act = (struct xkb_pointer_action *) action;
582 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
583 return ReportActionNotArray(action->type, field);
585 if ((field == F_X) || (field == F_Y))
587 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
591 if (!ExprResolveInteger(value, &rtrn))
592 return ReportMismatch(action->type, field, "integer");
596 act->flags |= XkbSA_MoveAbsoluteX;
602 act->flags |= XkbSA_MoveAbsoluteY;
607 else if (field == F_Accel)
609 if (!ExprResolveBoolean(value, &rtrn))
610 return ReportMismatch(action->type, field, "boolean");
612 act->flags &= ~XkbSA_NoAcceleration;
614 act->flags |= XkbSA_NoAcceleration;
616 return ReportIllegal(action->type, field);
619 static LookupEntry lockWhich[] = {
621 {"lock", XkbSA_LockNoUnlock},
622 {"neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock)},
623 {"unlock", XkbSA_LockNoLock},
628 HandlePtrBtn(struct xkb_desc * xkb,
629 struct xkb_any_action * action,
630 unsigned field, ExprDef * array_ndx, ExprDef * value)
633 struct xkb_pointer_button_action *act;
635 act = (struct xkb_pointer_button_action *) action;
636 if (field == F_Button)
638 if (array_ndx != NULL)
639 return ReportActionNotArray(action->type, field);
640 if (!ExprResolveButton(value, &rtrn))
641 return ReportMismatch(action->type, field,
642 "integer (range 1..5)");
643 if ((rtrn.ival < 0) || (rtrn.ival > 5))
645 ERROR("Button must specify default or be in the range 1..5\n");
646 ACTION("Illegal button value %d ignored\n", rtrn.ival);
649 act->button = rtrn.ival;
652 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect))
654 if (array_ndx != NULL)
655 return ReportActionNotArray(action->type, field);
656 if (!ExprResolveEnum(value, &rtrn, lockWhich))
657 return ReportMismatch(action->type, field, "lock or unlock");
658 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
659 act->flags |= rtrn.ival;
662 else if (field == F_Count)
664 if (array_ndx != NULL)
665 return ReportActionNotArray(action->type, field);
666 if (!ExprResolveButton(value, &rtrn))
667 return ReportMismatch(action->type, field, "integer");
668 if ((rtrn.ival < 0) || (rtrn.ival > 255))
670 ERROR("The count field must have a value in the range 0..255\n");
671 ACTION("Illegal count %d ignored\n", rtrn.ival);
674 act->count = rtrn.ival;
677 return ReportIllegal(action->type, field);
680 static LookupEntry ptrDflts[] = {
681 {"dfltbtn", XkbSA_AffectDfltBtn},
682 {"defaultbutton", XkbSA_AffectDfltBtn},
683 {"button", XkbSA_AffectDfltBtn},
688 HandleSetPtrDflt(struct xkb_desc * xkb,
689 struct xkb_any_action * action,
690 unsigned field, ExprDef * array_ndx, ExprDef * value)
693 struct xkb_pointer_default_action *act;
695 act = (struct xkb_pointer_default_action *) action;
696 if (field == F_Affect)
698 if (array_ndx != NULL)
699 return ReportActionNotArray(action->type, field);
700 if (!ExprResolveEnum(value, &rtrn, ptrDflts))
701 return ReportMismatch(action->type, field, "pointer component");
702 act->affect = rtrn.uval;
705 else if ((field == F_Button) || (field == F_Value))
708 if (array_ndx != NULL)
709 return ReportActionNotArray(action->type, field);
710 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
712 act->flags &= ~XkbSA_DfltBtnAbsolute;
713 btn = value->value.child;
717 act->flags |= XkbSA_DfltBtnAbsolute;
721 if (!ExprResolveButton(btn, &rtrn))
722 return ReportMismatch(action->type, field,
723 "integer (range 1..5)");
724 if ((rtrn.ival < 0) || (rtrn.ival > 5))
726 ERROR("New default button value must be in the range 1..5\n");
727 ACTION("Illegal default button value %d ignored\n", rtrn.ival);
732 ERROR("Cannot set default pointer button to \"default\"\n");
733 ACTION("Illegal default button setting ignored\n");
736 if (value->op == OpNegate)
737 act->value = -rtrn.ival;
739 act->value = rtrn.ival;
742 return ReportIllegal(action->type, field);
745 static LookupEntry isoNames[] = {
746 {"mods", XkbSA_ISONoAffectMods},
747 {"modifiers", XkbSA_ISONoAffectMods},
748 {"group", XkbSA_ISONoAffectGroup},
749 {"groups", XkbSA_ISONoAffectGroup},
750 {"ptr", XkbSA_ISONoAffectPtr},
751 {"pointer", XkbSA_ISONoAffectPtr},
752 {"ctrls", XkbSA_ISONoAffectCtrls},
753 {"controls", XkbSA_ISONoAffectCtrls},
754 {"all", ~((unsigned) 0)},
760 HandleISOLock(struct xkb_desc * xkb,
761 struct xkb_any_action * action,
762 unsigned field, ExprDef * array_ndx, ExprDef * value)
765 struct xkb_iso_action *act;
766 unsigned flags, mods;
769 act = (struct xkb_iso_action *) action;
773 if (array_ndx != NULL)
774 return ReportActionNotArray(action->type, field);
776 if (CheckModifierField(xkb, action->type, value, &flags, &mods))
778 act->flags = flags & (~XkbSA_ISODfltIsGroup);
779 act->real_mods = mods & 0xff;
780 act->vmods = (mods >> 8) & 0xff;
785 if (array_ndx != NULL)
786 return ReportActionNotArray(action->type, field);
788 if (CheckGroupField(action->type, value, &flags, &group))
790 act->flags = flags | XkbSA_ISODfltIsGroup;
796 if (array_ndx != NULL)
797 return ReportActionNotArray(action->type, field);
798 if (!ExprResolveMask(value, &rtrn, isoNames))
799 return ReportMismatch(action->type, field, "keyboard component");
800 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
803 return ReportIllegal(action->type, field);
807 HandleSwitchScreen(struct xkb_desc * xkb,
808 struct xkb_any_action * action,
809 unsigned field, ExprDef * array_ndx, ExprDef * value)
812 struct xkb_switch_screen_action *act;
814 act = (struct xkb_switch_screen_action *) action;
815 if (field == F_Screen)
818 if (array_ndx != NULL)
819 return ReportActionNotArray(action->type, field);
820 if ((value->op == OpNegate) || (value->op == OpUnaryPlus))
822 act->flags &= ~XkbSA_SwitchAbsolute;
823 scrn = value->value.child;
827 act->flags |= XkbSA_SwitchAbsolute;
831 if (!ExprResolveInteger(scrn, &rtrn))
832 return ReportMismatch(action->type, field, "integer (0..255)");
833 if ((rtrn.ival < 0) || (rtrn.ival > 255))
835 ERROR("Screen index must be in the range 1..255\n");
836 ACTION("Illegal screen value %d ignored\n", rtrn.ival);
839 if (value->op == OpNegate)
840 act->screen = -rtrn.ival;
842 act->screen = rtrn.ival;
845 else if (field == F_Same)
847 if (array_ndx != NULL)
848 return ReportActionNotArray(action->type, field);
849 if (!ExprResolveBoolean(value, &rtrn))
850 return ReportMismatch(action->type, field, "boolean");
852 act->flags &= ~XkbSA_SwitchApplication;
854 act->flags |= XkbSA_SwitchApplication;
857 return ReportIllegal(action->type, field);
860 LookupEntry ctrlNames[] = {
861 {"repeatkeys", XkbRepeatKeysMask}
863 {"repeat", XkbRepeatKeysMask}
865 {"autorepeat", XkbRepeatKeysMask}
867 {"slowkeys", XkbSlowKeysMask}
869 {"bouncekeys", XkbBounceKeysMask}
871 {"stickykeys", XkbStickyKeysMask}
873 {"mousekeys", XkbMouseKeysMask}
875 {"mousekeysaccel", XkbMouseKeysAccelMask}
877 {"accessxkeys", XkbAccessXKeysMask}
879 {"accessxtimeout", XkbAccessXTimeoutMask}
881 {"accessxfeedback", XkbAccessXFeedbackMask}
883 {"audiblebell", XkbAudibleBellMask}
885 {"overlay1", XkbOverlay1Mask}
887 {"overlay2", XkbOverlay2Mask}
889 {"ignoregrouplock", XkbIgnoreGroupLockMask}
891 {"all", XkbAllBooleanCtrlsMask}
899 HandleSetLockControls(struct xkb_desc * xkb,
900 struct xkb_any_action * action,
901 unsigned field, ExprDef * array_ndx, ExprDef * value)
904 struct xkb_controls_action *act;
906 act = (struct xkb_controls_action *) action;
907 if (field == F_Controls)
909 if (array_ndx != NULL)
910 return ReportActionNotArray(action->type, field);
911 if (!ExprResolveMask(value, &rtrn, ctrlNames))
912 return ReportMismatch(action->type, field, "controls mask");
913 act->ctrls = rtrn.uval;
916 return ReportIllegal(action->type, field);
919 static LookupEntry evNames[] = {
920 {"press", XkbSA_MessageOnPress},
921 {"keypress", XkbSA_MessageOnPress},
922 {"release", XkbSA_MessageOnRelease},
923 {"keyrelease", XkbSA_MessageOnRelease},
924 {"all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease},
930 HandleActionMessage(struct xkb_desc * xkb,
931 struct xkb_any_action * action,
932 unsigned field, ExprDef * array_ndx, ExprDef * value)
935 struct xkb_message_action *act;
937 act = (struct xkb_message_action *) action;
941 if (array_ndx != NULL)
942 return ReportActionNotArray(action->type, field);
943 if (!ExprResolveMask(value, &rtrn, evNames))
944 return ReportMismatch(action->type, field, "key event mask");
945 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
947 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
950 if (array_ndx != NULL)
951 return ReportActionNotArray(action->type, field);
952 if (!ExprResolveBoolean(value, &rtrn))
953 return ReportMismatch(action->type, field, "boolean");
955 act->flags |= XkbSA_MessageGenKeyEvent;
957 act->flags &= ~XkbSA_MessageGenKeyEvent;
960 if (array_ndx == NULL)
962 if (!ExprResolveString(value, &rtrn))
963 return ReportMismatch(action->type, field, "string");
966 int len = strlen(rtrn.str);
967 if ((len < 1) || (len > 6))
969 WARN("An action message can hold only 6 bytes\n");
970 ACTION("Extra %d bytes ignored\n", len - 6);
972 strncpy((char *) act->message, rtrn.str, 6);
979 if (!ExprResolveInteger(array_ndx, &rtrn))
981 ERROR("Array subscript must be integer\n");
982 ACTION("Illegal subscript ignored\n");
988 ERROR("An action message is at most 6 bytes long\n");
989 ACTION("Attempt to use data[%d] ignored\n", ndx);
992 if (!ExprResolveInteger(value, &rtrn))
993 return ReportMismatch(action->type, field, "integer");
994 if ((rtrn.ival < 0) || (rtrn.ival > 255))
996 ERROR("Message data must be in the range 0..255\n");
997 ACTION("Illegal datum %d ignored\n", rtrn.ival);
1000 act->message[ndx] = rtrn.uval;
1004 return ReportIllegal(action->type, field);
1008 HandleRedirectKey(struct xkb_desc * xkb,
1009 struct xkb_any_action * action,
1010 unsigned field, ExprDef * array_ndx, ExprDef * value)
1013 struct xkb_redirect_key_action *act;
1018 if (array_ndx != NULL)
1019 return ReportActionNotArray(action->type, field);
1021 act = (struct xkb_redirect_key_action *) action;
1025 if (!ExprResolveKeyName(value, &rtrn))
1026 return ReportMismatch(action->type, field, "key name");
1027 tmp = KeyNameToLong(rtrn.keyName.name);
1028 if (!FindNamedKey(xkb, tmp, &kc, True, CreateKeyNames(xkb), 0))
1030 return ReportNotFound(action->type, field, "Key",
1031 XkbcKeyNameText(rtrn.keyName.name));
1038 if (CheckModifierField(xkb, action->type, value, &t1, &t2))
1040 act->mods_mask |= (t2 & 0xff);
1041 if (field == F_Modifiers)
1042 act->mods |= (t2 & 0xff);
1044 act->mods &= ~(t2 & 0xff);
1046 t2 = (t2 >> 8) & 0xffff;
1047 act->vmods_mask |= t2;
1048 if (field == F_Modifiers)
1056 return ReportIllegal(action->type, field);
1060 HandleDeviceBtn(struct xkb_desc * xkb,
1061 struct xkb_any_action * action,
1062 unsigned field, ExprDef * array_ndx, ExprDef * value)
1065 struct xkb_device_button_action *act;
1067 act = (struct xkb_device_button_action *) action;
1068 if (field == F_Button)
1070 if (array_ndx != NULL)
1071 return ReportActionNotArray(action->type, field);
1072 if (!ExprResolveInteger(value, &rtrn))
1073 return ReportMismatch(action->type, field,
1074 "integer (range 1..255)");
1075 if ((rtrn.ival < 0) || (rtrn.ival > 255))
1077 ERROR("Button must specify default or be in the range 1..255\n");
1078 ACTION("Illegal button value %d ignored\n", rtrn.ival);
1081 act->button = rtrn.ival;
1084 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect))
1086 if (array_ndx != NULL)
1087 return ReportActionNotArray(action->type, field);
1088 if (!ExprResolveEnum(value, &rtrn, lockWhich))
1089 return ReportMismatch(action->type, field, "lock or unlock");
1090 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
1091 act->flags |= rtrn.ival;
1094 else if (field == F_Count)
1096 if (array_ndx != NULL)
1097 return ReportActionNotArray(action->type, field);
1098 if (!ExprResolveButton(value, &rtrn))
1099 return ReportMismatch(action->type, field, "integer");
1100 if ((rtrn.ival < 0) || (rtrn.ival > 255))
1102 ERROR("The count field must have a value in the range 0..255\n");
1103 ACTION("Illegal count %d ignored\n", rtrn.ival);
1106 act->count = rtrn.ival;
1109 else if (field == F_Device)
1111 if (array_ndx != NULL)
1112 return ReportActionNotArray(action->type, field);
1113 if (!ExprResolveInteger(value, &rtrn))
1114 return ReportMismatch(action->type, field,
1115 "integer (range 1..255)");
1116 if ((rtrn.ival < 0) || (rtrn.ival > 255))
1118 ERROR("Device must specify default or be in the range 1..255\n");
1119 ACTION("Illegal device value %d ignored\n", rtrn.ival);
1122 act->device = rtrn.ival;
1125 return ReportIllegal(action->type, field);
1129 HandleDeviceValuator(struct xkb_desc * xkb,
1130 struct xkb_any_action * action,
1131 unsigned field, ExprDef * array_ndx, ExprDef * value)
1135 struct xkb_device_valuator_action *act;
1137 act = (struct xkb_device_valuator_action *) action;
1138 /* XXX - Not yet implemented */
1144 HandlePrivate(struct xkb_desc * xkb,
1145 struct xkb_any_action * action,
1146 unsigned field, ExprDef * array_ndx, ExprDef * value)
1153 if (!ExprResolveInteger(value, &rtrn))
1154 return ReportMismatch(PrivateAction, field, "integer");
1155 if ((rtrn.ival < 0) || (rtrn.ival > 255))
1157 ERROR("Private action type must be in the range 0..255\n");
1158 ACTION("Illegal type %d ignored\n", rtrn.ival);
1161 action->type = rtrn.uval;
1164 if (array_ndx == NULL)
1166 if (!ExprResolveString(value, &rtrn))
1167 return ReportMismatch(action->type, field, "string");
1170 int len = strlen(rtrn.str);
1171 if ((len < 1) || (len > 7))
1173 WARN("A private action has 7 data bytes\n");
1174 ACTION("Extra %d bytes ignored\n", len - 6);
1177 strncpy((char *) action->data, rtrn.str, sizeof action->data);
1185 if (!ExprResolveInteger(array_ndx, &rtrn))
1187 ERROR("Array subscript must be integer\n");
1188 ACTION("Illegal subscript ignored\n");
1192 if (ndx >= sizeof action->data)
1194 ERROR("The data for a private action is 18 bytes long\n");
1195 ACTION("Attempt to use data[%d] ignored\n", ndx);
1198 if (!ExprResolveInteger(value, &rtrn))
1199 return ReportMismatch(action->type, field, "integer");
1200 if ((rtrn.ival < 0) || (rtrn.ival > 255))
1202 ERROR("All data for a private action must be 0..255\n");
1203 ACTION("Illegal datum %d ignored\n", rtrn.ival);
1206 action->data[ndx] = rtrn.uval;
1210 return ReportIllegal(PrivateAction, field);
1213 typedef Bool(*actionHandler) (struct xkb_desc * /* xkb */ ,
1214 struct xkb_any_action * /* action */ ,
1215 unsigned /* field */ ,
1216 ExprDef * /* array_ndx */ ,
1217 ExprDef * /* value */
1220 static actionHandler handleAction[XkbSA_NumActions + 1] = {
1221 HandleNoAction /* NoAction */ ,
1222 HandleSetLatchMods /* SetMods */ ,
1223 HandleSetLatchMods /* LatchMods */ ,
1224 HandleLockMods /* LockMods */ ,
1225 HandleSetLatchGroup /* SetGroup */ ,
1226 HandleSetLatchGroup /* LatchGroup */ ,
1227 HandleLockGroup /* LockGroup */ ,
1228 HandleMovePtr /* MovePtr */ ,
1229 HandlePtrBtn /* PtrBtn */ ,
1230 HandlePtrBtn /* LockPtrBtn */ ,
1231 HandleSetPtrDflt /* SetPtrDflt */ ,
1232 HandleISOLock /* ISOLock */ ,
1233 HandleNoAction /* Terminate */ ,
1234 HandleSwitchScreen /* SwitchScreen */ ,
1235 HandleSetLockControls /* SetControls */ ,
1236 HandleSetLockControls /* LockControls */ ,
1237 HandleActionMessage /* ActionMessage */ ,
1238 HandleRedirectKey /* RedirectKey */ ,
1239 HandleDeviceBtn /* DeviceBtn */ ,
1240 HandleDeviceBtn /* LockDeviceBtn */ ,
1241 HandleDeviceValuator /* DeviceValuatr */ ,
1242 HandlePrivate /* Private */
1245 /***====================================================================***/
1248 ApplyActionFactoryDefaults(union xkb_action * action)
1250 if (action->type == XkbSA_SetPtrDflt)
1251 { /* increment default button */
1252 action->dflt.affect = XkbSA_AffectDfltBtn;
1253 action->dflt.flags = 0;
1254 action->dflt.value = 1;
1256 else if (action->type == XkbSA_ISOLock)
1258 action->iso.real_mods = LockMask;
1267 HandleActionDef(ExprDef * def,
1268 struct xkb_desc * xkb,
1269 struct xkb_any_action * action, unsigned mergeMode, ActionInfo * info)
1273 unsigned tmp, hndlrType;
1275 if (!actionsInitialized)
1278 if (def->op != ExprActionDecl)
1280 ERROR("Expected an action definition, found %s\n",
1281 exprOpText(def->op));
1284 str = XkbcAtomText(def->value.action.name);
1287 WSGO("Missing name in action definition!!\n");
1290 if (!stringToAction(str, &tmp))
1292 ERROR("Unknown action %s\n", str);
1295 action->type = hndlrType = tmp;
1296 if (action->type != XkbSA_NoAction)
1298 ApplyActionFactoryDefaults((union xkb_action *) action);
1301 if ((info->action == XkbSA_NoAction)
1302 || (info->action == hndlrType))
1304 if (!(*handleAction[hndlrType]) (xkb, action,
1315 for (arg = def->value.action.args; arg != NULL;
1316 arg = (ExprDef *) arg->common.next)
1318 ExprDef *field, *value, *arrayRtrn;
1319 ExprResult elemRtrn, fieldRtrn;
1322 if (arg->op == OpAssign)
1324 field = arg->value.binary.left;
1325 value = arg->value.binary.right;
1329 if ((arg->op == OpNot) || (arg->op == OpInvert))
1331 field = arg->value.child;
1332 value = &constFalse;
1340 if (!ExprResolveLhs(field, &elemRtrn, &fieldRtrn, &arrayRtrn))
1341 return False; /* internal error -- already reported */
1343 if (elemRtrn.str != NULL)
1345 ERROR("Cannot change defaults in an action definition\n");
1346 ACTION("Ignoring attempt to change %s.%s\n", elemRtrn.str,
1349 free(fieldRtrn.str);
1352 if (!stringToField(fieldRtrn.str, &fieldNdx))
1354 ERROR("Unknown field name %s\n", uStringText(fieldRtrn.str));
1356 free(fieldRtrn.str);
1360 free(fieldRtrn.str);
1361 if (!(*handleAction[hndlrType])
1362 (xkb, action, fieldNdx, arrayRtrn, value))
1370 /***====================================================================***/
1373 SetActionField(struct xkb_desc * xkb,
1376 ExprDef * array_ndx, ExprDef * value, ActionInfo ** info_rtrn)
1378 ActionInfo *new, *old;
1380 if (!actionsInitialized)
1383 new = uTypedAlloc(ActionInfo);
1386 WSGO("Couldn't allocate space for action default\n");
1389 if (uStrCaseCmp(elem, "action") == 0)
1390 new->action = XkbSA_NoAction;
1393 if (!stringToAction(elem, &new->action))
1398 if (new->action == XkbSA_NoAction)
1400 ERROR("\"%s\" is not a valid field in a NoAction action\n",
1406 if (!stringToField(field, &new->field))
1408 ERROR("\"%s\" is not a legal field name\n", field);
1412 new->array_ndx = array_ndx;
1416 while ((old) && (old->next))
1425 /***====================================================================***/
1430 if (!actionsInitialized)
1432 bzero((char *) &constTrue, sizeof(constTrue));
1433 bzero((char *) &constFalse, sizeof(constFalse));
1434 constTrue.common.stmtType = StmtExpr;
1435 constTrue.common.next = NULL;
1436 constTrue.op = ExprIdent;
1437 constTrue.type = TypeBoolean;
1438 constTrue.value.str = xkb_intern_atom("true");
1439 constFalse.common.stmtType = StmtExpr;
1440 constFalse.common.next = NULL;
1441 constFalse.op = ExprIdent;
1442 constFalse.type = TypeBoolean;
1443 constFalse.value.str = xkb_intern_atom("false");
1444 actionsInitialized = 1;