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 ********************************************************/
31 #include "X11/extensions/XKBcommon.h"
32 #include "XKBcommonint.h"
33 #include <X11/extensions/XKM.h>
38 #define BUFFER_SIZE 1024
39 static char textBuffer[BUFFER_SIZE];
40 static int tbNext = 0;
43 tbGetBuffer(unsigned int size)
47 if (size >= BUFFER_SIZE)
50 if ((BUFFER_SIZE - tbNext) <= size)
53 rtrn = &textBuffer[tbNext];
60 XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx)
64 char *rtrn, *tmp = NULL;
66 if (xkb && xkb->names)
67 vmodNames = xkb->names->vmods;
71 if (ndx >= XkbNumVirtualMods)
72 tmp = strdup("illegal");
73 else if (vmodNames && (vmodNames[ndx] != None))
74 tmp = XkbcAtomGetString(vmodNames[ndx]);
77 tmp = malloc(20 * sizeof(char));
78 snprintf(tmp, 20, "%d", ndx);
81 len = strlen(tmp) + 1;
82 if (len >= BUFFER_SIZE)
83 len = BUFFER_SIZE - 1;
85 rtrn = tbGetBuffer(len);
86 strncpy(rtrn, tmp, len);
94 XkbcVModMaskText(XkbcDescPtr xkb, unsigned modMask, unsigned mask)
97 char *mm = NULL, *rtrn, *str;
98 char buf[BUFFER_SIZE];
100 if ((modMask == 0) && (mask == 0))
104 mm = XkbcModMaskText(modMask, False);
111 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
116 len = snprintf(str, rem, "%s%s",
117 (str != buf) ? "+" : "",
118 XkbcVModIndexText(xkb, i));
128 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
129 ((str && mm) ? 1 : 0);
130 if (len >= BUFFER_SIZE)
131 len = BUFFER_SIZE - 1;
133 rtrn = tbGetBuffer(len + 1);
136 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
137 (mm && str) ? "+" : "", (str) ? str : "");
142 static char *modNames[XkbNumModifiers] = {
154 XkbcModIndexText(unsigned ndx)
158 if (ndx < XkbNumModifiers)
159 return modNames[ndx];
160 else if (ndx == XkbNoModifier)
163 buf = tbGetBuffer(32);
164 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
170 XkbcModMaskText(unsigned mask, Bool cFormat)
175 if ((mask & 0xff) == 0xff)
176 return (cFormat ? "0xff" : "all");
178 if ((mask & 0xff) == 0)
179 return (cFormat ? "0" : "none");
182 buf = tbGetBuffer(rem);
185 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
191 len = snprintf(str, rem, "%s%s%s",
192 (str != buf) ? (cFormat ? "|" : "+") : "",
194 cFormat ? "Mask" : "");
203 XkbcConfigText(unsigned config)
206 case XkmSemanticsFile:
212 case XkmGeometryFile:
213 case XkmGeometryIndex:
217 case XkmCompatMapIndex:
219 case XkmSymbolsIndex:
221 case XkmIndicatorsIndex:
223 case XkmKeyNamesIndex:
225 case XkmVirtualModsIndex:
226 return "VirtualMods";
233 XkbcGeomFPText(int val)
238 buf = tbGetBuffer(12);
239 whole = val / XkbGeomPtsPerMM;
240 frac = val % XkbGeomPtsPerMM;
243 snprintf(buf, 12, "%d.%d", whole, frac);
245 snprintf(buf, 12, "%d", whole);
250 static char *actionTypeNames[XkbSA_NumActions]= {
251 "NoAction", /* XkbSA_NoAction */
252 "SetMods", /* XkbSA_SetMods */
253 "LatchMods", /* XkbSA_LatchMods */
254 "LockMods", /* XkbSA_LockMods */
255 "SetGroup", /* XkbSA_SetGroup */
256 "LatchGroup", /* XkbSA_LatchGroup */
257 "LockGroup", /* XkbSA_LockGroup */
258 "MovePtr", /* XkbSA_MovePtr */
259 "PtrBtn", /* XkbSA_PtrBtn */
260 "LockPtrBtn", /* XkbSA_LockPtrBtn */
261 "SetPtrDflt", /* XkbSA_SetPtrDflt */
262 "ISOLock", /* XkbSA_ISOLock */
263 "Terminate", /* XkbSA_Terminate */
264 "SwitchScreen", /* XkbSA_SwitchScreen */
265 "SetControls", /* XkbSA_SetControls */
266 "LockControls", /* XkbSA_LockControls */
267 "ActionMessage", /* XkbSA_ActionMessage */
268 "RedirectKey", /* XkbSA_RedirectKey */
269 "DeviceBtn", /* XkbSA_DeviceBtn */
270 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
271 "DeviceValuator" /* XkbSA_DeviceValuator */
275 XkbcActionTypeText(unsigned type)
277 if (type <= XkbSA_LastAction)
278 return actionTypeNames[type];
283 XkbcKeysymText(uint32_t sym)
285 return XkbcKeysymToString(sym);
289 XkbcKeyNameText(char *name)
294 buf = tbGetBuffer(7);
296 strncpy(&buf[1], name, 4);
305 static char *siMatchText[5] = {
306 "NoneOf", /* XkbSI_NoneOf */
307 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
308 "AnyOf", /* XkbSI_AnyOf */
309 "AllOf", /* XkbSI_AllOf */
310 "Exactly" /* XkbSI_Exactly */
314 XkbcSIMatchText(unsigned type)
318 switch (type & XkbSI_OpMask) {
320 return siMatchText[0];
321 case XkbSI_AnyOfOrNone:
322 return siMatchText[1];
324 return siMatchText[2];
326 return siMatchText[3];
328 return siMatchText[4];
330 buf = tbGetBuffer(40);
331 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);