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 LookupString(const LookupEntry tab[], const char *string,
32 unsigned int *value_rtrn)
34 const LookupEntry *entry;
39 for (entry = tab; entry->name; entry++) {
40 if (istreq(entry->name, string)) {
41 *value_rtrn = entry->value;
50 LookupValue(const LookupEntry tab[], unsigned int value)
52 const LookupEntry *entry;
54 for (entry = tab; entry->name; entry++)
55 if (entry->value == value)
61 const LookupEntry ctrlMaskNames[] = {
62 { "RepeatKeys", CONTROL_REPEAT },
63 { "Repeat", CONTROL_REPEAT },
64 { "AutoRepeat", CONTROL_REPEAT },
65 { "SlowKeys", CONTROL_SLOW },
66 { "BounceKeys", CONTROL_DEBOUNCE },
67 { "StickyKeys", CONTROL_STICKY },
68 { "MouseKeys", CONTROL_MOUSEKEYS },
69 { "MouseKeysAccel", CONTROL_MOUSEKEYS_ACCEL },
70 { "AccessXKeys", CONTROL_AX },
71 { "AccessXTimeout", CONTROL_AX_TIMEOUT },
72 { "AccessXFeedback", CONTROL_AX_FEEDBACK },
73 { "AudibleBell", CONTROL_BELL },
74 { "IgnoreGroupLock", CONTROL_IGNORE_GROUP_LOCK },
75 { "all", CONTROL_ALL },
82 const LookupEntry modComponentMaskNames[] = {
83 {"base", XKB_STATE_DEPRESSED},
84 {"latched", XKB_STATE_LATCHED},
85 {"locked", XKB_STATE_LOCKED},
86 {"effective", XKB_STATE_EFFECTIVE},
87 {"compat", XKB_STATE_EFFECTIVE},
88 {"any", XKB_STATE_EFFECTIVE},
93 const LookupEntry groupComponentMaskNames[] = {
94 {"base", XKB_STATE_DEPRESSED},
95 {"latched", XKB_STATE_LATCHED},
96 {"locked", XKB_STATE_LOCKED},
97 {"effective", XKB_STATE_EFFECTIVE},
98 {"any", XKB_STATE_EFFECTIVE},
103 const LookupEntry groupMaskNames[] = {
117 const LookupEntry groupNames[] = {
129 const LookupEntry levelNames[] = {
141 const LookupEntry buttonNames[] = {
151 const LookupEntry useModMapValueNames[] = {
159 const LookupEntry actionTypeNames[] = {
160 { "NoAction", ACTION_TYPE_NONE },
161 { "SetMods", ACTION_TYPE_MOD_SET },
162 { "LatchMods", ACTION_TYPE_MOD_LATCH },
163 { "LockMods", ACTION_TYPE_MOD_LOCK },
164 { "SetGroup", ACTION_TYPE_GROUP_SET },
165 { "LatchGroup", ACTION_TYPE_GROUP_LATCH },
166 { "LockGroup", ACTION_TYPE_GROUP_LOCK },
167 { "MovePtr", ACTION_TYPE_PTR_MOVE },
168 { "MovePointer", ACTION_TYPE_PTR_MOVE },
169 { "PtrBtn", ACTION_TYPE_PTR_BUTTON },
170 { "PointerButton", ACTION_TYPE_PTR_BUTTON },
171 { "LockPtrBtn", ACTION_TYPE_PTR_LOCK },
172 { "LockPtrButton", ACTION_TYPE_PTR_LOCK },
173 { "LockPointerButton", ACTION_TYPE_PTR_LOCK },
174 { "LockPointerBtn", ACTION_TYPE_PTR_LOCK },
175 { "SetPtrDflt", ACTION_TYPE_PTR_DEFAULT },
176 { "SetPointerDefault", ACTION_TYPE_PTR_DEFAULT },
177 { "Terminate", ACTION_TYPE_TERMINATE },
178 { "TerminateServer", ACTION_TYPE_TERMINATE },
179 { "SwitchScreen", ACTION_TYPE_SWITCH_VT },
180 { "SetControls", ACTION_TYPE_CTRL_SET },
181 { "LockControls", ACTION_TYPE_CTRL_LOCK },
182 { "RedirectKey", ACTION_TYPE_KEY_REDIRECT },
183 { "Redirect", ACTION_TYPE_KEY_REDIRECT },
184 { "Private", ACTION_TYPE_PRIVATE },
185 /* deprecated actions below here - unused */
186 { "ISOLock", ACTION_TYPE_NONE },
187 { "ActionMessage", ACTION_TYPE_NONE },
188 { "MessageAction", ACTION_TYPE_NONE },
189 { "Message", ACTION_TYPE_NONE },
190 { "DeviceBtn", ACTION_TYPE_NONE },
191 { "DevBtn", ACTION_TYPE_NONE },
192 { "DevButton", ACTION_TYPE_NONE },
193 { "DeviceButton", ACTION_TYPE_NONE },
194 { "LockDeviceBtn", ACTION_TYPE_NONE },
195 { "LockDevBtn", ACTION_TYPE_NONE },
196 { "LockDevButton", ACTION_TYPE_NONE },
197 { "LockDeviceButton", ACTION_TYPE_NONE },
198 { "DeviceValuator", ACTION_TYPE_NONE },
199 { "DevVal", ACTION_TYPE_NONE },
200 { "DeviceVal", ACTION_TYPE_NONE },
201 { "DevValuator", ACTION_TYPE_NONE },
205 const LookupEntry symInterpretMatchMaskNames[] = {
206 { "NoneOf", MATCH_NONE },
207 { "AnyOfOrNone", MATCH_ANY_OR_NONE },
208 { "AnyOf", MATCH_ANY },
209 { "AllOf", MATCH_ALL },
210 { "Exactly", MATCH_EXACTLY },
213 #define BUFFER_SIZE 1024
216 GetBuffer(size_t size)
218 static char buffer[BUFFER_SIZE];
222 if (size >= BUFFER_SIZE)
225 if (BUFFER_SIZE - next <= size)
228 rtrn = &buffer[next];
235 * Get a vmod name's text, where the vmod index is zero based
236 * (0..XKB_NUM_VIRTUAL_MODS-1).
239 VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
243 const char *tmp = NULL;
246 if (ndx >= XKB_NUM_VIRTUAL_MODS)
249 tmp = xkb_atom_text(keymap->ctx, keymap->vmod_names[ndx]);
252 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
256 len = strlen(tmp) + 1;
257 if (len >= BUFFER_SIZE)
258 len = BUFFER_SIZE - 1;
260 rtrn = GetBuffer(len);
261 strncpy(rtrn, tmp, len);
266 /* Get a mod mask's text, where the mask is in rmods+vmods format. */
268 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
272 xkb_mod_mask_t rmask, vmask;
274 const char *mm = NULL;
276 char buf[BUFFER_SIZE];
278 rmask = cmask & 0xff;
279 vmask = cmask >> XKB_NUM_CORE_MODS;
281 if (rmask == 0 && vmask == 0)
285 mm = ModMaskText(rmask);
292 for (i = 0, bit = 1; i < XKB_NUM_VIRTUAL_MODS && rem > 1; i++, bit <<=
297 len = snprintf(str, rem, "%s%s",
298 (str != buf) ? "+" : "",
299 VModIndexText(keymap, i));
309 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
311 if (len >= BUFFER_SIZE)
312 len = BUFFER_SIZE - 1;
314 rtrn = GetBuffer(len + 1);
317 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
318 (mm && str ? "+" : ""), (str ? str : ""));
325 * The indices used for the legacy core modifiers is derived from
326 * the order of the names in this table. It matches the values
327 * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
330 static const char *modNames[XKB_NUM_CORE_MODS] = {
342 ModNameToIndex(const char *name)
346 for (i = 0; i < XKB_NUM_CORE_MODS; i++)
347 if (istreq(name, modNames[i]))
350 return XKB_MOD_INVALID;
354 ModIndexToName(xkb_mod_index_t ndx)
356 if (ndx < XKB_NUM_CORE_MODS)
357 return modNames[ndx];
362 ModIndexText(xkb_mod_index_t ndx)
367 name = ModIndexToName(ndx);
371 if (ndx == XKB_MOD_INVALID)
375 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
380 /* Gets the text for the real modifiers only. */
382 ModMaskText(xkb_mod_mask_t mask)
388 if ((mask & 0xff) == 0xff)
391 if ((mask & 0xff) == 0)
395 buf = GetBuffer(rem);
398 for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) {
404 len = snprintf(str, rem, "%s%s",
405 (str != buf ? "+" : ""), modNames[i]);
414 ActionTypeText(unsigned type)
416 const char *name = LookupValue(actionTypeNames, type);
417 return name ? name : "Private";
421 KeysymText(xkb_keysym_t sym)
423 static char buffer[64];
425 xkb_keysym_get_name(sym, buffer, sizeof buffer);
431 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
433 const char *sname = xkb_atom_text(ctx, name);
434 size_t len = strlen(sname) + 3;
435 char *buf = GetBuffer(len);
436 snprintf(buf, len, "<%s>", sname);
441 SIMatchText(enum xkb_match_operation type)
446 type &= MATCH_OP_MASK;
448 name = LookupValue(symInterpretMatchMaskNames, type);
453 snprintf(buf, 40, "0x%x", type);