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 #define BUFFER_SIZE 1024
32 GetBuffer(size_t size)
34 static char buffer[BUFFER_SIZE];
38 if (size >= BUFFER_SIZE)
41 if (BUFFER_SIZE - next <= size)
51 * Get a vmod name's text, where the vmod index is zero based
52 * (0..XkbNumVirtualMods-1).
55 VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
59 const char *tmp = NULL;
62 if (ndx >= XkbNumVirtualMods)
65 tmp = keymap->vmod_names[ndx];
68 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
72 len = strlen(tmp) + 1;
73 if (len >= BUFFER_SIZE)
74 len = BUFFER_SIZE - 1;
76 rtrn = GetBuffer(len);
77 strncpy(rtrn, tmp, len);
82 /* Get a mod mask's text, where the mask is in rmods+vmods format. */
84 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
88 xkb_mod_mask_t rmask, vmask;
90 const char *mm = NULL;
92 char buf[BUFFER_SIZE];
95 vmask = cmask >> XkbNumModifiers;
97 if (rmask == 0 && vmask == 0)
101 mm = ModMaskText(rmask);
108 for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<=
113 len = snprintf(str, rem, "%s%s",
114 (str != buf) ? "+" : "",
115 VModIndexText(keymap, i));
125 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
127 if (len >= BUFFER_SIZE)
128 len = BUFFER_SIZE - 1;
130 rtrn = GetBuffer(len + 1);
133 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
134 (mm && str ? "+" : ""), (str ? str : ""));
141 * The indices used for the legacy core modifiers is derived from
142 * the order of the names in this table. It matches the values
143 * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
146 static const char *modNames[XkbNumModifiers] = {
158 ModNameToIndex(const char *name)
162 for (i = 0; i < XkbNumModifiers; i++)
163 if (istreq(name, modNames[i]))
166 return XKB_MOD_INVALID;
170 ModIndexToName(xkb_mod_index_t ndx)
172 if (ndx < XkbNumModifiers)
173 return modNames[ndx];
178 ModIndexText(xkb_mod_index_t ndx)
183 name = ModIndexToName(ndx);
187 if (ndx == XkbNoModifier)
191 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
196 /* Gets the text for the real modifiers only. */
198 ModMaskText(xkb_mod_mask_t mask)
204 if ((mask & 0xff) == 0xff)
207 if ((mask & 0xff) == 0)
211 buf = GetBuffer(rem);
214 for (i = 0, bit = 1; i < XkbNumModifiers && rem > 1; i++, bit <<= 1) {
220 len = snprintf(str, rem, "%s%s",
221 (str != buf ? "+" : ""), modNames[i]);
229 static const char *actionTypeNames[XkbSA_NumActions] = {
230 [XkbSA_NoAction] = "NoAction",
231 [XkbSA_SetMods] = "SetMods",
232 [XkbSA_LatchMods] = "LatchMods",
233 [XkbSA_LockMods] = "LockMods",
234 [XkbSA_SetGroup] = "SetGroup",
235 [XkbSA_LatchGroup] = "LatchGroup",
236 [XkbSA_LockGroup] = "LockGroup",
237 [XkbSA_MovePtr] = "MovePtr",
238 [XkbSA_PtrBtn] = "PtrBtn",
239 [XkbSA_LockPtrBtn] = "LockPtrBtn",
240 [XkbSA_SetPtrDflt] = "SetPtrDflt",
241 [XkbSA_ISOLock] = "ISOLock",
242 [XkbSA_Terminate] = "Terminate",
243 [XkbSA_SwitchScreen] = "SwitchScreen",
244 [XkbSA_SetControls] = "SetControls",
245 [XkbSA_LockControls] = "LockControls",
246 [XkbSA_ActionMessage] = "ActionMessage",
247 [XkbSA_RedirectKey] = "RedirectKey",
248 [XkbSA_DeviceBtn] = "DeviceBtn",
249 [XkbSA_LockDeviceBtn] = "LockDeviceBtn",
250 [XkbSA_DeviceValuator] = "DeviceValuator"
254 ActionTypeText(unsigned type)
256 if (type <= XkbSA_LastAction)
257 return actionTypeNames[type];
262 KeysymText(xkb_keysym_t sym)
264 static char buffer[64];
266 xkb_keysym_get_name(sym, buffer, sizeof buffer);
272 KeyNameText(const char name[XkbKeyNameLength])
279 strncpy(&buf[1], name, 4);
288 static const char *siMatchText[5] = {
289 "NoneOf", /* XkbSI_NoneOf */
290 "AnyOfOrNone", /* XkbSI_AnyOfOrNone */
291 "AnyOf", /* XkbSI_AnyOf */
292 "AllOf", /* XkbSI_AllOf */
293 "Exactly" /* XkbSI_Exactly */
297 SIMatchText(unsigned type)
301 switch (type & XkbSI_OpMask) {
303 return siMatchText[0];
304 case XkbSI_AnyOfOrNone:
305 return siMatchText[1];
307 return siMatchText[2];
309 return siMatchText[3];
311 return siMatchText[4];
314 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);