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! */
232 if (!ExprResolveBoolean(keymap->ctx, value, &result))
233 return ReportMismatch(keymap, action, field, "boolean");
237 *flags_inout &= ~tmp;
242 CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
243 unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn)
246 if (value->op == EXPR_IDENT) {
248 valStr = xkb_atom_text(keymap->ctx, value->value.str);
249 if (valStr && (istreq(valStr, "usemodmapmods") ||
250 istreq(valStr, "modmapmods"))) {
253 *flags_inout |= XkbSA_UseModMapMods;
258 if (!ExprResolveVModMask(keymap, value, &rtrn))
259 return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
261 *mods_rtrn = (xkb_mod_mask_t) rtrn.ival;
262 *flags_inout &= ~XkbSA_UseModMapMods;
267 HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
268 unsigned field, ExprDef *array_ndx, ExprDef *value)
270 struct xkb_mod_action *act;
275 act = (struct xkb_mod_action *) action;
276 if (array_ndx != NULL) {
281 return ReportActionNotArray(keymap, action->type, field);
288 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
296 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
298 act->real_mods = act->mask = (t2 & 0xff);
299 act->vmods = (t2 >> 8) & 0xffff;
304 return ReportIllegal(keymap, action->type, field);
308 HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
309 unsigned field, ExprDef *array_ndx, ExprDef *value)
311 struct xkb_mod_action *act;
315 act = (struct xkb_mod_action *) action;
316 if ((array_ndx != NULL) && (field == F_Modifiers))
317 return ReportActionNotArray(keymap, action->type, field);
321 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
323 act->real_mods = act->mask = (t2 & 0xff);
324 act->vmods = (t2 >> 8) & 0xffff;
329 return ReportIllegal(keymap, action->type, field);
333 CheckGroupField(struct xkb_keymap *keymap, unsigned action,
334 ExprDef * value, unsigned *flags_inout,
335 xkb_group_index_t *grp_rtrn)
340 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
341 *flags_inout &= ~XkbSA_GroupAbsolute;
342 spec = value->value.child;
345 *flags_inout |= XkbSA_GroupAbsolute;
349 if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
350 return ReportMismatch(keymap, action, F_Group,
351 "integer (range 1..8)");
352 if (value->op == EXPR_NEGATE)
353 *grp_rtrn = -rtrn.ival;
354 else if (value->op == EXPR_UNARY_PLUS)
355 *grp_rtrn = rtrn.ival;
357 *grp_rtrn = rtrn.ival - 1;
362 HandleSetLatchGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
363 unsigned field, ExprDef *array_ndx, ExprDef *value)
365 struct xkb_group_action *act;
368 xkb_group_index_t t2;
370 act = (struct xkb_group_action *) action;
371 if (array_ndx != NULL) {
376 return ReportActionNotArray(keymap, action->type, field);
383 if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
391 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
398 return ReportIllegal(keymap, action->type, field);
402 HandleLockGroup(struct xkb_keymap *keymap, struct xkb_any_action *action,
403 unsigned field, ExprDef *array_ndx, ExprDef *value)
405 struct xkb_group_action *act;
407 xkb_group_index_t t2;
409 act = (struct xkb_group_action *) action;
410 if ((array_ndx != NULL) && (field == F_Group))
411 return ReportActionNotArray(keymap, action->type, field);
412 if (field == F_Group) {
414 if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
421 return ReportIllegal(keymap, action->type, field);
425 HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
426 unsigned field, ExprDef *array_ndx, ExprDef *value)
429 struct xkb_pointer_action *act;
432 act = (struct xkb_pointer_action *) action;
433 if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y)))
434 return ReportActionNotArray(keymap, action->type, field);
436 if ((field == F_X) || (field == F_Y)) {
437 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
441 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
442 return ReportMismatch(keymap, action->type, field, "integer");
445 act->flags |= XkbSA_MoveAbsoluteX;
450 act->flags |= XkbSA_MoveAbsoluteY;
455 else if (field == F_Accel) {
456 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
457 return ReportMismatch(keymap, action->type, field, "boolean");
459 act->flags &= ~XkbSA_NoAcceleration;
461 act->flags |= XkbSA_NoAcceleration;
463 return ReportIllegal(keymap, action->type, field);
466 static const LookupEntry lockWhich[] = {
468 { "lock", XkbSA_LockNoUnlock },
469 { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) },
470 { "unlock", XkbSA_LockNoLock },
475 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
476 unsigned field, ExprDef *array_ndx, ExprDef *value)
479 struct xkb_pointer_button_action *act;
481 act = (struct xkb_pointer_button_action *) action;
482 if (field == F_Button) {
483 if (array_ndx != NULL)
484 return ReportActionNotArray(keymap, action->type, field);
485 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
486 return ReportMismatch(keymap, action->type, field,
487 "integer (range 1..5)");
488 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
490 "Button must specify default or be in the range 1..5; "
491 "Illegal button value %d ignored\n", rtrn.ival);
494 act->button = rtrn.ival;
497 else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
498 if (array_ndx != NULL)
499 return ReportActionNotArray(keymap, action->type, field);
500 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
501 return ReportMismatch(keymap, action->type, field,
503 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
504 act->flags |= rtrn.ival;
507 else if (field == F_Count) {
508 if (array_ndx != NULL)
509 return ReportActionNotArray(keymap, action->type, field);
510 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
511 return ReportMismatch(keymap, action->type, field, "integer");
512 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
514 "The count field must have a value in the range 0..255; "
515 "Illegal count %d ignored\n", rtrn.ival);
518 act->count = rtrn.ival;
521 return ReportIllegal(keymap, action->type, field);
524 static const LookupEntry ptrDflts[] = {
525 { "dfltbtn", XkbSA_AffectDfltBtn },
526 { "defaultbutton", XkbSA_AffectDfltBtn },
527 { "button", XkbSA_AffectDfltBtn },
532 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
533 unsigned field, ExprDef *array_ndx, ExprDef *value)
536 struct xkb_pointer_default_action *act;
538 act = (struct xkb_pointer_default_action *) action;
539 if (field == F_Affect) {
540 if (array_ndx != NULL)
541 return ReportActionNotArray(keymap, action->type, field);
542 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, ptrDflts))
543 return ReportMismatch(keymap, action->type, field,
544 "pointer component");
545 act->affect = rtrn.uval;
548 else if ((field == F_Button) || (field == F_Value)) {
550 if (array_ndx != NULL)
551 return ReportActionNotArray(keymap, action->type, field);
552 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
553 act->flags &= ~XkbSA_DfltBtnAbsolute;
554 btn = value->value.child;
557 act->flags |= XkbSA_DfltBtnAbsolute;
561 if (!ExprResolveButton(keymap->ctx, btn, &rtrn))
562 return ReportMismatch(keymap, action->type, field,
563 "integer (range 1..5)");
564 if ((rtrn.ival < 0) || (rtrn.ival > 5)) {
566 "New default button value must be in the range 1..5; "
567 "Illegal default button value %d ignored\n", rtrn.ival);
570 if (rtrn.ival == 0) {
572 "Cannot set default pointer button to \"default\"; "
573 "Illegal default button setting ignored\n");
577 act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival);
580 return ReportIllegal(keymap, action->type, field);
583 static const LookupEntry isoNames[] = {
584 { "mods", XkbSA_ISONoAffectMods },
585 { "modifiers", XkbSA_ISONoAffectMods },
586 { "group", XkbSA_ISONoAffectGroup },
587 { "groups", XkbSA_ISONoAffectGroup },
588 { "ptr", XkbSA_ISONoAffectPtr },
589 { "pointer", XkbSA_ISONoAffectPtr },
590 { "ctrls", XkbSA_ISONoAffectCtrls },
591 { "controls", XkbSA_ISONoAffectCtrls },
592 { "all", ~((unsigned) 0) },
598 HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
599 unsigned field, ExprDef *array_ndx, ExprDef *value)
602 struct xkb_iso_action *act;
605 xkb_group_index_t group;
607 act = (struct xkb_iso_action *) action;
610 if (array_ndx != NULL)
611 return ReportActionNotArray(keymap, action->type, field);
613 if (CheckModifierField(keymap, action->type, value, &flags, &mods)) {
614 act->flags = flags & (~XkbSA_ISODfltIsGroup);
615 act->real_mods = mods & 0xff;
616 act->vmods = (mods >> 8) & 0xff;
622 if (array_ndx != NULL)
623 return ReportActionNotArray(keymap, action->type, field);
625 if (CheckGroupField(keymap, action->type, value, &flags, &group)) {
626 act->flags = flags | XkbSA_ISODfltIsGroup;
633 if (array_ndx != NULL)
634 return ReportActionNotArray(keymap, action->type, field);
635 if (!ExprResolveMask(keymap->ctx, value, &rtrn, isoNames))
636 return ReportMismatch(keymap, action->type, field,
637 "keyboard component");
638 act->affect = (~rtrn.uval) & XkbSA_ISOAffectMask;
641 return ReportIllegal(keymap, action->type, field);
645 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
646 unsigned field, ExprDef *array_ndx, ExprDef *value)
649 struct xkb_switch_screen_action *act;
651 act = (struct xkb_switch_screen_action *) action;
652 if (field == F_Screen) {
654 if (array_ndx != NULL)
655 return ReportActionNotArray(keymap, action->type, field);
656 if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
657 act->flags &= ~XkbSA_SwitchAbsolute;
658 scrn = value->value.child;
661 act->flags |= XkbSA_SwitchAbsolute;
665 if (!ExprResolveInteger(keymap->ctx, scrn, &rtrn))
666 return ReportMismatch(keymap, action->type, field,
668 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
670 "Screen index must be in the range 1..255; "
671 "Illegal screen value %d ignored\n", rtrn.ival);
674 if (value->op == EXPR_NEGATE)
675 act->screen = -rtrn.ival;
677 act->screen = rtrn.ival;
680 else if (field == F_Same) {
681 if (array_ndx != NULL)
682 return ReportActionNotArray(keymap, action->type, field);
683 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
684 return ReportMismatch(keymap, action->type, field, "boolean");
686 act->flags &= ~XkbSA_SwitchApplication;
688 act->flags |= XkbSA_SwitchApplication;
691 return ReportIllegal(keymap, action->type, field);
694 const LookupEntry ctrlNames[] = {
695 { "repeatkeys", XkbRepeatKeysMask },
696 { "repeat", XkbRepeatKeysMask },
697 { "autorepeat", XkbRepeatKeysMask },
698 { "slowkeys", XkbSlowKeysMask },
699 { "bouncekeys", XkbBounceKeysMask },
700 { "stickykeys", XkbStickyKeysMask },
701 { "mousekeys", XkbMouseKeysMask },
702 { "mousekeysaccel", XkbMouseKeysAccelMask },
703 { "accessxkeys", XkbAccessXKeysMask },
704 { "accessxtimeout", XkbAccessXTimeoutMask },
705 { "accessxfeedback", XkbAccessXFeedbackMask },
706 { "audiblebell", XkbAudibleBellMask },
707 { "ignoregrouplock", XkbIgnoreGroupLockMask },
708 { "all", XkbAllBooleanCtrlsMask },
716 HandleSetLockControls(struct xkb_keymap *keymap,
717 struct xkb_any_action *action,
718 unsigned field, ExprDef *array_ndx,
722 struct xkb_controls_action *act;
724 act = (struct xkb_controls_action *) action;
725 if (field == F_Controls) {
726 if (array_ndx != NULL)
727 return ReportActionNotArray(keymap, action->type, field);
728 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
729 return ReportMismatch(keymap, action->type, field,
731 act->ctrls = rtrn.uval;
734 return ReportIllegal(keymap, action->type, field);
737 static const LookupEntry evNames[] = {
738 { "press", XkbSA_MessageOnPress },
739 { "keypress", XkbSA_MessageOnPress },
740 { "release", XkbSA_MessageOnRelease },
741 { "keyrelease", XkbSA_MessageOnRelease },
742 { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease },
748 HandleActionMessage(struct xkb_keymap *keymap, struct xkb_any_action *action,
749 unsigned field, ExprDef *array_ndx, ExprDef *value)
752 struct xkb_message_action *act;
754 act = (struct xkb_message_action *) action;
757 if (array_ndx != NULL)
758 return ReportActionNotArray(keymap, action->type, field);
759 if (!ExprResolveMask(keymap->ctx, value, &rtrn, evNames))
760 return ReportMismatch(keymap, action->type, field,
762 act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
764 rtrn.uval & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
768 if (array_ndx != NULL)
769 return ReportActionNotArray(keymap, action->type, field);
770 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
771 return ReportMismatch(keymap, action->type, field, "boolean");
773 act->flags |= XkbSA_MessageGenKeyEvent;
775 act->flags &= ~XkbSA_MessageGenKeyEvent;
779 if (array_ndx == NULL) {
780 if (!ExprResolveString(keymap->ctx, value, &rtrn))
781 return ReportMismatch(keymap, action->type, field, "string");
783 int len = strlen(rtrn.str);
784 if ((len < 1) || (len > 6)) {
785 log_warn(keymap->ctx,
786 "An action message can hold only 6 bytes; "
787 "Extra %d bytes ignored\n", len - 6);
789 strncpy((char *) act->message, rtrn.str, 6);
795 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
797 "Array subscript must be integer; "
798 "Illegal subscript ignored\n");
804 "An action message is at most 6 bytes long; "
805 "Attempt to use data[%d] ignored\n", ndx);
808 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
809 return ReportMismatch(keymap, action->type, field, "integer");
810 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
812 "Message data must be in the range 0..255; "
813 "Illegal datum %d ignored\n", rtrn.ival);
816 act->message[ndx] = rtrn.uval;
820 return ReportIllegal(keymap, action->type, field);
824 HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
825 unsigned field, ExprDef *array_ndx, ExprDef *value)
829 struct xkb_redirect_key_action *act;
834 if (array_ndx != NULL)
835 return ReportActionNotArray(keymap, action->type, field);
837 act = (struct xkb_redirect_key_action *) action;
840 if (!ExprResolveKeyName(keymap->ctx, value, &rtrn))
841 return ReportMismatch(keymap, action->type, field, "key name");
843 tmp = KeyNameToLong(rtrn.name);
844 key = FindNamedKey(keymap, tmp, true, CreateKeyNames(keymap), 0);
846 return ReportNotFound(keymap, action->type, field, "Key",
847 KeyNameText(rtrn.name));
848 act->new_kc = XkbKeyGetKeycode(keymap, key);
854 if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
855 act->mods_mask |= (t2 & 0xff);
856 if (field == F_Modifiers)
857 act->mods |= (t2 & 0xff);
859 act->mods &= ~(t2 & 0xff);
861 t2 = (t2 >> 8) & 0xffff;
862 act->vmods_mask |= t2;
863 if (field == F_Modifiers)
871 return ReportIllegal(keymap, action->type, field);
875 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
876 unsigned field, ExprDef *array_ndx, ExprDef *value)
879 struct xkb_device_button_action *act;
881 act = (struct xkb_device_button_action *) action;
882 if (field == F_Button) {
883 if (array_ndx != NULL)
884 return ReportActionNotArray(keymap, action->type, field);
885 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
886 return ReportMismatch(keymap, action->type, field,
887 "integer (range 1..255)");
888 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
890 "Button must specify default or be in the range 1..255; "
891 "Illegal button value %d ignored\n", rtrn.ival);
894 act->button = rtrn.ival;
897 else if ((action->type == XkbSA_LockDeviceBtn) && (field == F_Affect)) {
898 if (array_ndx != NULL)
899 return ReportActionNotArray(keymap, action->type, field);
900 if (!ExprResolveEnum(keymap->ctx, value, &rtrn, lockWhich))
901 return ReportMismatch(keymap, action->type, field,
903 act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock);
904 act->flags |= rtrn.ival;
907 else if (field == F_Count) {
908 if (array_ndx != NULL)
909 return ReportActionNotArray(keymap, action->type, field);
910 if (!ExprResolveButton(keymap->ctx, value, &rtrn))
911 return ReportMismatch(keymap, action->type, field, "integer");
912 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
914 "The count field must have a value in the range 0..255; "
915 "Illegal count %d ignored\n", rtrn.ival);
918 act->count = rtrn.ival;
921 else if (field == F_Device) {
922 if (array_ndx != NULL)
923 return ReportActionNotArray(keymap, action->type, field);
924 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
925 return ReportMismatch(keymap, action->type, field,
926 "integer (range 1..255)");
927 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
929 "Device must specify default or be in the range 1..255; "
930 "Illegal device value %d ignored\n", rtrn.ival);
933 act->device = rtrn.ival;
936 return ReportIllegal(keymap, action->type, field);
940 HandleDeviceValuator(struct xkb_keymap *keymap, struct xkb_any_action *action,
941 unsigned field, ExprDef *array_ndx, ExprDef *value)
945 struct xkb_device_valuator_action *act;
947 act = (struct xkb_device_valuator_action *) action;
948 /* XXX - Not yet implemented */
954 HandlePrivate(struct xkb_keymap *keymap, struct xkb_any_action *action,
955 unsigned field, ExprDef *array_ndx, ExprDef *value)
961 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
962 return ReportMismatch(keymap, PrivateAction, field, "integer");
963 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
965 "Private action type must be in the range 0..255; "
966 "Illegal type %d ignored\n", rtrn.ival);
969 action->type = rtrn.uval;
973 if (array_ndx == NULL) {
974 if (!ExprResolveString(keymap->ctx, value, &rtrn))
975 return ReportMismatch(keymap, action->type, field, "string");
977 int len = strlen(rtrn.str);
978 if ((len < 1) || (len > 7)) {
979 log_warn(keymap->ctx,
980 "A private action has 7 data bytes; "
981 "Extra %d bytes ignored\n", len - 6);
984 strncpy((char *) action->data, rtrn.str, sizeof action->data);
990 if (!ExprResolveInteger(keymap->ctx, array_ndx, &rtrn)) {
992 "Array subscript must be integer; "
993 "Illegal subscript ignored\n");
997 if (ndx >= sizeof action->data) {
999 "The data for a private action is 18 bytes long; "
1000 "Attempt to use data[%d] ignored\n", ndx);
1003 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
1004 return ReportMismatch(keymap, action->type, field, "integer");
1005 if ((rtrn.ival < 0) || (rtrn.ival > 255)) {
1006 log_err(keymap->ctx,
1007 "All data for a private action must be 0..255; "
1008 "Illegal datum %d ignored\n", rtrn.ival);
1011 action->data[ndx] = rtrn.uval;
1015 return ReportIllegal(keymap, PrivateAction, field);
1018 typedef bool (*actionHandler)(struct xkb_keymap *keymap,
1019 struct xkb_any_action *action, unsigned field,
1020 ExprDef *array_ndx, ExprDef *value);
1022 static const actionHandler handleAction[XkbSA_NumActions + 1] = {
1023 [XkbSA_NoAction] = HandleNoAction,
1024 [XkbSA_SetMods] = HandleSetLatchMods,
1025 [XkbSA_LatchMods] = HandleSetLatchMods,
1026 [XkbSA_LockMods] = HandleLockMods,
1027 [XkbSA_SetGroup] = HandleSetLatchGroup,
1028 [XkbSA_LatchGroup] = HandleSetLatchGroup,
1029 [XkbSA_LockGroup] = HandleLockGroup,
1030 [XkbSA_MovePtr] = HandleMovePtr,
1031 [XkbSA_PtrBtn] = HandlePtrBtn,
1032 [XkbSA_LockPtrBtn] = HandlePtrBtn,
1033 [XkbSA_SetPtrDflt] = HandleSetPtrDflt,
1034 [XkbSA_ISOLock] = HandleISOLock,
1035 [XkbSA_Terminate] = HandleNoAction,
1036 [XkbSA_SwitchScreen] = HandleSwitchScreen,
1037 [XkbSA_SetControls] = HandleSetLockControls,
1038 [XkbSA_LockControls] = HandleSetLockControls,
1039 [XkbSA_ActionMessage] = HandleActionMessage,
1040 [XkbSA_RedirectKey] = HandleRedirectKey,
1041 [XkbSA_DeviceBtn] = HandleDeviceBtn,
1042 [XkbSA_LockDeviceBtn] = HandleDeviceBtn,
1043 [XkbSA_DeviceValuator] = HandleDeviceValuator,
1044 [PrivateAction] = HandlePrivate,
1047 /***====================================================================***/
1050 ApplyActionFactoryDefaults(union xkb_action * action)
1052 if (action->type == XkbSA_SetPtrDflt) { /* increment default button */
1053 action->dflt.affect = XkbSA_AffectDfltBtn;
1054 action->dflt.flags = 0;
1055 action->dflt.value = 1;
1057 else if (action->type == XkbSA_ISOLock) {
1058 action->iso.real_mods = LockMask;
1063 ActionsInit(struct xkb_context *ctx);
1066 HandleActionDef(ExprDef * def,
1067 struct xkb_keymap *keymap,
1068 struct xkb_any_action *action, ActionInfo *info)
1072 unsigned tmp, hndlrType;
1074 if (!actionsInitialized)
1075 ActionsInit(keymap->ctx);
1077 if (def->op != EXPR_ACTION_DECL) {
1078 log_err(keymap->ctx, "Expected an action definition, found %s\n",
1079 exprOpText(def->op));
1082 str = xkb_atom_text(keymap->ctx, def->value.action.name);
1084 log_wsgo(keymap->ctx, "Missing name in action definition!!\n");
1087 if (!stringToAction(str, &tmp)) {
1088 log_err(keymap->ctx, "Unknown action %s\n", str);
1091 action->type = hndlrType = tmp;
1092 if (action->type != XkbSA_NoAction) {
1093 ApplyActionFactoryDefaults((union xkb_action *) action);
1096 if ((info->action == XkbSA_NoAction)
1097 || (info->action == hndlrType)) {
1098 if (!(*handleAction[hndlrType])(keymap, action,
1108 for (arg = def->value.action.args; arg != NULL;
1109 arg = (ExprDef *) arg->common.next) {
1110 ExprDef *field, *value, *arrayRtrn;
1111 ExprResult elemRtrn, fieldRtrn;
1114 if (arg->op == EXPR_ASSIGN) {
1115 field = arg->value.binary.left;
1116 value = arg->value.binary.right;
1119 if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
1120 field = arg->value.child;
1121 constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
1122 value = &constFalse;
1126 constTrue.value.str = xkb_atom_intern(keymap->ctx, "true");
1130 if (!ExprResolveLhs(keymap, field, &elemRtrn, &fieldRtrn, &arrayRtrn))
1131 return false; /* internal error -- already reported */
1133 if (elemRtrn.str != NULL) {
1134 log_err(keymap->ctx,
1135 "Cannot change defaults in an action definition; "
1136 "Ignoring attempt to change %s.%s\n",
1137 elemRtrn.str, fieldRtrn.str);
1140 if (!stringToField(fieldRtrn.str, &fieldNdx)) {
1141 log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn.str);
1144 if (!(*handleAction[hndlrType])(keymap, action, fieldNdx, arrayRtrn,
1151 /***====================================================================***/
1154 SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field,
1155 ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn)
1157 ActionInfo *new, *old;
1159 if (!actionsInitialized)
1160 ActionsInit(keymap->ctx);
1162 new = malloc(sizeof(*new));
1164 log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n");
1168 if (istreq(elem, "action"))
1169 new->action = XkbSA_NoAction;
1171 if (!stringToAction(elem, &new->action)) {
1175 if (new->action == XkbSA_NoAction) {
1176 log_err(keymap->ctx,
1177 "\"%s\" is not a valid field in a NoAction action\n",
1183 if (!stringToField(field, &new->field)) {
1184 log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field);
1188 new->array_ndx = array_ndx;
1192 while ((old) && (old->next))
1201 /***====================================================================***/
1204 ActionsInit(struct xkb_context *ctx)
1206 if (!actionsInitialized) {
1207 memset(&constTrue, 0, sizeof(constTrue));
1208 memset(&constFalse, 0, sizeof(constFalse));
1209 constTrue.common.type = STMT_EXPR;
1210 constTrue.common.next = NULL;
1211 constTrue.op = EXPR_IDENT;
1212 constTrue.value_type = EXPR_TYPE_BOOLEAN;
1213 constTrue.value.str = xkb_atom_intern(ctx, "true");
1214 constFalse.common.type = STMT_EXPR;
1215 constFalse.common.next = NULL;
1216 constFalse.op = EXPR_IDENT;
1217 constFalse.value_type = EXPR_TYPE_BOOLEAN;
1218 constFalse.value.str = xkb_atom_intern(ctx, "false");
1219 actionsInitialized = 1;
1224 ResizeKeyActions(struct xkb_keymap *keymap, struct xkb_key *key,
1227 size_t old_ndx, old_num_acts, new_ndx;
1230 key->acts_index = 0;
1234 if (XkbKeyHasActions(key) && key->width >= needed)
1235 return XkbKeyActionsPtr(keymap, key);
1238 * The key may already be in the array, but without enough space.
1239 * This should not happen often, so in order to avoid moving and
1240 * copying stuff from acts and key_acts, we just allocate new
1241 * space for the key at the end, and leave the old space alone.
1244 old_ndx = key->acts_index;
1245 old_num_acts = XkbKeyNumActions(key);
1246 new_ndx = darray_size(keymap->acts);
1248 darray_resize0(keymap->acts, new_ndx + needed);
1249 key->acts_index = new_ndx;
1252 * The key was already in the array, copy the old actions to the
1256 memcpy(darray_mem(keymap->acts, new_ndx),
1257 darray_mem(keymap->acts, old_ndx),
1258 old_num_acts * sizeof(union xkb_action));
1260 return XkbKeyActionsPtr(keymap, key);