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) {
489 if (array_ndx != NULL)
490 return ReportActionNotArray(keymap, action->type, field);
491 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
492 return ReportMismatch(keymap, action->type, field,
493 "integer (range 1..5)");
494 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
496 "Button must specify default or be in the range 1..5; "
497 "Illegal button value %d ignored\n", rtrn.ival);
500 act->button = rtrn.ival;
503 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
504 if (array_ndx != NULL)
505 return ReportActionNotArray(keymap, action->type, field);
506 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
507 return ReportMismatch(keymap, action->type, field,
509 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
510 act->flags |= rtrn.ival;
513 else if (field == F_Count) {
514 if (array_ndx != NULL)
515 return ReportActionNotArray(keymap, action->type, field);
516 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
517 return ReportMismatch(keymap, action->type, field, "integer");
518 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
520 "The count field must have a value in the range 0..255; "
521 "Illegal count %d ignored\n", rtrn.ival);
524 act->count = rtrn.ival;
527 return ReportIllegal(keymap, action->type, field);
530 static const LookupEntry ptrDflts[] = {
531 { "dfltbtn", XkbSA_AffectDfltBtn },
532 { "defaultbutton", XkbSA_AffectDfltBtn },
533 { "button", XkbSA_AffectDfltBtn },
538 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
539 unsigned field, ExprDef *array_ndx, ExprDef *value)
542 struct xkb_pointer_default_action *act;
544 act = (struct xkb_pointer_default_action *) action;
545 if (field == F_Affect) {
546 if (array_ndx != NULL)
547 return ReportActionNotArray(keymap, action->type, field);
548 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
549 return ReportMismatch(keymap, action->type, field,
550 "pointer component");
551 act->affect = rtrn.uval;
554 else if ((field == F_Button) || (field == F_Value)) {
556 if (array_ndx != NULL)
557 return ReportActionNotArray(keymap, action->type, field);
558 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
559 act->flags &= ~XkbSA_DfltBtnAbsolute;
560 btn = value->value.child;
563 act->flags |= XkbSA_DfltBtnAbsolute;
567 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
568 return ReportMismatch(keymap, action->type, field,
569 "integer (range 1..5)");
570 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
572 "New default button value must be in the range 1..5; "
573 "Illegal default button value %d ignored\n", rtrn.ival);
576 if (rtrn.ival == 0) {
578 "Cannot set default pointer button to \"default\"; "
579 "Illegal default button setting ignored\n");
583 act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival);
586 return ReportIllegal(keymap, action->type, field);
589 static const LookupEntry isoNames[] = {
590 { "mods", XkbSA_ISONoAffectMods },
591 { "modifiers", XkbSA_ISONoAffectMods },
592 { "group", XkbSA_ISONoAffectGroup },
593 { "groups", XkbSA_ISONoAffectGroup },
594 { "ptr", XkbSA_ISONoAffectPtr },
595 { "pointer", XkbSA_ISONoAffectPtr },
596 { "ctrls", XkbSA_ISONoAffectCtrls },
597 { "controls", XkbSA_ISONoAffectCtrls },
598 { "all", ~((unsigned) 0) },
604 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
605 unsigned field, ExprDef *array_ndx, ExprDef *value)
608 struct xkb_iso_action *act;
611 xkb_group_index_t group;
613 act = (struct xkb_iso_action *) action;
616 if (array_ndx != NULL)
617 return ReportActionNotArray(keymap, action->type, field);
619 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
620 act->flags = flags & (~XkbSA_ISODfltIsGroup);
621 act->real_mods = mods & 0xff;
622 act->vmods = (mods >> 8) & 0xff;
628 if (array_ndx != NULL)
629 return ReportActionNotArray(keymap, action->type, field);
631 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
632 act->flags = flags | XkbSA_ISODfltIsGroup;
639 if (array_ndx != NULL)
640 return ReportActionNotArray(keymap, action->type, field);
641 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
642 return ReportMismatch(keymap, action->type, field,
643 "keyboard component");
644 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
647 return ReportIllegal(keymap, action->type, field);
651 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
652 unsigned field, ExprDef *array_ndx, ExprDef *value)
655 struct xkb_switch_screen_action *act;
657 act = (struct xkb_switch_screen_action *) action;
658 if (field == F_Screen) {
660 if (array_ndx != NULL)
661 return ReportActionNotArray(keymap, action->type, field);
662 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
663 act->flags &= ~XkbSA_SwitchAbsolute;
664 scrn = value->value.child;
667 act->flags |= XkbSA_SwitchAbsolute;
671 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
672 return ReportMismatch(keymap, action->type, field,
674 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
676 "Screen index must be in the range 1..255; "
677 "Illegal screen value %d ignored\n", rtrn.ival);
680 if (value->op == EXPR_NEGATE)
681 act->screen = -rtrn.ival;
683 act->screen = rtrn.ival;
686 else if (field == F_Same) {
690 return ReportActionNotArray(keymap, action->type, field);
692 if (!ExprResolveBoolean(keymap->ctx, value, &set))
693 return ReportMismatch(keymap, action->type, field, "boolean");
696 act->flags &= ~XkbSA_SwitchApplication;
698 act->flags |= XkbSA_SwitchApplication;
703 return ReportIllegal(keymap, action->type, field);
706 const LookupEntry ctrlNames[] = {
707 { "repeatkeys", XkbRepeatKeysMask },
708 { "repeat", XkbRepeatKeysMask },
709 { "autorepeat", XkbRepeatKeysMask },
710 { "slowkeys", XkbSlowKeysMask },
711 { "bouncekeys", XkbBounceKeysMask },
712 { "stickykeys", XkbStickyKeysMask },
713 { "mousekeys", XkbMouseKeysMask },
714 { "mousekeysaccel", XkbMouseKeysAccelMask },
715 { "accessxkeys", XkbAccessXKeysMask },
716 { "accessxtimeout", XkbAccessXTimeoutMask },
717 { "accessxfeedback", XkbAccessXFeedbackMask },
718 { "audiblebell", XkbAudibleBellMask },
719 { "ignoregrouplock", XkbIgnoreGroupLockMask },
720 { "all", XkbAllBooleanCtrlsMask },
728 HandleSetLockControls(struct xkb_keymap *keymap,
729 struct xkb_any_action *action,
730 unsigned field, ExprDef *array_ndx,
734 struct xkb_controls_action *act;
736 act = (struct xkb_controls_action *) action;
737 if (field == F_Controls) {
738 if (array_ndx != NULL)
739 return ReportActionNotArray(keymap, action->type, field);
740 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
741 return ReportMismatch(keymap, action->type, field,
743 act->ctrls = rtrn.uval;
746 return ReportIllegal(keymap, action->type, field);
749 static const LookupEntry evNames[] = {
750 { "press", XkbSA_MessageOnPress },
751 { "keypress", XkbSA_MessageOnPress },
752 { "release", XkbSA_MessageOnRelease },
753 { "keyrelease", XkbSA_MessageOnRelease },
754 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
760 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
761 unsigned field, ExprDef *array_ndx, ExprDef *value)
766 struct xkb_message_action *act;
768 act = (struct xkb_message_action *) action;
771 if (array_ndx != NULL)
772 return ReportActionNotArray(keymap, action->type, field);
773 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
774 return ReportMismatch(keymap, action->type, field,
776 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
778 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
783 return ReportActionNotArray(keymap, action->type, field);
785 if (!ExprResolveBoolean(keymap->ctx, value, &set))
786 return ReportMismatch(keymap, action->type, field, "boolean");
789 act->flags |= XkbSA_MessageGenKeyEvent;
791 act->flags &= ~XkbSA_MessageGenKeyEvent;
796 if (array_ndx == NULL) {
799 if (!ExprResolveString(keymap->ctx, value, &str))
800 return ReportMismatch(keymap, action->type, field, "string");
803 if (len < 1 || len > 6) {
804 log_warn(keymap->ctx,
805 "An action message can hold only 6 bytes; "
806 "Extra %d bytes ignored\n", len - 6);
809 strncpy((char *) act->message, str, 6);
814 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
816 "Array subscript must be integer; "
817 "Illegal subscript ignored\n");
823 "An action message is at most 6 bytes long; "
824 "Attempt to use data[%d] ignored\n", ndx);
827 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
828 return ReportMismatch(keymap, action->type, field, "integer");
829 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
831 "Message data must be in the range 0..255; "
832 "Illegal datum %d ignored\n", rtrn.ival);
835 act->message[ndx] = rtrn.uval;
839 return ReportIllegal(keymap, action->type, field);
843 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
844 unsigned field, ExprDef *array_ndx, ExprDef *value)
847 struct xkb_redirect_key_action *act;
851 char key_name[XkbKeyNameLength];
853 if (array_ndx != NULL)
854 return ReportActionNotArray(keymap, action->type, field);
856 act = (struct xkb_redirect_key_action *) action;
859 if (!ExprResolveKeyName(keymap->ctx, value, key_name))
860 return ReportMismatch(keymap, action->type, field, "key name");
862 tmp = KeyNameToLong(key_name);
863 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
865 return ReportNotFound(keymap, action->type, field, "Key",
866 KeyNameText(key_name));
867 act->new_kc = XkbKeyGetKeycode(keymap, key);
873 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
874 act->mods_mask |= (t2 & 0xff);
875 if (field == F_Modifiers)
876 act->mods |= (t2 & 0xff);
878 act->mods &= ~(t2 & 0xff);
880 t2 = (t2 >> 8) & 0xffff;
881 act->vmods_mask |= t2;
882 if (field == F_Modifiers)
890 return ReportIllegal(keymap, action->type, field);
894 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
895 unsigned field, ExprDef *array_ndx, ExprDef *value)
898 struct xkb_device_button_action *act;
900 act = (struct xkb_device_button_action *) action;
901 if (field == F_Button) {
902 if (array_ndx != NULL)
903 return ReportActionNotArray(keymap, action->type, field);
904 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
905 return ReportMismatch(keymap, action->type, field,
906 "integer (range 1..255)");
907 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
909 "Button must specify default or be in the range 1..255; "
910 "Illegal button value %d ignored\n", rtrn.ival);
913 act->button = rtrn.ival;
916 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
917 if (array_ndx != NULL)
918 return ReportActionNotArray(keymap, action->type, field);
919 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
920 return ReportMismatch(keymap, action->type, field,
922 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
923 act->flags |= rtrn.ival;
926 else if (field == F_Count) {
927 if (array_ndx != NULL)
928 return ReportActionNotArray(keymap, action->type, field);
929 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
930 return ReportMismatch(keymap, action->type, field, "integer");
931 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
933 "The count field must have a value in the range 0..255; "
934 "Illegal count %d ignored\n", rtrn.ival);
937 act->count = rtrn.ival;
940 else if (field == F_Device) {
941 if (array_ndx != NULL)
942 return ReportActionNotArray(keymap, action->type, field);
943 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
944 return ReportMismatch(keymap, action->type, field,
945 "integer (range 1..255)");
946 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
948 "Device must specify default or be in the range 1..255; "
949 "Illegal device value %d ignored\n", rtrn.ival);
952 act->device = rtrn.ival;
955 return ReportIllegal(keymap, action->type, field);
959 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
960 unsigned field, ExprDef *array_ndx, ExprDef *value)
964 struct xkb_device_valuator_action *act;
966 act = (struct xkb_device_valuator_action *) action;
967 /* XXX - Not yet implemented */
973 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
974 unsigned field, ExprDef *array_ndx, ExprDef *value)
980 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
981 return ReportMismatch(keymap, PrivateAction, field, "integer");
982 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
984 "Private action type must be in the range 0..255; "
985 "Illegal type %d ignored\n", rtrn.ival);
988 action->type = rtrn.uval;
992 if (array_ndx == NULL) {
996 if (!ExprResolveString(keymap->ctx, value, &str))
997 return ReportMismatch(keymap, action->type, field, "string");
1000 if (len < 1 || len > 7) {
1001 log_warn(keymap->ctx,
1002 "A private action has 7 data bytes; "
1003 "Extra %d bytes ignored\n", len - 6);
1007 strncpy((char *) action->data, str, sizeof(action->data));
1012 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
1013 log_err(keymap->ctx,
1014 "Array subscript must be integer; "
1015 "Illegal subscript ignored\n");
1019 if (ndx >= sizeof action->data) {
1020 log_err(keymap->ctx,
1021 "The data for a private action is 18 bytes long; "
1022 "Attempt to use data[%d] ignored\n", ndx);
1025 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1026 return ReportMismatch(keymap, action->type, field, "integer");
1027 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1028 log_err(keymap->ctx,
1029 "All data for a private action must be 0..255; "
1030 "Illegal datum %d ignored\n", rtrn.ival);
1033 action->data[ndx] = rtrn.uval;
1037 return ReportIllegal(keymap, PrivateAction, field);
1040 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1041 struct xkb_any_action *action, unsigned field,
1042 ExprDef *array_ndx, ExprDef *value);
1044 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1045 [XkbSA_NoAction] = HandleNoAction,
1046 [XkbSA_SetMods] = HandleSetLatchMods,
1047 [XkbSA_LatchMods] = HandleSetLatchMods,
1048 [XkbSA_LockMods] = HandleLockMods,
1049 [XkbSA_SetGroup] = HandleSetLatchGroup,
1050 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1051 [XkbSA_LockGroup] = HandleLockGroup,
1052 [XkbSA_MovePtr] = HandleMovePtr,
1053 [XkbSA_PtrBtn] = HandlePtrBtn,
1054 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1055 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1056 [XkbSA_ISOLock] = HandleISOLock,
1057 [XkbSA_Terminate] = HandleNoAction,
1058 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1059 [XkbSA_SetControls] = HandleSetLockControls,
1060 [XkbSA_LockControls] = HandleSetLockControls,
1061 [XkbSA_ActionMessage] = HandleActionMessage,
1062 [XkbSA_RedirectKey] = HandleRedirectKey,
1063 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1064 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1065 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1066 [PrivateAction] = HandlePrivate,
1069 /***====================================================================***/
1072 ApplyActionFactoryDefaults(union xkb_action * action)
1074 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1075 action->dflt.affect = XkbSA_AffectDfltBtn;
1076 action->dflt.flags = 0;
1077 action->dflt.value = 1;
1079 else if (action->type == XkbSA_ISOLock) {
1080 action->iso.real_mods = LockMask;
1085 ActionsInit(struct xkb_context *ctx);
1088 HandleActionDef(ExprDef * def,
1089 struct xkb_keymap *keymap,
1090 struct xkb_any_action *action, ActionInfo *info)
1094 unsigned tmp, hndlrType;
1096 if (!actionsInitialized)
1097 ActionsInit(keymap->ctx);
1099 if (def->op != EXPR_ACTION_DECL) {
1100 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1101 exprOpText(def->op));
1104 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1106 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1109 if (!stringToAction(str, &tmp)) {
1110 log_err(keymap->ctx, "Unknown action %s\n", str);
1113 action->type = hndlrType = tmp;
1114 if (action->type != XkbSA_NoAction) {
1115 ApplyActionFactoryDefaults((union xkb_action *) action);
1118 if ((info->action == XkbSA_NoAction)
1119 || (info->action == hndlrType)) {
1120 if (!(*handleAction[hndlrType])(keymap, action,
1130 for (arg = def->value.action.args; arg != NULL;
1131 arg = (ExprDef *) arg->common.next) {
1132 ExprDef *field, *value, *arrayRtrn;
1133 const char *elemRtrn, *fieldRtrn;
1136 if (arg->op == EXPR_ASSIGN) {
1137 field = arg->value.binary.left;
1138 value = arg->value.binary.right;
1141 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1142 field = arg->value.child;
1143 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1144 value = &constFalse;
1148 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1152 if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn,
1154 return false; /* internal error -- already reported */
1156 if (elemRtrn != NULL) {
1157 log_err(keymap->ctx,
1158 "Cannot change defaults in an action definition; "
1159 "Ignoring attempt to change %s.%s\n",
1160 elemRtrn, fieldRtrn);
1163 if (!stringToField(fieldRtrn, &fieldNdx)) {
1164 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn);
1167 if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn,
1174 /***====================================================================***/
1177 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1178 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1180 ActionInfo *new, *old;
1182 if (!actionsInitialized)
1183 ActionsInit(keymap->ctx);
1185 new = malloc(sizeof(*new));
1187 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1191 if (istreq(elem, "action"))
1192 new->action = XkbSA_NoAction;
1194 if (!stringToAction(elem, &new->action)) {
1198 if (new->action == XkbSA_NoAction) {
1199 log_err(keymap->ctx,
1200 "\"%s\" is not a valid field in a NoAction action\n",
1206 if (!stringToField(field, &new->field)) {
1207 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1211 new->array_ndx = array_ndx;
1215 while ((old) && (old->next))
1224 /***====================================================================***/
1227 ActionsInit(struct xkb_context *ctx)
1229 if (!actionsInitialized) {
1230 memset(&constTrue, 0, sizeof(constTrue));
1231 memset(&constFalse, 0, sizeof(constFalse));
1232 constTrue.common.type = STMT_EXPR;
1233 constTrue.common.next = NULL;
1234 constTrue.op = EXPR_IDENT;
1235 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1236 constTrue.value.str = xkb_atom_intern(ctx, "true");
1237 constFalse.common.type = STMT_EXPR;
1238 constFalse.common.next = NULL;
1239 constFalse.op = EXPR_IDENT;
1240 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1241 constFalse.value.str = xkb_atom_intern(ctx, "false");
1242 actionsInitialized = 1;
1247 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1250 size_t old_ndx, old_num_acts, new_ndx;
1253 key->acts_index = 0;
1257 if (XkbKeyHasActions(key) && key->width >= needed)
1258 return XkbKeyActionsPtr(keymap, key);
1261 * The key may already be in the array, but without enough space.
1262 * This should not happen often, so in order to avoid moving and
1263 * copying stuff from acts and key_acts, we just allocate new
1264 * space for the key at the end, and leave the old space alone.
1267 old_ndx = key->acts_index;
1268 old_num_acts = XkbKeyNumActions(key);
1269 new_ndx = darray_size(keymap->acts);
1271 darray_resize0(keymap->acts, new_ndx + needed);
1272 key->acts_index = new_ndx;
1275 * The key was already in the array, copy the old actions to the
1279 memcpy(darray_mem(keymap->acts, new_ndx),
1280 darray_mem(keymap->acts, old_ndx),
1281 old_num_acts * sizeof(union xkb_action));
1283 return XkbKeyActionsPtr(keymap, key);