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"
37 #define BUFFER_SIZE 1024
38 static char textBuffer[BUFFER_SIZE];
39 static int tbNext = 0;
42 tbGetBuffer(unsigned int size)
46 if (size >= BUFFER_SIZE)
49 if ((BUFFER_SIZE - tbNext) <= size)
52 rtrn = &textBuffer[tbNext];
59 XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
63 char *rtrn, *tmp = NULL;
65 if (xkb && xkb->names)
66 vmodNames = xkb->names->vmods;
70 if (ndx >= XkbNumVirtualMods)
71 tmp = strdup("illegal");
72 else if (vmodNames && (vmodNames[ndx] != None))
73 tmp = XkbcAtomGetString(vmodNames[ndx]);
76 tmp = malloc(20 * sizeof(char));
77 snprintf(tmp, 20, "%d", ndx);
80 len = strlen(tmp) + 1;
81 if (len >= BUFFER_SIZE)
82 len = BUFFER_SIZE - 1;
84 rtrn = tbGetBuffer(len);
85 strncpy(rtrn, tmp, len);
93 XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
96 char *mm = NULL, *rtrn, *str;
97 char buf[BUFFER_SIZE];
99 if ((modMask == 0) && (mask == 0))
103 mm = XkbcModMaskText(modMask, False);
110 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
115 len = snprintf(str, rem, "%s%s",
116 (str != buf) ? "+" : "",
117 XkbcVModIndexText(xkb, i));
127 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
128 ((str && mm) ? 1 : 0);
129 if (len >= BUFFER_SIZE)
130 len = BUFFER_SIZE - 1;
132 rtrn = tbGetBuffer(len + 1);
135 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
136 (mm && str) ? "+" : "", (str) ? str : "");
141 static char *modNames[XkbNumModifiers] = {
153 XkbcModIndexText(unsigned ndx)
157 if (ndx < XkbNumModifiers)
158 return modNames[ndx];
159 else if (ndx == XkbNoModifier)
162 buf = tbGetBuffer(32);
163 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
169 XkbcModMaskText(unsigned mask, Bool cFormat)
174 if ((mask & 0xff) == 0xff)
175 return (cFormat ? "0xff" : "all");
177 if ((mask & 0xff) == 0)
178 return (cFormat ? "0" : "none");
181 buf = tbGetBuffer(rem);
184 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
190 len = snprintf(str, rem, "%s%s%s",
191 (str != buf) ? (cFormat ? "|" : "+") : "",
193 cFormat ? "Mask" : "");
202 XkbcConfigText(unsigned config)
205 case XkmSemanticsFile:
211 case XkmGeometryFile:
212 case XkmGeometryIndex:
216 case XkmCompatMapIndex:
218 case XkmSymbolsIndex:
220 case XkmIndicatorsIndex:
222 case XkmKeyNamesIndex:
224 case XkmVirtualModsIndex:
225 return "VirtualMods";
232 XkbcGeomFPText(int val)
237 buf = tbGetBuffer(12);
238 whole = val / XkbGeomPtsPerMM;
239 frac = val % XkbGeomPtsPerMM;
242 snprintf(buf, 12, "%d.%d", whole, frac);
244 snprintf(buf, 12, "%d", whole);
249 static char *actionTypeNames[XkbSA_NumActions]= {
250 "NoAction", /* XkbSA_NoAction */
251 "SetMods", /* XkbSA_SetMods */
252 "LatchMods", /* XkbSA_LatchMods */
253 "LockMods", /* XkbSA_LockMods */
254 "SetGroup", /* XkbSA_SetGroup */
255 "LatchGroup", /* XkbSA_LatchGroup */
256 "LockGroup", /* XkbSA_LockGroup */
257 "MovePtr", /* XkbSA_MovePtr */
258 "PtrBtn", /* XkbSA_PtrBtn */
259 "LockPtrBtn", /* XkbSA_LockPtrBtn */
260 "SetPtrDflt", /* XkbSA_SetPtrDflt */
261 "ISOLock", /* XkbSA_ISOLock */
262 "Terminate", /* XkbSA_Terminate */
263 "SwitchScreen", /* XkbSA_SwitchScreen */
264 "SetControls", /* XkbSA_SetControls */
265 "LockControls", /* XkbSA_LockControls */
266 "ActionMessage", /* XkbSA_ActionMessage */
267 "RedirectKey", /* XkbSA_RedirectKey */
268 "DeviceBtn", /* XkbSA_DeviceBtn */
269 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
270 "DeviceValuator" /* XkbSA_DeviceValuator */
274 XkbcActionTypeText(unsigned type)
276 if (type <= XkbSA_LastAction)
277 return actionTypeNames[type];
282 XkbcKeysymText(uint32_t sym)
284 static char buffer[16];
286 xkb_keysym_to_string(sym, buffer, sizeof buffer);
292 XkbcKeyNameText(char *name)
297 buf = tbGetBuffer(7);
299 strncpy(&buf[1], name, 4);
308 static char *siMatchText[5] = {
309 "NoneOf", /* XkbSI_NoneOf */
310 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
311 "AnyOf", /* XkbSI_AnyOf */
312 "AllOf", /* XkbSI_AllOf */
313 "Exactly" /* XkbSI_Exactly */
317 XkbcSIMatchText(unsigned type)
321 switch (type & XkbSI_OpMask) {
323 return siMatchText[0];
324 case XkbSI_AnyOfOrNone:
325 return siMatchText[1];
327 return siMatchText[2];
329 return siMatchText[3];
331 return siMatchText[4];
333 buf = tbGetBuffer(40);
334 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);