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 mod mask's text, where the mask is in rmods+vmods format. */
236 VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask)
239 xkb_mod_mask_t rmask, vmask;
241 const char *mm = NULL;
243 char buf[BUFFER_SIZE];
244 const struct xkb_mod *mod;
247 vmask = mask & (~0xff);
249 if (rmask == 0 && vmask == 0)
253 mm = ModMaskText(keymap, rmask);
262 darray_enumerate(i, mod, keymap->mods) {
263 if (mod->type != MOD_VIRT || !(vmask & (1 << i)))
266 len = snprintf(str, rem, "%s%s",
267 (str != buf) ? "+" : "",
268 xkb_atom_text(keymap->ctx, mod->name));
278 len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
280 if (len >= BUFFER_SIZE)
281 len = BUFFER_SIZE - 1;
283 rtrn = GetBuffer(len + 1);
286 snprintf(rtrn, len + 1, "%s%s%s", (mm ? mm : ""),
287 (mm && str ? "+" : ""), (str ? str : ""));
293 ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name)
296 const struct xkb_mod *mod;
298 darray_enumerate(i, mod, keymap->mods)
299 if (mod->type == MOD_REAL && name == mod->name)
302 return XKB_MOD_INVALID;
306 ModIndexToName(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
308 if (ndx >= darray_size(keymap->mods) ||
309 darray_item(keymap->mods, ndx).type != MOD_REAL)
310 return XKB_ATOM_NONE;
312 return darray_item(keymap->mods, ndx).name;
316 ModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
320 name = ModIndexToName(keymap, ndx);
322 return xkb_atom_text(keymap->ctx, name);
324 if (ndx == XKB_MOD_INVALID)
331 ModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask)
336 const struct xkb_mod *mod;
338 if ((mask & 0xff) == 0xff)
341 if ((mask & 0xff) == 0)
345 buf = GetBuffer(rem);
348 darray_enumerate(i, mod, keymap->mods) {
349 if (mod->type != MOD_REAL || !(mask & (1 << i)))
352 len = snprintf(str, rem, "%s%s",
353 (str != buf ? "+" : ""),
354 ModIndexText(keymap, i));
366 ActionTypeText(unsigned type)
368 const char *name = LookupValue(actionTypeNames, type);
369 return name ? name : "Private";
373 KeysymText(xkb_keysym_t sym)
375 static char buffer[64];
377 xkb_keysym_get_name(sym, buffer, sizeof buffer);
383 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
385 const char *sname = xkb_atom_text(ctx, name);
386 size_t len = strlen(sname) + 3;
387 char *buf = GetBuffer(len);
388 snprintf(buf, len, "<%s>", sname);
393 SIMatchText(enum xkb_match_operation type)
398 type &= MATCH_OP_MASK;
400 name = LookupValue(symInterpretMatchMaskNames, type);
405 snprintf(buf, 40, "0x%x", type);