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 ********************************************************/
28 #include "xkbcommon/xkbcommon.h"
29 #include "XKBcommonint.h"
34 #define BUFFER_SIZE 1024
35 static char textBuffer[BUFFER_SIZE];
36 static unsigned int tbNext = 0;
39 tbGetBuffer(unsigned int size)
43 if (size >= BUFFER_SIZE)
46 if ((BUFFER_SIZE - tbNext) <= size)
49 rtrn = &textBuffer[tbNext];
56 XkbcVModIndexText(struct xkb_keymap * xkb, unsigned ndx)
60 const char *tmp = NULL;
63 if (ndx >= XkbNumVirtualMods)
65 else if (xkb && xkb->names)
66 tmp = xkb->names->vmods[ndx];
69 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
73 len = strlen(tmp) + 1;
74 if (len >= BUFFER_SIZE)
75 len = BUFFER_SIZE - 1;
77 rtrn = tbGetBuffer(len);
78 strncpy(rtrn, tmp, len);
84 XkbcVModMaskText(struct xkb_keymap * xkb, unsigned modMask, unsigned mask)
87 const char *mm = NULL;
89 char buf[BUFFER_SIZE];
91 if ((modMask == 0) && (mask == 0))
95 mm = XkbcModMaskText(modMask, false);
102 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
107 len = snprintf(str, rem, "%s%s",
108 (str != buf) ? "+" : "",
109 XkbcVModIndexText(xkb, i));
119 len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
120 ((str && mm) ? 1 : 0);
121 if (len >= BUFFER_SIZE)
122 len = BUFFER_SIZE - 1;
124 rtrn = tbGetBuffer(len + 1);
127 snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
128 (mm && str) ? "+" : "", (str) ? str : "");
133 static const char *modNames[XkbNumModifiers] = {
145 XkbcModIndexText(unsigned ndx)
149 if (ndx < XkbNumModifiers)
150 return modNames[ndx];
151 else if (ndx == XkbNoModifier)
154 buf = tbGetBuffer(32);
155 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
161 XkbcModMaskText(unsigned mask, bool cFormat)
166 if ((mask & 0xff) == 0xff)
167 return (cFormat ? "0xff" : "all");
169 if ((mask & 0xff) == 0)
170 return (cFormat ? "0" : "none");
173 buf = tbGetBuffer(rem);
176 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
182 len = snprintf(str, rem, "%s%s%s",
183 (str != buf) ? (cFormat ? "|" : "+") : "",
185 cFormat ? "Mask" : "");
194 XkbcConfigText(unsigned config)
197 case XkmSemanticsFile:
205 case XkmCompatMapIndex:
207 case XkmSymbolsIndex:
209 case XkmIndicatorsIndex:
211 case XkmKeyNamesIndex:
213 case XkmVirtualModsIndex:
214 return "VirtualMods";
220 static const char *actionTypeNames[XkbSA_NumActions]= {
221 "NoAction", /* XkbSA_NoAction */
222 "SetMods", /* XkbSA_SetMods */
223 "LatchMods", /* XkbSA_LatchMods */
224 "LockMods", /* XkbSA_LockMods */
225 "SetGroup", /* XkbSA_SetGroup */
226 "LatchGroup", /* XkbSA_LatchGroup */
227 "LockGroup", /* XkbSA_LockGroup */
228 "MovePtr", /* XkbSA_MovePtr */
229 "PtrBtn", /* XkbSA_PtrBtn */
230 "LockPtrBtn", /* XkbSA_LockPtrBtn */
231 "SetPtrDflt", /* XkbSA_SetPtrDflt */
232 "ISOLock", /* XkbSA_ISOLock */
233 "Terminate", /* XkbSA_Terminate */
234 "SwitchScreen", /* XkbSA_SwitchScreen */
235 "SetControls", /* XkbSA_SetControls */
236 "LockControls", /* XkbSA_LockControls */
237 "ActionMessage", /* XkbSA_ActionMessage */
238 "RedirectKey", /* XkbSA_RedirectKey */
239 "DeviceBtn", /* XkbSA_DeviceBtn */
240 "LockDeviceBtn", /* XkbSA_LockDeviceBtn */
241 "DeviceValuator" /* XkbSA_DeviceValuator */
245 XkbcActionTypeText(unsigned type)
247 if (type <= XkbSA_LastAction)
248 return actionTypeNames[type];
253 XkbcKeysymText(xkb_keysym_t sym)
255 static char buffer[16];
257 xkb_keysym_to_string(sym, buffer, sizeof buffer);
263 XkbcKeyNameText(char *name)
268 buf = tbGetBuffer(7);
270 strncpy(&buf[1], name, 4);
279 static const char *siMatchText[5] = {
280 "NoneOf", /* XkbSI_NoneOf */
281 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
282 "AnyOf", /* XkbSI_AnyOf */
283 "AllOf", /* XkbSI_AllOf */
284 "Exactly" /* XkbSI_Exactly */
288 XkbcSIMatchText(unsigned type)
292 switch (type & XkbSI_OpMask) {
294 return siMatchText[0];
295 case XkbSI_AnyOfOrNone:
296 return siMatchText[1];
298 return siMatchText[2];
300 return siMatchText[3];
302 return siMatchText[4];
304 buf = tbGetBuffer(40);
305 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);