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)
342 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
343 *flags_inout &= ~XkbSA_GroupAbsolute;
344 spec = value->value.child;
347 *flags_inout |= XkbSA_GroupAbsolute;
351 if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
352 return ReportMismatch(keymap, action, F_Group,
353 "integer (range 1..8)");
355 if (value->op == EXPR_NEGATE)
356 *grp_rtrn = -*grp_rtrn;
357 else if (value->op != EXPR_UNARY_PLUS)
364 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
365 unsigned field, ExprDef *array_ndx, ExprDef *value)
367 struct xkb_group_action *act;
370 xkb_group_index_t t2;
372 act = (struct xkb_group_action *) action;
373 if (array_ndx != NULL) {
378 return ReportActionNotArray(keymap, action->type, field);
385 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
393 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
400 return ReportIllegal(keymap, action->type, field);
404 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
405 unsigned field, ExprDef *array_ndx, ExprDef *value)
407 struct xkb_group_action *act;
409 xkb_group_index_t t2;
411 act = (struct xkb_group_action *) action;
412 if ((array_ndx != NULL) && (field == F_Group))
413 return ReportActionNotArray(keymap, action->type, field);
414 if (field == F_Group) {
416 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
423 return ReportIllegal(keymap, action->type, field);
427 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
428 unsigned field, ExprDef *array_ndx, ExprDef *value)
431 struct xkb_pointer_action *act;
434 act = (struct xkb_pointer_action *) action;
435 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
436 return ReportActionNotArray(keymap, action->type, field);
438 if ((field == F_X) || (field == F_Y)) {
439 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
443 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
444 return ReportMismatch(keymap, action->type, field, "integer");
447 act->flags |= XkbSA_MoveAbsoluteX;
452 act->flags |= XkbSA_MoveAbsoluteY;
457 else if (field == F_Accel) {
460 if (!ExprResolveBoolean(keymap->ctx, value, &set))
461 return ReportMismatch(keymap, action->type, field, "boolean");
464 act->flags &= ~XkbSA_NoAcceleration;
466 act->flags |= XkbSA_NoAcceleration;
469 return ReportIllegal(keymap, action->type, field);
472 static const LookupEntry lockWhich[] = {
474 { "lock", XkbSA_LockNoUnlock },
475 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
476 { "unlock", XkbSA_LockNoLock },
481 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
482 unsigned field, ExprDef *array_ndx, ExprDef *value)
485 struct xkb_pointer_button_action *act;
487 act = (struct xkb_pointer_button_action *) action;
488 if (field == F_Button) {
492 return ReportActionNotArray(keymap, action->type, field);
494 if (!ExprResolveButton(keymap->ctx, value, &btn))
495 return ReportMismatch(keymap, action->type, field,
496 "integer (range 1..5)");
498 if (btn < 0 || btn > 5) {
500 "Button must specify default or be in the range 1..5; "
501 "Illegal button value %d ignored\n", btn);
508 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
509 if (array_ndx != NULL)
510 return ReportActionNotArray(keymap, action->type, field);
511 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
512 return ReportMismatch(keymap, action->type, field,
514 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
515 act->flags |= rtrn.ival;
518 else if (field == F_Count) {
522 return ReportActionNotArray(keymap, action->type, field);
524 /* XXX: Should this actually be ResolveButton? */
525 if (!ExprResolveButton(keymap->ctx, value, &btn))
526 return ReportMismatch(keymap, action->type, field, "integer");
528 if (btn < 0 || btn > 255) {
530 "The count field must have a value in the range 0..255; "
531 "Illegal count %d ignored\n", rtrn.ival);
538 return ReportIllegal(keymap, action->type, field);
541 static const LookupEntry ptrDflts[] = {
542 { "dfltbtn", XkbSA_AffectDfltBtn },
543 { "defaultbutton", XkbSA_AffectDfltBtn },
544 { "button", XkbSA_AffectDfltBtn },
549 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
550 unsigned field, ExprDef *array_ndx, ExprDef *value)
553 struct xkb_pointer_default_action *act;
555 act = (struct xkb_pointer_default_action *) action;
556 if (field == F_Affect) {
557 if (array_ndx != NULL)
558 return ReportActionNotArray(keymap, action->type, field);
559 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
560 return ReportMismatch(keymap, action->type, field,
561 "pointer component");
562 act->affect = rtrn.uval;
565 else if ((field == F_Button) || (field == F_Value)) {
570 return ReportActionNotArray(keymap, action->type, field);
572 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
573 act->flags &= ~XkbSA_DfltBtnAbsolute;
574 button = value->value.child;
577 act->flags |= XkbSA_DfltBtnAbsolute;
581 if (!ExprResolveButton(keymap->ctx, button, &btn))
582 return ReportMismatch(keymap, action->type, field,
583 "integer (range 1..5)");
585 if (btn < 0 || btn > 5) {
587 "New default button value must be in the range 1..5; "
588 "Illegal default button value %d ignored\n", rtrn.ival);
593 "Cannot set default pointer button to \"default\"; "
594 "Illegal default button setting ignored\n");
598 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
602 return ReportIllegal(keymap, action->type, field);
605 static const LookupEntry isoNames[] = {
606 { "mods", XkbSA_ISONoAffectMods },
607 { "modifiers", XkbSA_ISONoAffectMods },
608 { "group", XkbSA_ISONoAffectGroup },
609 { "groups", XkbSA_ISONoAffectGroup },
610 { "ptr", XkbSA_ISONoAffectPtr },
611 { "pointer", XkbSA_ISONoAffectPtr },
612 { "ctrls", XkbSA_ISONoAffectCtrls },
613 { "controls", XkbSA_ISONoAffectCtrls },
614 { "all", ~((unsigned) 0) },
620 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
621 unsigned field, ExprDef *array_ndx, ExprDef *value)
624 struct xkb_iso_action *act;
627 xkb_group_index_t group;
629 act = (struct xkb_iso_action *) action;
632 if (array_ndx != NULL)
633 return ReportActionNotArray(keymap, action->type, field);
635 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
636 act->flags = flags & (~XkbSA_ISODfltIsGroup);
637 act->real_mods = mods & 0xff;
638 act->vmods = (mods >> 8) & 0xff;
644 if (array_ndx != NULL)
645 return ReportActionNotArray(keymap, action->type, field);
647 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
648 act->flags = flags | XkbSA_ISODfltIsGroup;
655 if (array_ndx != NULL)
656 return ReportActionNotArray(keymap, action->type, field);
657 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
658 return ReportMismatch(keymap, action->type, field,
659 "keyboard component");
660 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
663 return ReportIllegal(keymap, action->type, field);
667 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
668 unsigned field, ExprDef *array_ndx, ExprDef *value)
671 struct xkb_switch_screen_action *act;
673 act = (struct xkb_switch_screen_action *) action;
674 if (field == F_Screen) {
676 if (array_ndx != NULL)
677 return ReportActionNotArray(keymap, action->type, field);
678 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
679 act->flags &= ~XkbSA_SwitchAbsolute;
680 scrn = value->value.child;
683 act->flags |= XkbSA_SwitchAbsolute;
687 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
688 return ReportMismatch(keymap, action->type, field,
690 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
692 "Screen index must be in the range 1..255; "
693 "Illegal screen value %d ignored\n", rtrn.ival);
696 if (value->op == EXPR_NEGATE)
697 act->screen = -rtrn.ival;
699 act->screen = rtrn.ival;
702 else if (field == F_Same) {
706 return ReportActionNotArray(keymap, action->type, field);
708 if (!ExprResolveBoolean(keymap->ctx, value, &set))
709 return ReportMismatch(keymap, action->type, field, "boolean");
712 act->flags &= ~XkbSA_SwitchApplication;
714 act->flags |= XkbSA_SwitchApplication;
719 return ReportIllegal(keymap, action->type, field);
722 const LookupEntry ctrlNames[] = {
723 { "repeatkeys", XkbRepeatKeysMask },
724 { "repeat", XkbRepeatKeysMask },
725 { "autorepeat", XkbRepeatKeysMask },
726 { "slowkeys", XkbSlowKeysMask },
727 { "bouncekeys", XkbBounceKeysMask },
728 { "stickykeys", XkbStickyKeysMask },
729 { "mousekeys", XkbMouseKeysMask },
730 { "mousekeysaccel", XkbMouseKeysAccelMask },
731 { "accessxkeys", XkbAccessXKeysMask },
732 { "accessxtimeout", XkbAccessXTimeoutMask },
733 { "accessxfeedback", XkbAccessXFeedbackMask },
734 { "audiblebell", XkbAudibleBellMask },
735 { "ignoregrouplock", XkbIgnoreGroupLockMask },
736 { "all", XkbAllBooleanCtrlsMask },
744 HandleSetLockControls(struct xkb_keymap *keymap,
745 struct xkb_any_action *action,
746 unsigned field, ExprDef *array_ndx,
750 struct xkb_controls_action *act;
752 act = (struct xkb_controls_action *) action;
753 if (field == F_Controls) {
754 if (array_ndx != NULL)
755 return ReportActionNotArray(keymap, action->type, field);
756 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
757 return ReportMismatch(keymap, action->type, field,
759 act->ctrls = rtrn.uval;
762 return ReportIllegal(keymap, action->type, field);
765 static const LookupEntry evNames[] = {
766 { "press", XkbSA_MessageOnPress },
767 { "keypress", XkbSA_MessageOnPress },
768 { "release", XkbSA_MessageOnRelease },
769 { "keyrelease", XkbSA_MessageOnRelease },
770 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
776 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
777 unsigned field, ExprDef *array_ndx, ExprDef *value)
782 struct xkb_message_action *act;
784 act = (struct xkb_message_action *) action;
787 if (array_ndx != NULL)
788 return ReportActionNotArray(keymap, action->type, field);
789 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
790 return ReportMismatch(keymap, action->type, field,
792 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
794 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
799 return ReportActionNotArray(keymap, action->type, field);
801 if (!ExprResolveBoolean(keymap->ctx, value, &set))
802 return ReportMismatch(keymap, action->type, field, "boolean");
805 act->flags |= XkbSA_MessageGenKeyEvent;
807 act->flags &= ~XkbSA_MessageGenKeyEvent;
812 if (array_ndx == NULL) {
815 if (!ExprResolveString(keymap->ctx, value, &str))
816 return ReportMismatch(keymap, action->type, field, "string");
819 if (len < 1 || len > 6) {
820 log_warn(keymap->ctx,
821 "An action message can hold only 6 bytes; "
822 "Extra %d bytes ignored\n", len - 6);
825 strncpy((char *) act->message, str, 6);
830 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
832 "Array subscript must be integer; "
833 "Illegal subscript ignored\n");
839 "An action message is at most 6 bytes long; "
840 "Attempt to use data[%d] ignored\n", ndx);
843 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
844 return ReportMismatch(keymap, action->type, field, "integer");
845 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
847 "Message data must be in the range 0..255; "
848 "Illegal datum %d ignored\n", rtrn.ival);
851 act->message[ndx] = rtrn.uval;
855 return ReportIllegal(keymap, action->type, field);
859 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
860 unsigned field, ExprDef *array_ndx, ExprDef *value)
863 struct xkb_redirect_key_action *act;
867 char key_name[XkbKeyNameLength];
869 if (array_ndx != NULL)
870 return ReportActionNotArray(keymap, action->type, field);
872 act = (struct xkb_redirect_key_action *) action;
875 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
876 return ReportMismatch(keymap, action->type, field, "key name");
878 tmp = KeyNameToLong(key_name);
879 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
881 return ReportNotFound(keymap, action->type, field, "Key",
882 KeyNameText(key_name));
883 act->new_kc = XkbKeyGetKeycode(keymap, key);
889 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
890 act->mods_mask |= (t2 & 0xff);
891 if (field == F_Modifiers)
892 act->mods |= (t2 & 0xff);
894 act->mods &= ~(t2 & 0xff);
896 t2 = (t2 >> 8) & 0xffff;
897 act->vmods_mask |= t2;
898 if (field == F_Modifiers)
906 return ReportIllegal(keymap, action->type, field);
910 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
911 unsigned field, ExprDef *array_ndx, ExprDef *value)
914 struct xkb_device_button_action *act;
916 act = (struct xkb_device_button_action *) action;
917 if (field == F_Button) {
918 if (array_ndx != NULL)
919 return ReportActionNotArray(keymap, action->type, field);
920 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
921 return ReportMismatch(keymap, action->type, field,
922 "integer (range 1..255)");
923 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
925 "Button must specify default or be in the range 1..255; "
926 "Illegal button value %d ignored\n", rtrn.ival);
929 act->button = rtrn.ival;
932 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
933 if (array_ndx != NULL)
934 return ReportActionNotArray(keymap, action->type, field);
935 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
936 return ReportMismatch(keymap, action->type, field,
938 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
939 act->flags |= rtrn.ival;
942 else if (field == F_Count) {
946 return ReportActionNotArray(keymap, action->type, field);
948 /* XXX: Should this actually be ResolveButton? */
949 if (!ExprResolveButton(keymap->ctx, value, &btn))
950 return ReportMismatch(keymap, action->type, field, "integer");
952 if (btn < 0 || btn > 255) {
954 "The count field must have a value in the range 0..255; "
955 "Illegal count %d ignored\n", rtrn.ival);
962 else if (field == F_Device) {
963 if (array_ndx != NULL)
964 return ReportActionNotArray(keymap, action->type, field);
965 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
966 return ReportMismatch(keymap, action->type, field,
967 "integer (range 1..255)");
968 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
970 "Device must specify default or be in the range 1..255; "
971 "Illegal device value %d ignored\n", rtrn.ival);
974 act->device = rtrn.ival;
977 return ReportIllegal(keymap, action->type, field);
981 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
982 unsigned field, ExprDef *array_ndx, ExprDef *value)
986 struct xkb_device_valuator_action *act;
988 act = (struct xkb_device_valuator_action *) action;
989 /* XXX - Not yet implemented */
995 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
996 unsigned field, ExprDef *array_ndx, ExprDef *value)
1002 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1003 return ReportMismatch(keymap, PrivateAction, field, "integer");
1004 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1005 log_err(keymap->ctx,
1006 "Private action type must be in the range 0..255; "
1007 "Illegal type %d ignored\n", rtrn.ival);
1010 action->type = rtrn.uval;
1014 if (array_ndx == NULL) {
1018 if (!ExprResolveString(keymap->ctx, value, &str))
1019 return ReportMismatch(keymap, action->type, field, "string");
1022 if (len < 1 || len > 7) {
1023 log_warn(keymap->ctx,
1024 "A private action has 7 data bytes; "
1025 "Extra %d bytes ignored\n", len - 6);
1029 strncpy((char *) action->data, str, sizeof(action->data));
1034 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
1035 log_err(keymap->ctx,
1036 "Array subscript must be integer; "
1037 "Illegal subscript ignored\n");
1041 if (ndx >= sizeof action->data) {
1042 log_err(keymap->ctx,
1043 "The data for a private action is 18 bytes long; "
1044 "Attempt to use data[%d] ignored\n", ndx);
1047 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1048 return ReportMismatch(keymap, action->type, field, "integer");
1049 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1050 log_err(keymap->ctx,
1051 "All data for a private action must be 0..255; "
1052 "Illegal datum %d ignored\n", rtrn.ival);
1055 action->data[ndx] = rtrn.uval;
1059 return ReportIllegal(keymap, PrivateAction, field);
1062 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1063 struct xkb_any_action *action, unsigned field,
1064 ExprDef *array_ndx, ExprDef *value);
1066 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1067 [XkbSA_NoAction] = HandleNoAction,
1068 [XkbSA_SetMods] = HandleSetLatchMods,
1069 [XkbSA_LatchMods] = HandleSetLatchMods,
1070 [XkbSA_LockMods] = HandleLockMods,
1071 [XkbSA_SetGroup] = HandleSetLatchGroup,
1072 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1073 [XkbSA_LockGroup] = HandleLockGroup,
1074 [XkbSA_MovePtr] = HandleMovePtr,
1075 [XkbSA_PtrBtn] = HandlePtrBtn,
1076 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1077 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1078 [XkbSA_ISOLock] = HandleISOLock,
1079 [XkbSA_Terminate] = HandleNoAction,
1080 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1081 [XkbSA_SetControls] = HandleSetLockControls,
1082 [XkbSA_LockControls] = HandleSetLockControls,
1083 [XkbSA_ActionMessage] = HandleActionMessage,
1084 [XkbSA_RedirectKey] = HandleRedirectKey,
1085 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1086 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1087 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1088 [PrivateAction] = HandlePrivate,
1091 /***====================================================================***/
1094 ApplyActionFactoryDefaults(union xkb_action * action)
1096 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1097 action->dflt.affect = XkbSA_AffectDfltBtn;
1098 action->dflt.flags = 0;
1099 action->dflt.value = 1;
1101 else if (action->type == XkbSA_ISOLock) {
1102 action->iso.real_mods = LockMask;
1107 ActionsInit(struct xkb_context *ctx);
1110 HandleActionDef(ExprDef * def,
1111 struct xkb_keymap *keymap,
1112 struct xkb_any_action *action, ActionInfo *info)
1116 unsigned tmp, hndlrType;
1118 if (!actionsInitialized)
1119 ActionsInit(keymap->ctx);
1121 if (def->op != EXPR_ACTION_DECL) {
1122 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1123 exprOpText(def->op));
1126 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1128 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1131 if (!stringToAction(str, &tmp)) {
1132 log_err(keymap->ctx, "Unknown action %s\n", str);
1135 action->type = hndlrType = tmp;
1136 if (action->type != XkbSA_NoAction) {
1137 ApplyActionFactoryDefaults((union xkb_action *) action);
1140 if ((info->action == XkbSA_NoAction)
1141 || (info->action == hndlrType)) {
1142 if (!(*handleAction[hndlrType])(keymap, action,
1152 for (arg = def->value.action.args; arg != NULL;
1153 arg = (ExprDef *) arg->common.next) {
1154 ExprDef *field, *value, *arrayRtrn;
1155 const char *elemRtrn, *fieldRtrn;
1158 if (arg->op == EXPR_ASSIGN) {
1159 field = arg->value.binary.left;
1160 value = arg->value.binary.right;
1163 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1164 field = arg->value.child;
1165 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1166 value = &constFalse;
1170 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1174 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1176 return false; /* internal error -- already reported */
1178 if (elemRtrn != NULL) {
1179 log_err(keymap->ctx,
1180 "Cannot change defaults in an action definition; "
1181 "Ignoring attempt to change %s.%s\n",
1182 elemRtrn, fieldRtrn);
1185 if (!stringToField(fieldRtrn, &fieldNdx)) {
1186 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1189 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1196 /***====================================================================***/
1199 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1200 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1202 ActionInfo *new, *old;
1204 if (!actionsInitialized)
1205 ActionsInit(keymap->ctx);
1207 new = malloc(sizeof(*new));
1209 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1213 if (istreq(elem, "action"))
1214 new->action = XkbSA_NoAction;
1216 if (!stringToAction(elem, &new->action)) {
1220 if (new->action == XkbSA_NoAction) {
1221 log_err(keymap->ctx,
1222 "\"%s\" is not a valid field in a NoAction action\n",
1228 if (!stringToField(field, &new->field)) {
1229 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1233 new->array_ndx = array_ndx;
1237 while ((old) && (old->next))
1246 /***====================================================================***/
1249 ActionsInit(struct xkb_context *ctx)
1251 if (!actionsInitialized) {
1252 memset(&constTrue, 0, sizeof(constTrue));
1253 memset(&constFalse, 0, sizeof(constFalse));
1254 constTrue.common.type = STMT_EXPR;
1255 constTrue.common.next = NULL;
1256 constTrue.op = EXPR_IDENT;
1257 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1258 constTrue.value.str = xkb_atom_intern(ctx, "true");
1259 constFalse.common.type = STMT_EXPR;
1260 constFalse.common.next = NULL;
1261 constFalse.op = EXPR_IDENT;
1262 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1263 constFalse.value.str = xkb_atom_intern(ctx, "false");
1264 actionsInitialized = 1;
1269 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1272 size_t old_ndx, old_num_acts, new_ndx;
1275 key->acts_index = 0;
1279 if (XkbKeyHasActions(key) && key->width >= needed)
1280 return XkbKeyActionsPtr(keymap, key);
1283 * The key may already be in the array, but without enough space.
1284 * This should not happen often, so in order to avoid moving and
1285 * copying stuff from acts and key_acts, we just allocate new
1286 * space for the key at the end, and leave the old space alone.
1289 old_ndx = key->acts_index;
1290 old_num_acts = XkbKeyNumActions(key);
1291 new_ndx = darray_size(keymap->acts);
1293 darray_resize0(keymap->acts, new_ndx + needed);
1294 key->acts_index = new_ndx;
1297 * The key was already in the array, copy the old actions to the
1301 memcpy(darray_mem(keymap->acts, new_ndx),
1302 darray_mem(keymap->acts, old_ndx),
1303 old_num_acts * sizeof(union xkb_action));
1305 return XkbKeyActionsPtr(keymap, key);