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)
430 struct xkb_pointer_action *act;
433 act = (struct xkb_pointer_action *) action;
434 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
435 return ReportActionNotArray(keymap, action->type, field);
437 if (field == F_X || field == F_Y) {
440 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
445 if (!ExprResolveInteger(keymap->ctx, value, &val))
446 return ReportMismatch(keymap, action->type, field, "integer");
450 act->flags |= XkbSA_MoveAbsoluteX;
455 act->flags |= XkbSA_MoveAbsoluteY;
461 else if (field == F_Accel) {
464 if (!ExprResolveBoolean(keymap->ctx, value, &set))
465 return ReportMismatch(keymap, action->type, field, "boolean");
468 act->flags &= ~XkbSA_NoAcceleration;
470 act->flags |= XkbSA_NoAcceleration;
473 return ReportIllegal(keymap, action->type, field);
476 static const LookupEntry lockWhich[] = {
478 { "lock", XkbSA_LockNoUnlock },
479 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
480 { "unlock", XkbSA_LockNoLock },
485 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
486 unsigned field, ExprDef *array_ndx, ExprDef *value)
489 struct xkb_pointer_button_action *act;
491 act = (struct xkb_pointer_button_action *) action;
492 if (field == F_Button) {
496 return ReportActionNotArray(keymap, action->type, field);
498 if (!ExprResolveButton(keymap->ctx, value, &btn))
499 return ReportMismatch(keymap, action->type, field,
500 "integer (range 1..5)");
502 if (btn < 0 || btn > 5) {
504 "Button must specify default or be in the range 1..5; "
505 "Illegal button value %d ignored\n", btn);
512 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
513 if (array_ndx != NULL)
514 return ReportActionNotArray(keymap, action->type, field);
515 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
516 return ReportMismatch(keymap, action->type, field,
518 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
519 act->flags |= rtrn.ival;
522 else if (field == F_Count) {
526 return ReportActionNotArray(keymap, action->type, field);
528 /* XXX: Should this actually be ResolveButton? */
529 if (!ExprResolveButton(keymap->ctx, value, &btn))
530 return ReportMismatch(keymap, action->type, field, "integer");
532 if (btn < 0 || btn > 255) {
534 "The count field must have a value in the range 0..255; "
535 "Illegal count %d ignored\n", rtrn.ival);
542 return ReportIllegal(keymap, action->type, field);
545 static const LookupEntry ptrDflts[] = {
546 { "dfltbtn", XkbSA_AffectDfltBtn },
547 { "defaultbutton", XkbSA_AffectDfltBtn },
548 { "button", XkbSA_AffectDfltBtn },
553 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
554 unsigned field, ExprDef *array_ndx, ExprDef *value)
557 struct xkb_pointer_default_action *act;
559 act = (struct xkb_pointer_default_action *) action;
560 if (field == F_Affect) {
561 if (array_ndx != NULL)
562 return ReportActionNotArray(keymap, action->type, field);
563 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
564 return ReportMismatch(keymap, action->type, field,
565 "pointer component");
566 act->affect = rtrn.uval;
569 else if ((field == F_Button) || (field == F_Value)) {
574 return ReportActionNotArray(keymap, action->type, field);
576 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
577 act->flags &= ~XkbSA_DfltBtnAbsolute;
578 button = value->value.child;
581 act->flags |= XkbSA_DfltBtnAbsolute;
585 if (!ExprResolveButton(keymap->ctx, button, &btn))
586 return ReportMismatch(keymap, action->type, field,
587 "integer (range 1..5)");
589 if (btn < 0 || btn > 5) {
591 "New default button value must be in the range 1..5; "
592 "Illegal default button value %d ignored\n", rtrn.ival);
597 "Cannot set default pointer button to \"default\"; "
598 "Illegal default button setting ignored\n");
602 act->value = (value->op == EXPR_NEGATE ? -btn: btn);
606 return ReportIllegal(keymap, action->type, field);
609 static const LookupEntry isoNames[] = {
610 { "mods", XkbSA_ISONoAffectMods },
611 { "modifiers", XkbSA_ISONoAffectMods },
612 { "group", XkbSA_ISONoAffectGroup },
613 { "groups", XkbSA_ISONoAffectGroup },
614 { "ptr", XkbSA_ISONoAffectPtr },
615 { "pointer", XkbSA_ISONoAffectPtr },
616 { "ctrls", XkbSA_ISONoAffectCtrls },
617 { "controls", XkbSA_ISONoAffectCtrls },
618 { "all", ~((unsigned) 0) },
624 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
625 unsigned field, ExprDef *array_ndx, ExprDef *value)
628 struct xkb_iso_action *act;
631 xkb_group_index_t group;
633 act = (struct xkb_iso_action *) action;
636 if (array_ndx != NULL)
637 return ReportActionNotArray(keymap, action->type, field);
639 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
640 act->flags = flags & (~XkbSA_ISODfltIsGroup);
641 act->real_mods = mods & 0xff;
642 act->vmods = (mods >> 8) & 0xff;
648 if (array_ndx != NULL)
649 return ReportActionNotArray(keymap, action->type, field);
651 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
652 act->flags = flags | XkbSA_ISODfltIsGroup;
659 if (array_ndx != NULL)
660 return ReportActionNotArray(keymap, action->type, field);
661 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
662 return ReportMismatch(keymap, action->type, field,
663 "keyboard component");
664 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
667 return ReportIllegal(keymap, action->type, field);
671 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
672 unsigned field, ExprDef *array_ndx, ExprDef *value)
675 struct xkb_switch_screen_action *act;
677 act = (struct xkb_switch_screen_action *) action;
678 if (field == F_Screen) {
683 return ReportActionNotArray(keymap, action->type, field);
685 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
686 act->flags &= ~XkbSA_SwitchAbsolute;
687 scrn = value->value.child;
690 act->flags |= XkbSA_SwitchAbsolute;
694 if (!ExprResolveInteger(keymap->ctx, scrn, &val))
695 return ReportMismatch(keymap, action->type, field,
698 if (val < 0 || val > 255) {
700 "Screen index must be in the range 1..255; "
701 "Illegal screen value %d ignored\n", rtrn.ival);
705 act->screen = (value->op == EXPR_NEGATE ? -val : val);
708 else if (field == F_Same) {
712 return ReportActionNotArray(keymap, action->type, field);
714 if (!ExprResolveBoolean(keymap->ctx, value, &set))
715 return ReportMismatch(keymap, action->type, field, "boolean");
718 act->flags &= ~XkbSA_SwitchApplication;
720 act->flags |= XkbSA_SwitchApplication;
725 return ReportIllegal(keymap, action->type, field);
728 const LookupEntry ctrlNames[] = {
729 { "repeatkeys", XkbRepeatKeysMask },
730 { "repeat", XkbRepeatKeysMask },
731 { "autorepeat", XkbRepeatKeysMask },
732 { "slowkeys", XkbSlowKeysMask },
733 { "bouncekeys", XkbBounceKeysMask },
734 { "stickykeys", XkbStickyKeysMask },
735 { "mousekeys", XkbMouseKeysMask },
736 { "mousekeysaccel", XkbMouseKeysAccelMask },
737 { "accessxkeys", XkbAccessXKeysMask },
738 { "accessxtimeout", XkbAccessXTimeoutMask },
739 { "accessxfeedback", XkbAccessXFeedbackMask },
740 { "audiblebell", XkbAudibleBellMask },
741 { "ignoregrouplock", XkbIgnoreGroupLockMask },
742 { "all", XkbAllBooleanCtrlsMask },
750 HandleSetLockControls(struct xkb_keymap *keymap,
751 struct xkb_any_action *action,
752 unsigned field, ExprDef *array_ndx,
756 struct xkb_controls_action *act;
758 act = (struct xkb_controls_action *) action;
759 if (field == F_Controls) {
760 if (array_ndx != NULL)
761 return ReportActionNotArray(keymap, action->type, field);
762 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
763 return ReportMismatch(keymap, action->type, field,
765 act->ctrls = rtrn.uval;
768 return ReportIllegal(keymap, action->type, field);
771 static const LookupEntry evNames[] = {
772 { "press", XkbSA_MessageOnPress },
773 { "keypress", XkbSA_MessageOnPress },
774 { "release", XkbSA_MessageOnRelease },
775 { "keyrelease", XkbSA_MessageOnRelease },
776 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
782 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
783 unsigned field, ExprDef *array_ndx, ExprDef *value)
788 struct xkb_message_action *act;
790 act = (struct xkb_message_action *) action;
793 if (array_ndx != NULL)
794 return ReportActionNotArray(keymap, action->type, field);
795 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
796 return ReportMismatch(keymap, action->type, field,
798 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
800 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
805 return ReportActionNotArray(keymap, action->type, field);
807 if (!ExprResolveBoolean(keymap->ctx, value, &set))
808 return ReportMismatch(keymap, action->type, field, "boolean");
811 act->flags |= XkbSA_MessageGenKeyEvent;
813 act->flags &= ~XkbSA_MessageGenKeyEvent;
818 if (array_ndx == NULL) {
821 if (!ExprResolveString(keymap->ctx, value, &str))
822 return ReportMismatch(keymap, action->type, field, "string");
825 if (len < 1 || len > 6) {
826 log_warn(keymap->ctx,
827 "An action message can hold only 6 bytes; "
828 "Extra %d bytes ignored\n", len - 6);
831 strncpy((char *) act->message, str, 6);
837 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
839 "Array subscript must be integer; "
840 "Illegal subscript ignored\n");
844 if (ndx < 0 || ndx > 5) {
846 "An action message is at most 6 bytes long; "
847 "Attempt to use data[%d] ignored\n", ndx);
851 if (!ExprResolveInteger(keymap->ctx, value, &datum))
852 return ReportMismatch(keymap, action->type, field, "integer");
854 if (datum < 0 || datum > 255) {
856 "Message data must be in the range 0..255; "
857 "Illegal datum %d ignored\n", datum);
861 act->message[ndx] = (uint8_t) datum;
867 return ReportIllegal(keymap, action->type, field);
871 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
872 unsigned field, ExprDef *array_ndx, ExprDef *value)
875 struct xkb_redirect_key_action *act;
879 char key_name[XkbKeyNameLength];
881 if (array_ndx != NULL)
882 return ReportActionNotArray(keymap, action->type, field);
884 act = (struct xkb_redirect_key_action *) action;
887 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
888 return ReportMismatch(keymap, action->type, field, "key name");
890 tmp = KeyNameToLong(key_name);
891 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
893 return ReportNotFound(keymap, action->type, field, "Key",
894 KeyNameText(key_name));
895 act->new_kc = XkbKeyGetKeycode(keymap, key);
901 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
902 act->mods_mask |= (t2 & 0xff);
903 if (field == F_Modifiers)
904 act->mods |= (t2 & 0xff);
906 act->mods &= ~(t2 & 0xff);
908 t2 = (t2 >> 8) & 0xffff;
909 act->vmods_mask |= t2;
910 if (field == F_Modifiers)
918 return ReportIllegal(keymap, action->type, field);
922 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
923 unsigned field, ExprDef *array_ndx, ExprDef *value)
926 struct xkb_device_button_action *act;
928 act = (struct xkb_device_button_action *) action;
929 if (field == F_Button) {
933 return ReportActionNotArray(keymap, action->type, field);
935 if (!ExprResolveInteger(keymap->ctx, value, &val))
936 return ReportMismatch(keymap, action->type, field,
937 "integer (range 1..255)");
939 if (val < 0 || val > 255) {
941 "Button must specify default or be in the range 1..255; "
942 "Illegal button value %d ignored\n", val);
949 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
950 if (array_ndx != NULL)
951 return ReportActionNotArray(keymap, action->type, field);
952 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
953 return ReportMismatch(keymap, action->type, field,
955 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
956 act->flags |= rtrn.ival;
959 else if (field == F_Count) {
963 return ReportActionNotArray(keymap, action->type, field);
965 /* XXX: Should this actually be ResolveButton? */
966 if (!ExprResolveButton(keymap->ctx, value, &btn))
967 return ReportMismatch(keymap, action->type, field, "integer");
969 if (btn < 0 || btn > 255) {
971 "The count field must have a value in the range 0..255; "
972 "Illegal count %d ignored\n", rtrn.ival);
979 else if (field == F_Device) {
983 return ReportActionNotArray(keymap, action->type, field);
985 if (!ExprResolveInteger(keymap->ctx, value, &val))
986 return ReportMismatch(keymap, action->type, field,
987 "integer (range 1..255)");
989 if (val < 0 || val > 255) {
991 "Device must specify default or be in the range 1..255; "
992 "Illegal device value %d ignored\n", val);
1000 return ReportIllegal(keymap, action->type, field);
1004 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
1005 unsigned field, ExprDef *array_ndx, ExprDef *value)
1009 struct xkb_device_valuator_action *act;
1011 act = (struct xkb_device_valuator_action *) action;
1012 /* XXX - Not yet implemented */
1018 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
1019 unsigned field, ExprDef *array_ndx, ExprDef *value)
1021 if (field == F_Type) {
1024 if (!ExprResolveInteger(keymap->ctx, value, &type))
1025 return ReportMismatch(keymap, PrivateAction, field, "integer");
1027 if (type < 0 || type > 255) {
1028 log_err(keymap->ctx,
1029 "Private action type must be in the range 0..255; "
1030 "Illegal type %d ignored\n", type);
1034 action->type = (uint8_t) type;
1037 else if (field == F_Data) {
1038 if (array_ndx == NULL) {
1042 if (!ExprResolveString(keymap->ctx, value, &str))
1043 return ReportMismatch(keymap, action->type, field, "string");
1046 if (len < 1 || len > 7) {
1047 log_warn(keymap->ctx,
1048 "A private action has 7 data bytes; "
1049 "Extra %d bytes ignored\n", len - 6);
1053 strncpy((char *) action->data, str, sizeof(action->data));
1059 if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
1060 log_err(keymap->ctx,
1061 "Array subscript must be integer; "
1062 "Illegal subscript ignored\n");
1066 if (ndx < 0 || ndx >= sizeof(action->data)) {
1067 log_err(keymap->ctx,
1068 "The data for a private action is %zu bytes long; "
1069 "Attempt to use data[%d] ignored\n",
1070 sizeof(action->data), ndx);
1074 if (!ExprResolveInteger(keymap->ctx, value, &datum))
1075 return ReportMismatch(keymap, action->type, field, "integer");
1077 if (datum < 0 || datum > 255) {
1078 log_err(keymap->ctx,
1079 "All data for a private action must be 0..255; "
1080 "Illegal datum %d ignored\n", datum);
1084 action->data[ndx] = (uint8_t) datum;
1089 return ReportIllegal(keymap, PrivateAction, field);
1092 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1093 struct xkb_any_action *action, unsigned field,
1094 ExprDef *array_ndx, ExprDef *value);
1096 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1097 [XkbSA_NoAction] = HandleNoAction,
1098 [XkbSA_SetMods] = HandleSetLatchMods,
1099 [XkbSA_LatchMods] = HandleSetLatchMods,
1100 [XkbSA_LockMods] = HandleLockMods,
1101 [XkbSA_SetGroup] = HandleSetLatchGroup,
1102 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1103 [XkbSA_LockGroup] = HandleLockGroup,
1104 [XkbSA_MovePtr] = HandleMovePtr,
1105 [XkbSA_PtrBtn] = HandlePtrBtn,
1106 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1107 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1108 [XkbSA_ISOLock] = HandleISOLock,
1109 [XkbSA_Terminate] = HandleNoAction,
1110 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1111 [XkbSA_SetControls] = HandleSetLockControls,
1112 [XkbSA_LockControls] = HandleSetLockControls,
1113 [XkbSA_ActionMessage] = HandleActionMessage,
1114 [XkbSA_RedirectKey] = HandleRedirectKey,
1115 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1116 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1117 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1118 [PrivateAction] = HandlePrivate,
1121 /***====================================================================***/
1124 ApplyActionFactoryDefaults(union xkb_action * action)
1126 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1127 action->dflt.affect = XkbSA_AffectDfltBtn;
1128 action->dflt.flags = 0;
1129 action->dflt.value = 1;
1131 else if (action->type == XkbSA_ISOLock) {
1132 action->iso.real_mods = LockMask;
1137 ActionsInit(struct xkb_context *ctx);
1140 HandleActionDef(ExprDef * def,
1141 struct xkb_keymap *keymap,
1142 struct xkb_any_action *action, ActionInfo *info)
1146 unsigned tmp, hndlrType;
1148 if (!actionsInitialized)
1149 ActionsInit(keymap->ctx);
1151 if (def->op != EXPR_ACTION_DECL) {
1152 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1153 exprOpText(def->op));
1156 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1158 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1161 if (!stringToAction(str, &tmp)) {
1162 log_err(keymap->ctx, "Unknown action %s\n", str);
1165 action->type = hndlrType = tmp;
1166 if (action->type != XkbSA_NoAction) {
1167 ApplyActionFactoryDefaults((union xkb_action *) action);
1170 if ((info->action == XkbSA_NoAction)
1171 || (info->action == hndlrType)) {
1172 if (!(*handleAction[hndlrType])(keymap, action,
1182 for (arg = def->value.action.args; arg != NULL;
1183 arg = (ExprDef *) arg->common.next) {
1184 ExprDef *field, *value, *arrayRtrn;
1185 const char *elemRtrn, *fieldRtrn;
1188 if (arg->op == EXPR_ASSIGN) {
1189 field = arg->value.binary.left;
1190 value = arg->value.binary.right;
1193 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1194 field = arg->value.child;
1195 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1196 value = &constFalse;
1200 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1204 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1206 return false; /* internal error -- already reported */
1208 if (elemRtrn != NULL) {
1209 log_err(keymap->ctx,
1210 "Cannot change defaults in an action definition; "
1211 "Ignoring attempt to change %s.%s\n",
1212 elemRtrn, fieldRtrn);
1215 if (!stringToField(fieldRtrn, &fieldNdx)) {
1216 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1219 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1226 /***====================================================================***/
1229 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1230 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1232 ActionInfo *new, *old;
1234 if (!actionsInitialized)
1235 ActionsInit(keymap->ctx);
1237 new = malloc(sizeof(*new));
1239 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1243 if (istreq(elem, "action"))
1244 new->action = XkbSA_NoAction;
1246 if (!stringToAction(elem, &new->action)) {
1250 if (new->action == XkbSA_NoAction) {
1251 log_err(keymap->ctx,
1252 "\"%s\" is not a valid field in a NoAction action\n",
1258 if (!stringToField(field, &new->field)) {
1259 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1263 new->array_ndx = array_ndx;
1267 while ((old) && (old->next))
1276 /***====================================================================***/
1279 ActionsInit(struct xkb_context *ctx)
1281 if (!actionsInitialized) {
1282 memset(&constTrue, 0, sizeof(constTrue));
1283 memset(&constFalse, 0, sizeof(constFalse));
1284 constTrue.common.type = STMT_EXPR;
1285 constTrue.common.next = NULL;
1286 constTrue.op = EXPR_IDENT;
1287 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1288 constTrue.value.str = xkb_atom_intern(ctx, "true");
1289 constFalse.common.type = STMT_EXPR;
1290 constFalse.common.next = NULL;
1291 constFalse.op = EXPR_IDENT;
1292 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1293 constFalse.value.str = xkb_atom_intern(ctx, "false");
1294 actionsInitialized = 1;
1299 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1302 size_t old_ndx, old_num_acts, new_ndx;
1305 key->acts_index = 0;
1309 if (XkbKeyHasActions(key) && key->width >= needed)
1310 return XkbKeyActionsPtr(keymap, key);
1313 * The key may already be in the array, but without enough space.
1314 * This should not happen often, so in order to avoid moving and
1315 * copying stuff from acts and key_acts, we just allocate new
1316 * space for the key at the end, and leave the old space alone.
1319 old_ndx = key->acts_index;
1320 old_num_acts = XkbKeyNumActions(key);
1321 new_ndx = darray_size(keymap->acts);
1323 darray_resize0(keymap->acts, new_ndx + needed);
1324 key->acts_index = new_ndx;
1327 * The key was already in the array, copy the old actions to the
1331 memcpy(darray_mem(keymap->acts, new_ndx),
1332 darray_mem(keymap->acts, old_ndx),
1333 old_num_acts * sizeof(union xkb_action));
1335 return XkbKeyActionsPtr(keymap, key);