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];
234 /* Get a vmod name's text, where the vmod index is zero based. */
236 VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
238 if (ndx >= darray_size(keymap->vmods))
240 return xkb_atom_text(keymap->ctx,
241 darray_item(keymap->vmods, ndx).name);
244 /* Get a mod mask's text, where the mask is in rmods+vmods format. */
246 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
249 xkb_mod_mask_t rmask, vmask;
251 const char *mm = NULL;
253 char buf[BUFFER_SIZE];
255 rmask = cmask & 0xff;
256 vmask = cmask >> XKB_NUM_CORE_MODS;
258 if (rmask == 0 && vmask == 0)
262 mm = ModMaskText(rmask);
269 for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) {
270 if (!(vmask & (1 << i)))
273 len = snprintf(str, rem, "%s%s",
274 (str != buf) ? "+" : "",
275 VModIndexText(keymap, i));
285 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
287 if (len >= BUFFER_SIZE)
288 len = BUFFER_SIZE - 1;
290 rtrn = GetBuffer(len + 1);
293 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
294 (mm && str ? "+" : ""), (str ? str : ""));
301 * The indices used for the legacy core modifiers is derived from
302 * the order of the names in this table. It matches the values
303 * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before
306 static const char *modNames[XKB_NUM_CORE_MODS] = {
318 ModNameToIndex(const char *name)
322 for (i = 0; i < XKB_NUM_CORE_MODS; i++)
323 if (istreq(name, modNames[i]))
326 return XKB_MOD_INVALID;
330 ModIndexToName(xkb_mod_index_t ndx)
332 if (ndx < XKB_NUM_CORE_MODS)
333 return modNames[ndx];
338 ModIndexText(xkb_mod_index_t ndx)
343 name = ModIndexToName(ndx);
347 if (ndx == XKB_MOD_INVALID)
351 snprintf(buf, 32, "ILLEGAL_%02x", ndx);
356 /* Gets the text for the real modifiers only. */
358 ModMaskText(xkb_mod_mask_t mask)
364 if ((mask & 0xff) == 0xff)
367 if ((mask & 0xff) == 0)
371 buf = GetBuffer(rem);
374 for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) {
380 len = snprintf(str, rem, "%s%s",
381 (str != buf ? "+" : ""), modNames[i]);
390 ActionTypeText(unsigned type)
392 const char *name = LookupValue(actionTypeNames, type);
393 return name ? name : "Private";
397 KeysymText(xkb_keysym_t sym)
399 static char buffer[64];
401 xkb_keysym_get_name(sym, buffer, sizeof buffer);
407 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
409 const char *sname = xkb_atom_text(ctx, name);
410 size_t len = strlen(sname) + 3;
411 char *buf = GetBuffer(len);
412 snprintf(buf, len, "<%s>", sname);
417 SIMatchText(enum xkb_match_operation type)
422 type &= MATCH_OP_MASK;
424 name = LookupValue(symInterpretMatchMaskNames, type);
429 snprintf(buf, 40, "0x%x", type);