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 ********************************************************/
27 #ifdef HAVE_DIX_CONFIG_H
28 #include <dix-config.h>
38 #include <X11/Xproto.h>
39 #include <X11/extensions/XKMformat.h>
44 #define XKBSRV_NEED_FILE_FUNCS 1
48 /***====================================================================***/
50 #define BUFFER_SIZE 512
52 static char textBuffer
[BUFFER_SIZE
];
53 static int tbNext
= 0;
56 tbGetBuffer(unsigned size
)
60 if (size
>= BUFFER_SIZE
)
62 if ((BUFFER_SIZE
- tbNext
) <= size
)
64 rtrn
= &textBuffer
[tbNext
];
69 /***====================================================================***/
72 XkbAtomText(Atom atm
, unsigned format
)
77 atmstr
= NameForAtom(atm
);
81 len
= strlen(atmstr
) + 1;
82 if (len
> BUFFER_SIZE
)
83 len
= BUFFER_SIZE
- 2;
84 rtrn
= tbGetBuffer(len
);
85 strlcpy(rtrn
, atmstr
, len
);
88 rtrn
= tbGetBuffer(1);
91 if (format
== XkbCFile
) {
92 for (tmp
= rtrn
; *tmp
!= '\0'; tmp
++) {
93 if ((tmp
== rtrn
) && (!isalpha(*tmp
)))
95 else if (!isalnum(*tmp
))
99 return XkbStringText(rtrn
, format
);
102 /***====================================================================***/
105 XkbVModIndexText(XkbDescPtr xkb
, unsigned ndx
, unsigned format
)
108 register Atom
*vmodNames
;
113 if (xkb
&& xkb
->names
)
114 vmodNames
= xkb
->names
->vmods
;
119 if (ndx
>= XkbNumVirtualMods
)
121 else if (vmodNames
&& (vmodNames
[ndx
] != None
))
122 tmp
= NameForAtom(vmodNames
[ndx
]);
124 snprintf(numBuf
, sizeof(numBuf
), "%d", ndx
);
128 len
= strlen(tmp
) + 1;
129 if (format
== XkbCFile
)
131 if (len
>= BUFFER_SIZE
)
132 len
= BUFFER_SIZE
- 1;
133 rtrn
= tbGetBuffer(len
);
134 if (format
== XkbCFile
) {
135 strcpy(rtrn
, "vmod_");
136 strncpy(&rtrn
[5], tmp
, len
- 4);
139 strncpy(rtrn
, tmp
, len
);
144 XkbVModMaskText(XkbDescPtr xkb
,
145 unsigned modMask
, unsigned mask
, unsigned format
)
150 char *str
, buf
[BUFFER_SIZE
];
152 if ((modMask
== 0) && (mask
== 0)) {
153 rtrn
= tbGetBuffer(5);
154 if (format
== XkbCFile
)
157 sprintf(rtrn
, "none");
161 mm
= XkbModMaskText(modMask
, format
);
170 for (i
= 0, bit
= 1; i
< XkbNumVirtualMods
; i
++, bit
<<= 1) {
172 tmp
= XkbVModIndexText(xkb
, i
, format
);
173 len
= strlen(tmp
) + 1 + (str
== buf
? 0 : 1);
174 if (format
== XkbCFile
)
176 if ((str
- (buf
+ len
)) <= BUFFER_SIZE
) {
178 if (format
== XkbCFile
)
185 if (format
== XkbCFile
)
186 sprintf(str
, "%sMask", tmp
);
201 len
+= strlen(str
) + (mm
== NULL
? 0 : 1);
202 if (len
>= BUFFER_SIZE
)
203 len
= BUFFER_SIZE
- 1;
204 rtrn
= tbGetBuffer(len
+ 1);
218 if (format
== XkbCFile
)
223 strncat(rtrn
, str
, len
- i
);
229 static const char *modNames
[XkbNumModifiers
] = {
230 "Shift", "Lock", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5"
234 XkbModIndexText(unsigned ndx
, unsigned format
)
239 if (format
== XkbCFile
) {
240 if (ndx
< XkbNumModifiers
)
241 snprintf(buf
, sizeof(buf
), "%sMapIndex", modNames
[ndx
]);
242 else if (ndx
== XkbNoModifier
)
243 snprintf(buf
, sizeof(buf
), "XkbNoModifier");
245 snprintf(buf
, sizeof(buf
), "0x%02x", ndx
);
248 if (ndx
< XkbNumModifiers
)
249 strcpy(buf
, modNames
[ndx
]);
250 else if (ndx
== XkbNoModifier
)
253 snprintf(buf
, sizeof(buf
), "ILLEGAL_%02x", ndx
);
255 rtrn
= tbGetBuffer(strlen(buf
) + 1);
261 XkbModMaskText(unsigned mask
, unsigned format
)
266 if ((mask
& 0xff) == 0xff) {
267 if (format
== XkbCFile
)
272 else if ((mask
& 0xff) == 0) {
273 if (format
== XkbCFile
)
282 for (i
= 0, bit
= 1; i
< XkbNumModifiers
; i
++, bit
<<= 1) {
285 if (format
== XkbCFile
)
290 strcpy(str
, modNames
[i
]);
291 str
= &str
[strlen(str
)];
292 if (format
== XkbCFile
) {
299 rtrn
= tbGetBuffer(strlen(buf
) + 1);
304 /***====================================================================***/
307 XkbConfigText(unsigned config
, unsigned format
)
311 buf
= tbGetBuffer(32);
313 case XkmSemanticsFile
:
314 strcpy(buf
, "Semantics");
317 strcpy(buf
, "Layout");
320 strcpy(buf
, "Keymap");
322 case XkmGeometryFile
:
323 case XkmGeometryIndex
:
324 strcpy(buf
, "Geometry");
327 strcpy(buf
, "Types");
329 case XkmCompatMapIndex
:
330 strcpy(buf
, "CompatMap");
332 case XkmSymbolsIndex
:
333 strcpy(buf
, "Symbols");
335 case XkmIndicatorsIndex
:
336 strcpy(buf
, "Indicators");
338 case XkmKeyNamesIndex
:
339 strcpy(buf
, "KeyNames");
341 case XkmVirtualModsIndex
:
342 strcpy(buf
, "VirtualMods");
345 sprintf(buf
, "unknown(%d)", config
);
351 /***====================================================================***/
354 XkbKeysymText(KeySym sym
, unsigned format
)
359 strcpy(buf
, "NoSymbol");
361 snprintf(buf
, sizeof(buf
), "0x%lx", (long) sym
);
366 XkbKeyNameText(char *name
, unsigned format
)
370 if (format
== XkbCFile
) {
371 buf
= tbGetBuffer(5);
372 memcpy(buf
, name
, 4);
378 buf
= tbGetBuffer(7);
380 memcpy(&buf
[1], name
, 4);
389 /***====================================================================***/
391 static const char *siMatchText
[5] = {
392 "NoneOf", "AnyOfOrNone", "AnyOf", "AllOf", "Exactly"
396 XkbSIMatchText(unsigned type
, unsigned format
)
401 switch (type
& XkbSI_OpMask
) {
403 rtrn
= siMatchText
[0];
405 case XkbSI_AnyOfOrNone
:
406 rtrn
= siMatchText
[1];
409 rtrn
= siMatchText
[2];
412 rtrn
= siMatchText
[3];
415 rtrn
= siMatchText
[4];
418 snprintf(buf
, sizeof(buf
), "0x%x", type
& XkbSI_OpMask
);
421 if (format
== XkbCFile
) {
422 if (type
& XkbSI_LevelOneOnly
)
423 snprintf(buf
, sizeof(buf
), "XkbSI_LevelOneOnly|XkbSI_%s", rtrn
);
425 snprintf(buf
, sizeof(buf
), "XkbSI_%s", rtrn
);
431 /***====================================================================***/
433 static const char *imWhichNames
[] = {
442 XkbIMWhichStateMaskText(unsigned use_which
, unsigned format
)
445 unsigned i
, bit
, tmp
;
448 if (use_which
== 0) {
449 buf
= tbGetBuffer(2);
453 tmp
= use_which
& XkbIM_UseAnyMods
;
454 for (len
= i
= 0, bit
= 1; tmp
!= 0; i
++, bit
<<= 1) {
457 len
+= strlen(imWhichNames
[i
]) + 1;
458 if (format
== XkbCFile
)
462 buf
= tbGetBuffer(len
+ 1);
463 tmp
= use_which
& XkbIM_UseAnyMods
;
464 for (len
= i
= 0, bit
= 1; tmp
!= 0; i
++, bit
<<= 1) {
467 if (format
== XkbCFile
) {
470 sprintf(&buf
[len
], "XkbIM_Use%s", imWhichNames
[i
]);
471 buf
[len
+ 9] = toupper(buf
[len
+ 9]);
476 sprintf(&buf
[len
], "%s", imWhichNames
[i
]);
478 len
+= strlen(&buf
[len
]);
484 static const char *ctrlNames
[] = {
501 XkbControlsMaskText(unsigned ctrls
, unsigned format
)
504 unsigned i
, bit
, tmp
;
508 buf
= tbGetBuffer(5);
509 if (format
== XkbCFile
)
515 tmp
= ctrls
& XkbAllBooleanCtrlsMask
;
516 for (len
= i
= 0, bit
= 1; tmp
!= 0; i
++, bit
<<= 1) {
519 len
+= strlen(ctrlNames
[i
]) + 1;
520 if (format
== XkbCFile
)
524 buf
= tbGetBuffer(len
+ 1);
525 tmp
= ctrls
& XkbAllBooleanCtrlsMask
;
526 for (len
= i
= 0, bit
= 1; tmp
!= 0; i
++, bit
<<= 1) {
529 if (format
== XkbCFile
) {
532 sprintf(&buf
[len
], "Xkb%sMask", ctrlNames
[i
]);
533 buf
[len
+ 3] = toupper(buf
[len
+ 3]);
538 sprintf(&buf
[len
], "%s", ctrlNames
[i
]);
540 len
+= strlen(&buf
[len
]);
546 /***====================================================================***/
549 XkbStringText(char *str
, unsigned format
)
552 register char *in
, *out
;
557 buf
= tbGetBuffer(2);
561 else if (format
== XkbXKMFile
)
563 for (ok
= TRUE
, len
= 0, in
= str
; *in
!= '\0'; in
++, len
++) {
583 buf
= tbGetBuffer(len
+ 1);
584 for (in
= str
, out
= buf
; *in
!= '\0'; in
++) {
591 else if (*in
== '\t')
593 else if (*in
== '\v')
595 else if (*in
== '\b')
597 else if (*in
== '\r')
599 else if (*in
== '\f')
601 else if ((*in
== '\033') && (format
== XkbXKMFile
)) {
606 sprintf(out
, "%o", *in
);
616 /***====================================================================***/
619 XkbGeomFPText(int val
, unsigned format
)
624 buf
= tbGetBuffer(12);
625 if (format
== XkbCFile
) {
626 sprintf(buf
, "%d", val
);
629 whole
= val
/ XkbGeomPtsPerMM
;
630 frac
= val
% XkbGeomPtsPerMM
;
632 sprintf(buf
, "%d.%d", whole
, frac
);
634 sprintf(buf
, "%d", whole
);
640 XkbDoodadTypeText(unsigned type
, unsigned format
)
644 if (format
== XkbCFile
) {
645 buf
= tbGetBuffer(24);
646 if (type
== XkbOutlineDoodad
)
647 strcpy(buf
, "XkbOutlineDoodad");
648 else if (type
== XkbSolidDoodad
)
649 strcpy(buf
, "XkbSolidDoodad");
650 else if (type
== XkbTextDoodad
)
651 strcpy(buf
, "XkbTextDoodad");
652 else if (type
== XkbIndicatorDoodad
)
653 strcpy(buf
, "XkbIndicatorDoodad");
654 else if (type
== XkbLogoDoodad
)
655 strcpy(buf
, "XkbLogoDoodad");
657 sprintf(buf
, "UnknownDoodad%d", type
);
660 buf
= tbGetBuffer(12);
661 if (type
== XkbOutlineDoodad
)
662 strcpy(buf
, "outline");
663 else if (type
== XkbSolidDoodad
)
664 strcpy(buf
, "solid");
665 else if (type
== XkbTextDoodad
)
667 else if (type
== XkbIndicatorDoodad
)
668 strcpy(buf
, "indicator");
669 else if (type
== XkbLogoDoodad
)
672 sprintf(buf
, "unknown%d", type
);
677 static const char *actionTypeNames
[XkbSA_NumActions
] = {
679 "SetMods", "LatchMods", "LockMods",
680 "SetGroup", "LatchGroup", "LockGroup",
682 "PtrBtn", "LockPtrBtn",
685 "Terminate", "SwitchScreen",
686 "SetControls", "LockControls",
689 "DeviceBtn", "LockDeviceBtn"
693 XkbActionTypeText(unsigned type
, unsigned format
)
698 if (type
<= XkbSA_LastAction
) {
699 rtrn
= actionTypeNames
[type
];
700 if (format
== XkbCFile
) {
701 snprintf(buf
, sizeof(buf
), "XkbSA_%s", rtrn
);
706 snprintf(buf
, sizeof(buf
), "Private");
710 /***====================================================================***/
713 TryCopyStr(char *to
, const char *from
, int *pLeft
)
719 if (len
< ((*pLeft
) - 3)) {
729 /*ARGSUSED*/ static Bool
730 CopyNoActionArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
736 CopyModActionArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
742 tmp
= XkbModActionVMods(act
);
743 TryCopyStr(buf
, "modifiers=", sz
);
744 if (act
->flags
& XkbSA_UseModMapMods
)
745 TryCopyStr(buf
, "modMapMods", sz
);
746 else if (act
->real_mods
|| tmp
) {
748 XkbVModMaskText(xkb
, act
->real_mods
, tmp
, XkbXKBFile
), sz
);
751 TryCopyStr(buf
, "none", sz
);
752 if (act
->type
== XkbSA_LockMods
)
754 if (act
->flags
& XkbSA_ClearLocks
)
755 TryCopyStr(buf
, ",clearLocks", sz
);
756 if (act
->flags
& XkbSA_LatchToLock
)
757 TryCopyStr(buf
, ",latchToLock", sz
);
761 /*ARGSUSED*/ static Bool
762 CopyGroupActionArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
767 act
= &action
->group
;
768 TryCopyStr(buf
, "group=", sz
);
769 if (act
->flags
& XkbSA_GroupAbsolute
)
770 snprintf(tbuf
, sizeof(tbuf
), "%d", XkbSAGroup(act
) + 1);
771 else if (XkbSAGroup(act
) < 0)
772 snprintf(tbuf
, sizeof(tbuf
), "%d", XkbSAGroup(act
));
774 snprintf(tbuf
, sizeof(tbuf
), "+%d", XkbSAGroup(act
));
775 TryCopyStr(buf
, tbuf
, sz
);
776 if (act
->type
== XkbSA_LockGroup
)
778 if (act
->flags
& XkbSA_ClearLocks
)
779 TryCopyStr(buf
, ",clearLocks", sz
);
780 if (act
->flags
& XkbSA_LatchToLock
)
781 TryCopyStr(buf
, ",latchToLock", sz
);
785 /*ARGSUSED*/ static Bool
786 CopyMovePtrArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
793 x
= XkbPtrActionX(act
);
794 y
= XkbPtrActionY(act
);
795 if ((act
->flags
& XkbSA_MoveAbsoluteX
) || (x
< 0))
796 snprintf(tbuf
, sizeof(tbuf
), "x=%d", x
);
798 snprintf(tbuf
, sizeof(tbuf
), "x=+%d", x
);
799 TryCopyStr(buf
, tbuf
, sz
);
801 if ((act
->flags
& XkbSA_MoveAbsoluteY
) || (y
< 0))
802 snprintf(tbuf
, sizeof(tbuf
), ",y=%d", y
);
804 snprintf(tbuf
, sizeof(tbuf
), ",y=+%d", y
);
805 TryCopyStr(buf
, tbuf
, sz
);
806 if (act
->flags
& XkbSA_NoAcceleration
)
807 TryCopyStr(buf
, ",!accel", sz
);
811 /*ARGSUSED*/ static Bool
812 CopyPtrBtnArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
814 XkbPtrBtnAction
*act
;
818 TryCopyStr(buf
, "button=", sz
);
819 if ((act
->button
> 0) && (act
->button
< 6)) {
820 snprintf(tbuf
, sizeof(tbuf
), "%d", act
->button
);
821 TryCopyStr(buf
, tbuf
, sz
);
824 TryCopyStr(buf
, "default", sz
);
825 if (act
->count
> 0) {
826 snprintf(tbuf
, sizeof(tbuf
), ",count=%d", act
->count
);
827 TryCopyStr(buf
, tbuf
, sz
);
829 if (action
->type
== XkbSA_LockPtrBtn
) {
830 switch (act
->flags
& (XkbSA_LockNoUnlock
| XkbSA_LockNoLock
)) {
831 case XkbSA_LockNoLock
:
832 TryCopyStr(buf
, ",affect=unlock", sz
);
834 case XkbSA_LockNoUnlock
:
835 TryCopyStr(buf
, ",affect=lock", sz
);
837 case XkbSA_LockNoUnlock
| XkbSA_LockNoLock
:
838 TryCopyStr(buf
, ",affect=neither", sz
);
841 TryCopyStr(buf
, ",affect=both", sz
);
848 /*ARGSUSED*/ static Bool
849 CopySetPtrDfltArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
851 XkbPtrDfltAction
*act
;
855 if (act
->affect
== XkbSA_AffectDfltBtn
) {
856 TryCopyStr(buf
, "affect=button,button=", sz
);
857 if ((act
->flags
& XkbSA_DfltBtnAbsolute
) ||
858 (XkbSAPtrDfltValue(act
) < 0))
859 snprintf(tbuf
, sizeof(tbuf
), "%d", XkbSAPtrDfltValue(act
));
861 snprintf(tbuf
, sizeof(tbuf
), "+%d", XkbSAPtrDfltValue(act
));
862 TryCopyStr(buf
, tbuf
, sz
);
868 CopyISOLockArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
874 if (act
->flags
& XkbSA_ISODfltIsGroup
) {
875 TryCopyStr(tbuf
, "group=", sz
);
876 if (act
->flags
& XkbSA_GroupAbsolute
)
877 snprintf(tbuf
, sizeof(tbuf
), "%d", XkbSAGroup(act
) + 1);
878 else if (XkbSAGroup(act
) < 0)
879 snprintf(tbuf
, sizeof(tbuf
), "%d", XkbSAGroup(act
));
881 snprintf(tbuf
, sizeof(tbuf
), "+%d", XkbSAGroup(act
));
882 TryCopyStr(buf
, tbuf
, sz
);
887 tmp
= XkbModActionVMods(act
);
888 TryCopyStr(buf
, "modifiers=", sz
);
889 if (act
->flags
& XkbSA_UseModMapMods
)
890 TryCopyStr(buf
, "modMapMods", sz
);
891 else if (act
->real_mods
|| tmp
) {
892 if (act
->real_mods
) {
893 TryCopyStr(buf
, XkbModMaskText(act
->real_mods
, XkbXKBFile
), sz
);
895 TryCopyStr(buf
, "+", sz
);
898 TryCopyStr(buf
, XkbVModMaskText(xkb
, 0, tmp
, XkbXKBFile
), sz
);
901 TryCopyStr(buf
, "none", sz
);
903 TryCopyStr(buf
, ",affect=", sz
);
904 if ((act
->affect
& XkbSA_ISOAffectMask
) == 0)
905 TryCopyStr(buf
, "all", sz
);
909 if ((act
->affect
& XkbSA_ISONoAffectMods
) == 0) {
910 TryCopyStr(buf
, "mods", sz
);
913 if ((act
->affect
& XkbSA_ISONoAffectGroup
) == 0) {
914 snprintf(tbuf
, sizeof(tbuf
), "%sgroups", (nOut
> 0 ? "+" : ""));
915 TryCopyStr(buf
, tbuf
, sz
);
918 if ((act
->affect
& XkbSA_ISONoAffectPtr
) == 0) {
919 snprintf(tbuf
, sizeof(tbuf
), "%spointer", (nOut
> 0 ? "+" : ""));
920 TryCopyStr(buf
, tbuf
, sz
);
923 if ((act
->affect
& XkbSA_ISONoAffectCtrls
) == 0) {
924 snprintf(tbuf
, sizeof(tbuf
), "%scontrols", (nOut
> 0 ? "+" : ""));
925 TryCopyStr(buf
, tbuf
, sz
);
932 /*ARGSUSED*/ static Bool
933 CopySwitchScreenArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
935 XkbSwitchScreenAction
*act
;
938 act
= &action
->screen
;
939 if ((act
->flags
& XkbSA_SwitchAbsolute
) || (XkbSAScreen(act
) < 0))
940 snprintf(tbuf
, sizeof(tbuf
), "screen=%d", XkbSAScreen(act
));
942 snprintf(tbuf
, sizeof(tbuf
), "screen=+%d", XkbSAScreen(act
));
943 TryCopyStr(buf
, tbuf
, sz
);
944 if (act
->flags
& XkbSA_SwitchApplication
)
945 TryCopyStr(buf
, ",!same", sz
);
947 TryCopyStr(buf
, ",same", sz
);
951 /*ARGSUSED*/ static Bool
952 CopySetLockControlsArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
958 act
= &action
->ctrls
;
959 tmp
= XkbActionCtrls(act
);
960 TryCopyStr(buf
, "controls=", sz
);
962 TryCopyStr(buf
, "none", sz
);
963 else if ((tmp
& XkbAllBooleanCtrlsMask
) == XkbAllBooleanCtrlsMask
)
964 TryCopyStr(buf
, "all", sz
);
968 if (tmp
& XkbRepeatKeysMask
) {
969 snprintf(tbuf
, sizeof(tbuf
), "%sRepeatKeys", (nOut
> 0 ? "+" : ""));
970 TryCopyStr(buf
, tbuf
, sz
);
973 if (tmp
& XkbSlowKeysMask
) {
974 snprintf(tbuf
, sizeof(tbuf
), "%sSlowKeys", (nOut
> 0 ? "+" : ""));
975 TryCopyStr(buf
, tbuf
, sz
);
978 if (tmp
& XkbBounceKeysMask
) {
979 snprintf(tbuf
, sizeof(tbuf
), "%sBounceKeys", (nOut
> 0 ? "+" : ""));
980 TryCopyStr(buf
, tbuf
, sz
);
983 if (tmp
& XkbStickyKeysMask
) {
984 snprintf(tbuf
, sizeof(tbuf
), "%sStickyKeys", (nOut
> 0 ? "+" : ""));
985 TryCopyStr(buf
, tbuf
, sz
);
988 if (tmp
& XkbMouseKeysMask
) {
989 snprintf(tbuf
, sizeof(tbuf
), "%sMouseKeys", (nOut
> 0 ? "+" : ""));
990 TryCopyStr(buf
, tbuf
, sz
);
993 if (tmp
& XkbMouseKeysAccelMask
) {
994 snprintf(tbuf
, sizeof(tbuf
), "%sMouseKeysAccel",
995 (nOut
> 0 ? "+" : ""));
996 TryCopyStr(buf
, tbuf
, sz
);
999 if (tmp
& XkbAccessXKeysMask
) {
1000 snprintf(tbuf
, sizeof(tbuf
), "%sAccessXKeys",
1001 (nOut
> 0 ? "+" : ""));
1002 TryCopyStr(buf
, tbuf
, sz
);
1005 if (tmp
& XkbAccessXTimeoutMask
) {
1006 snprintf(tbuf
, sizeof(tbuf
), "%sAccessXTimeout",
1007 (nOut
> 0 ? "+" : ""));
1008 TryCopyStr(buf
, tbuf
, sz
);
1011 if (tmp
& XkbAccessXFeedbackMask
) {
1012 snprintf(tbuf
, sizeof(tbuf
), "%sAccessXFeedback",
1013 (nOut
> 0 ? "+" : ""));
1014 TryCopyStr(buf
, tbuf
, sz
);
1017 if (tmp
& XkbAudibleBellMask
) {
1018 snprintf(tbuf
, sizeof(tbuf
), "%sAudibleBell",
1019 (nOut
> 0 ? "+" : ""));
1020 TryCopyStr(buf
, tbuf
, sz
);
1023 if (tmp
& XkbOverlay1Mask
) {
1024 snprintf(tbuf
, sizeof(tbuf
), "%sOverlay1", (nOut
> 0 ? "+" : ""));
1025 TryCopyStr(buf
, tbuf
, sz
);
1028 if (tmp
& XkbOverlay2Mask
) {
1029 snprintf(tbuf
, sizeof(tbuf
), "%sOverlay2", (nOut
> 0 ? "+" : ""));
1030 TryCopyStr(buf
, tbuf
, sz
);
1033 if (tmp
& XkbIgnoreGroupLockMask
) {
1034 snprintf(tbuf
, sizeof(tbuf
), "%sIgnoreGroupLock",
1035 (nOut
> 0 ? "+" : ""));
1036 TryCopyStr(buf
, tbuf
, sz
);
1043 /*ARGSUSED*/ static Bool
1044 CopyActionMessageArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
1046 XkbMessageAction
*act
;
1051 all
= XkbSA_MessageOnPress
| XkbSA_MessageOnRelease
;
1052 TryCopyStr(buf
, "report=", sz
);
1053 if ((act
->flags
& all
) == 0)
1054 TryCopyStr(buf
, "none", sz
);
1055 else if ((act
->flags
& all
) == all
)
1056 TryCopyStr(buf
, "all", sz
);
1057 else if (act
->flags
& XkbSA_MessageOnPress
)
1058 TryCopyStr(buf
, "KeyPress", sz
);
1060 TryCopyStr(buf
, "KeyRelease", sz
);
1061 snprintf(tbuf
, sizeof(tbuf
), ",data[0]=0x%02x", act
->message
[0]);
1062 TryCopyStr(buf
, tbuf
, sz
);
1063 snprintf(tbuf
, sizeof(tbuf
), ",data[1]=0x%02x", act
->message
[1]);
1064 TryCopyStr(buf
, tbuf
, sz
);
1065 snprintf(tbuf
, sizeof(tbuf
), ",data[2]=0x%02x", act
->message
[2]);
1066 TryCopyStr(buf
, tbuf
, sz
);
1067 snprintf(tbuf
, sizeof(tbuf
), ",data[3]=0x%02x", act
->message
[3]);
1068 TryCopyStr(buf
, tbuf
, sz
);
1069 snprintf(tbuf
, sizeof(tbuf
), ",data[4]=0x%02x", act
->message
[4]);
1070 TryCopyStr(buf
, tbuf
, sz
);
1071 snprintf(tbuf
, sizeof(tbuf
), ",data[5]=0x%02x", act
->message
[5]);
1072 TryCopyStr(buf
, tbuf
, sz
);
1077 CopyRedirectKeyArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
1079 XkbRedirectKeyAction
*act
;
1080 char tbuf
[32], *tmp
;
1082 unsigned vmods
, vmods_mask
;
1084 act
= &action
->redirect
;
1086 vmods
= XkbSARedirectVMods(act
);
1087 vmods_mask
= XkbSARedirectVModsMask(act
);
1088 if (xkb
&& xkb
->names
&& xkb
->names
->keys
&& (kc
<= xkb
->max_key_code
) &&
1089 (xkb
->names
->keys
[kc
].name
[0] != '\0')) {
1092 kn
= XkbKeyNameText(xkb
->names
->keys
[kc
].name
, XkbXKBFile
);
1093 snprintf(tbuf
, sizeof(tbuf
), "key=%s", kn
);
1096 snprintf(tbuf
, sizeof(tbuf
), "key=%d", kc
);
1097 TryCopyStr(buf
, tbuf
, sz
);
1098 if ((act
->mods_mask
== 0) && (vmods_mask
== 0))
1100 if ((act
->mods_mask
== XkbAllModifiersMask
) &&
1101 (vmods_mask
== XkbAllVirtualModsMask
)) {
1102 tmp
= XkbVModMaskText(xkb
, act
->mods
, vmods
, XkbXKBFile
);
1103 TryCopyStr(buf
, ",mods=", sz
);
1104 TryCopyStr(buf
, tmp
, sz
);
1107 if ((act
->mods_mask
& act
->mods
) || (vmods_mask
& vmods
)) {
1108 tmp
= XkbVModMaskText(xkb
, act
->mods_mask
& act
->mods
,
1109 vmods_mask
& vmods
, XkbXKBFile
);
1110 TryCopyStr(buf
, ",mods= ", sz
);
1111 TryCopyStr(buf
, tmp
, sz
);
1113 if ((act
->mods_mask
& (~act
->mods
)) || (vmods_mask
& (~vmods
))) {
1114 tmp
= XkbVModMaskText(xkb
, act
->mods_mask
& (~act
->mods
),
1115 vmods_mask
& (~vmods
), XkbXKBFile
);
1116 TryCopyStr(buf
, ",clearMods= ", sz
);
1117 TryCopyStr(buf
, tmp
, sz
);
1123 /*ARGSUSED*/ static Bool
1124 CopyDeviceBtnArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
1126 XkbDeviceBtnAction
*act
;
1129 act
= &action
->devbtn
;
1130 snprintf(tbuf
, sizeof(tbuf
), "device= %d", act
->device
);
1131 TryCopyStr(buf
, tbuf
, sz
);
1132 TryCopyStr(buf
, ",button=", sz
);
1133 snprintf(tbuf
, sizeof(tbuf
), "%d", act
->button
);
1134 TryCopyStr(buf
, tbuf
, sz
);
1135 if (act
->count
> 0) {
1136 snprintf(tbuf
, sizeof(tbuf
), ",count=%d", act
->count
);
1137 TryCopyStr(buf
, tbuf
, sz
);
1139 if (action
->type
== XkbSA_LockDeviceBtn
) {
1140 switch (act
->flags
& (XkbSA_LockNoUnlock
| XkbSA_LockNoLock
)) {
1141 case XkbSA_LockNoLock
:
1142 TryCopyStr(buf
, ",affect=unlock", sz
);
1144 case XkbSA_LockNoUnlock
:
1145 TryCopyStr(buf
, ",affect=lock", sz
);
1147 case XkbSA_LockNoUnlock
| XkbSA_LockNoLock
:
1148 TryCopyStr(buf
, ",affect=neither", sz
);
1151 TryCopyStr(buf
, ",affect=both", sz
);
1158 /*ARGSUSED*/ static Bool
1159 CopyOtherArgs(XkbDescPtr xkb
, XkbAction
*action
, char *buf
, int *sz
)
1165 snprintf(tbuf
, sizeof(tbuf
), "type=0x%02x", act
->type
);
1166 TryCopyStr(buf
, tbuf
, sz
);
1167 snprintf(tbuf
, sizeof(tbuf
), ",data[0]=0x%02x", act
->data
[0]);
1168 TryCopyStr(buf
, tbuf
, sz
);
1169 snprintf(tbuf
, sizeof(tbuf
), ",data[1]=0x%02x", act
->data
[1]);
1170 TryCopyStr(buf
, tbuf
, sz
);
1171 snprintf(tbuf
, sizeof(tbuf
), ",data[2]=0x%02x", act
->data
[2]);
1172 TryCopyStr(buf
, tbuf
, sz
);
1173 snprintf(tbuf
, sizeof(tbuf
), ",data[3]=0x%02x", act
->data
[3]);
1174 TryCopyStr(buf
, tbuf
, sz
);
1175 snprintf(tbuf
, sizeof(tbuf
), ",data[4]=0x%02x", act
->data
[4]);
1176 TryCopyStr(buf
, tbuf
, sz
);
1177 snprintf(tbuf
, sizeof(tbuf
), ",data[5]=0x%02x", act
->data
[5]);
1178 TryCopyStr(buf
, tbuf
, sz
);
1179 snprintf(tbuf
, sizeof(tbuf
), ",data[6]=0x%02x", act
->data
[6]);
1180 TryCopyStr(buf
, tbuf
, sz
);
1184 typedef Bool (*actionCopy
) (XkbDescPtr
/* xkb */ ,
1185 XkbAction
* /* action */ ,
1190 static actionCopy copyActionArgs
[XkbSA_NumActions
] = {
1191 CopyNoActionArgs
/* NoAction */ ,
1192 CopyModActionArgs
/* SetMods */ ,
1193 CopyModActionArgs
/* LatchMods */ ,
1194 CopyModActionArgs
/* LockMods */ ,
1195 CopyGroupActionArgs
/* SetGroup */ ,
1196 CopyGroupActionArgs
/* LatchGroup */ ,
1197 CopyGroupActionArgs
/* LockGroup */ ,
1198 CopyMovePtrArgs
/* MovePtr */ ,
1199 CopyPtrBtnArgs
/* PtrBtn */ ,
1200 CopyPtrBtnArgs
/* LockPtrBtn */ ,
1201 CopySetPtrDfltArgs
/* SetPtrDflt */ ,
1202 CopyISOLockArgs
/* ISOLock */ ,
1203 CopyNoActionArgs
/* Terminate */ ,
1204 CopySwitchScreenArgs
/* SwitchScreen */ ,
1205 CopySetLockControlsArgs
/* SetControls */ ,
1206 CopySetLockControlsArgs
/* LockControls */ ,
1207 CopyActionMessageArgs
/* ActionMessage */ ,
1208 CopyRedirectKeyArgs
/* RedirectKey */ ,
1209 CopyDeviceBtnArgs
/* DeviceBtn */ ,
1210 CopyDeviceBtnArgs
/* LockDeviceBtn */
1213 #define ACTION_SZ 256
1216 XkbActionText(XkbDescPtr xkb
, XkbAction
*action
, unsigned format
)
1218 char buf
[ACTION_SZ
], *tmp
;
1221 if (format
== XkbCFile
) {
1222 snprintf(buf
, sizeof(buf
),
1223 "{ %20s, { 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x } }",
1224 XkbActionTypeText(action
->type
, XkbCFile
),
1225 action
->any
.data
[0], action
->any
.data
[1], action
->any
.data
[2],
1226 action
->any
.data
[3], action
->any
.data
[4], action
->any
.data
[5],
1227 action
->any
.data
[6]);
1230 snprintf(buf
, sizeof(buf
), "%s(",
1231 XkbActionTypeText(action
->type
, XkbXKBFile
));
1232 sz
= ACTION_SZ
- strlen(buf
) + 2; /* room for close paren and NULL */
1233 if (action
->type
< (unsigned) XkbSA_NumActions
)
1234 (*copyActionArgs
[action
->type
]) (xkb
, action
, buf
, &sz
);
1236 CopyOtherArgs(xkb
, action
, buf
, &sz
);
1237 TryCopyStr(buf
, ")", &sz
);
1239 tmp
= tbGetBuffer(strlen(buf
) + 1);
1246 XkbBehaviorText(XkbDescPtr xkb
, XkbBehavior
* behavior
, unsigned format
)
1248 char buf
[256], *tmp
;
1250 if (format
== XkbCFile
) {
1251 if (behavior
->type
== XkbKB_Default
)
1252 snprintf(buf
, sizeof(buf
), "{ 0, 0 }");
1254 snprintf(buf
, sizeof(buf
), "{ %3d, 0x%02x }", behavior
->type
,
1258 unsigned type
, permanent
;
1260 type
= behavior
->type
& XkbKB_OpMask
;
1261 permanent
= ((behavior
->type
& XkbKB_Permanent
) != 0);
1263 if (type
== XkbKB_Lock
) {
1264 snprintf(buf
, sizeof(buf
), "lock= %s",
1265 (permanent
? "Permanent" : "TRUE"));
1267 else if (type
== XkbKB_RadioGroup
) {
1270 g
= ((behavior
->data
) & (~XkbKB_RGAllowNone
)) + 1;
1271 if (XkbKB_RGAllowNone
& behavior
->data
) {
1272 snprintf(buf
, sizeof(buf
), "allowNone,");
1273 tmp
= &buf
[strlen(buf
)];
1278 sprintf(tmp
, "permanentRadioGroup= %d", g
);
1280 sprintf(tmp
, "radioGroup= %d", g
);
1282 else if ((type
== XkbKB_Overlay1
) || (type
== XkbKB_Overlay2
)) {
1286 ndx
= ((type
== XkbKB_Overlay1
) ? 1 : 2);
1287 kc
= behavior
->data
;
1288 if ((xkb
) && (xkb
->names
) && (xkb
->names
->keys
))
1289 kn
= XkbKeyNameText(xkb
->names
->keys
[kc
].name
, XkbXKBFile
);
1291 static char tbuf
[8];
1293 snprintf(tbuf
, sizeof(tbuf
), "%d", kc
);
1297 snprintf(buf
, sizeof(buf
), "permanentOverlay%d= %s", ndx
, kn
);
1299 snprintf(buf
, sizeof(buf
), "overlay%d= %s", ndx
, kn
);
1302 tmp
= tbGetBuffer(strlen(buf
) + 1);
1308 /***====================================================================***/
1311 XkbIndentText(unsigned size
)
1313 static char buf
[32];
1319 for (i
= 0; i
< size
; i
++) {