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 ********************************************************/
30 LookupString(const LookupEntry tab[], const char *string,
31 unsigned int *value_rtrn)
33 const LookupEntry *entry;
38 for (entry = tab; entry->name; entry++) {
39 if (istreq(entry->name, string)) {
40 *value_rtrn = entry->value;
49 LookupValue(const LookupEntry tab[], unsigned int value)
51 const LookupEntry *entry;
53 for (entry = tab; entry->name; entry++)
54 if (entry->value == value)
60 const LookupEntry ctrlMaskNames[] = {
61 { "RepeatKeys", CONTROL_REPEAT },
62 { "Repeat", CONTROL_REPEAT },
63 { "AutoRepeat", CONTROL_REPEAT },
64 { "SlowKeys", CONTROL_SLOW },
65 { "BounceKeys", CONTROL_DEBOUNCE },
66 { "StickyKeys", CONTROL_STICKY },
67 { "MouseKeys", CONTROL_MOUSEKEYS },
68 { "MouseKeysAccel", CONTROL_MOUSEKEYS_ACCEL },
69 { "AccessXKeys", CONTROL_AX },
70 { "AccessXTimeout", CONTROL_AX_TIMEOUT },
71 { "AccessXFeedback", CONTROL_AX_FEEDBACK },
72 { "AudibleBell", CONTROL_BELL },
73 { "IgnoreGroupLock", CONTROL_IGNORE_GROUP_LOCK },
74 { "all", CONTROL_ALL },
81 const LookupEntry modComponentMaskNames[] = {
82 {"base", XKB_STATE_DEPRESSED},
83 {"latched", XKB_STATE_LATCHED},
84 {"locked", XKB_STATE_LOCKED},
85 {"effective", XKB_STATE_EFFECTIVE},
86 {"compat", XKB_STATE_EFFECTIVE},
87 {"any", XKB_STATE_EFFECTIVE},
92 const LookupEntry groupComponentMaskNames[] = {
93 {"base", XKB_STATE_DEPRESSED},
94 {"latched", XKB_STATE_LATCHED},
95 {"locked", XKB_STATE_LOCKED},
96 {"effective", XKB_STATE_EFFECTIVE},
97 {"any", XKB_STATE_EFFECTIVE},
102 const LookupEntry groupMaskNames[] = {
116 const LookupEntry groupNames[] = {
128 const LookupEntry levelNames[] = {
140 const LookupEntry buttonNames[] = {
150 const LookupEntry useModMapValueNames[] = {
158 const LookupEntry actionTypeNames[] = {
159 { "NoAction", ACTION_TYPE_NONE },
160 { "SetMods", ACTION_TYPE_MOD_SET },
161 { "LatchMods", ACTION_TYPE_MOD_LATCH },
162 { "LockMods", ACTION_TYPE_MOD_LOCK },
163 { "SetGroup", ACTION_TYPE_GROUP_SET },
164 { "LatchGroup", ACTION_TYPE_GROUP_LATCH },
165 { "LockGroup", ACTION_TYPE_GROUP_LOCK },
166 { "MovePtr", ACTION_TYPE_PTR_MOVE },
167 { "MovePointer", ACTION_TYPE_PTR_MOVE },
168 { "PtrBtn", ACTION_TYPE_PTR_BUTTON },
169 { "PointerButton", ACTION_TYPE_PTR_BUTTON },
170 { "LockPtrBtn", ACTION_TYPE_PTR_LOCK },
171 { "LockPtrButton", ACTION_TYPE_PTR_LOCK },
172 { "LockPointerButton", ACTION_TYPE_PTR_LOCK },
173 { "LockPointerBtn", ACTION_TYPE_PTR_LOCK },
174 { "SetPtrDflt", ACTION_TYPE_PTR_DEFAULT },
175 { "SetPointerDefault", ACTION_TYPE_PTR_DEFAULT },
176 { "Terminate", ACTION_TYPE_TERMINATE },
177 { "TerminateServer", ACTION_TYPE_TERMINATE },
178 { "SwitchScreen", ACTION_TYPE_SWITCH_VT },
179 { "SetControls", ACTION_TYPE_CTRL_SET },
180 { "LockControls", ACTION_TYPE_CTRL_LOCK },
181 { "RedirectKey", ACTION_TYPE_KEY_REDIRECT },
182 { "Redirect", ACTION_TYPE_KEY_REDIRECT },
183 { "Private", ACTION_TYPE_PRIVATE },
184 /* deprecated actions below here - unused */
185 { "ISOLock", ACTION_TYPE_NONE },
186 { "ActionMessage", ACTION_TYPE_NONE },
187 { "MessageAction", ACTION_TYPE_NONE },
188 { "Message", ACTION_TYPE_NONE },
189 { "DeviceBtn", ACTION_TYPE_NONE },
190 { "DevBtn", ACTION_TYPE_NONE },
191 { "DevButton", ACTION_TYPE_NONE },
192 { "DeviceButton", ACTION_TYPE_NONE },
193 { "LockDeviceBtn", ACTION_TYPE_NONE },
194 { "LockDevBtn", ACTION_TYPE_NONE },
195 { "LockDevButton", ACTION_TYPE_NONE },
196 { "LockDeviceButton", ACTION_TYPE_NONE },
197 { "DeviceValuator", ACTION_TYPE_NONE },
198 { "DevVal", ACTION_TYPE_NONE },
199 { "DeviceVal", ACTION_TYPE_NONE },
200 { "DevValuator", ACTION_TYPE_NONE },
204 const LookupEntry symInterpretMatchMaskNames[] = {
205 { "NoneOf", XkbSI_NoneOf },
206 { "AnyOfOrNone", XkbSI_AnyOfOrNone },
207 { "AnyOf", XkbSI_AnyOf },
208 { "AllOf", XkbSI_AllOf },
209 { "Exactly", XkbSI_Exactly },
212 #define BUFFER_SIZE 1024
215 GetBuffer(size_t size)
217 static char buffer[BUFFER_SIZE];
221 if (size >= BUFFER_SIZE)
224 if (BUFFER_SIZE - next <= size)
227 rtrn = &buffer[next];
234 * Get a vmod name's text, where the vmod index is zero based
235 * (0..XKB_NUM_VIRTUAL_MODS-1).
238 VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
242 const char *tmp = NULL;
245 if (ndx >= XKB_NUM_VIRTUAL_MODS)
248 tmp = xkb_atom_text(keymap->ctx, keymap->vmod_names[ndx]);
251 snprintf(buf, sizeof(buf) - 1, "%d", ndx);
255 len = strlen(tmp) + 1;
256 if (len >= BUFFER_SIZE)
257 len = BUFFER_SIZE - 1;
259 rtrn = GetBuffer(len);
260 strncpy(rtrn, tmp, len);
265 /* Get a mod mask's text, where the mask is in rmods+vmods format. */
267 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
271 xkb_mod_mask_t rmask, vmask;
273 const char *mm = NULL;
275 char buf[BUFFER_SIZE];
277 rmask = cmask & 0xff;
278 vmask = cmask >> XKB_NUM_CORE_MODS;
280 if (rmask == 0 && vmask == 0)
284 mm = ModMaskText(rmask);
291 for (i = 0, bit = 1; i < XKB_NUM_VIRTUAL_MODS && rem > 1; i++, bit <<=
296 len = snprintf(str, rem, "%s%s",
297 (str != buf) ? "+" : "",
298 VModIndexText(keymap, i));
308 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
310 if (len >= BUFFER_SIZE)
311 len = BUFFER_SIZE - 1;
313 rtrn = GetBuffer(len + 1);
316 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
317 (mm && str ? "+" : ""), (str ? str : ""));
324 * The indices used for the legacy core modifiers is derived from
325 * the order of the names in this table. It matches the values
326 * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
329 static const char *modNames[XKB_NUM_CORE_MODS] = {
341 ModNameToIndex(const char *name)
345 for (i = 0; i < XKB_NUM_CORE_MODS; i++)
346 if (istreq(name, modNames[i]))
349 return XKB_MOD_INVALID;
353 ModIndexToName(xkb_mod_index_t ndx)
355 if (ndx < XKB_NUM_CORE_MODS)
356 return modNames[ndx];
361 ModIndexText(xkb_mod_index_t ndx)
366 name = ModIndexToName(ndx);
370 if (ndx == XKB_MOD_INVALID)
374 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
379 /* Gets the text for the real modifiers only. */
381 ModMaskText(xkb_mod_mask_t mask)
387 if ((mask & 0xff) == 0xff)
390 if ((mask & 0xff) == 0)
394 buf = GetBuffer(rem);
397 for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) {
403 len = snprintf(str, rem, "%s%s",
404 (str != buf ? "+" : ""), modNames[i]);
413 ActionTypeText(unsigned type)
415 const char *name = LookupValue(actionTypeNames, type);
416 return name ? name : "Private";
420 KeysymText(xkb_keysym_t sym)
422 static char buffer[64];
424 xkb_keysym_get_name(sym, buffer, sizeof buffer);
430 KeyNameText(const char name[XKB_KEY_NAME_LENGTH])
437 strncpy(&buf[1], name, 4);
447 SIMatchText(unsigned type)
452 type &= XkbSI_OpMask;
454 name = LookupValue(symInterpretMatchMaskNames, type);
459 snprintf(buf, 40, "0x%x", type & XkbSI_OpMask);