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 },
214 ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
221 const struct xkb_mod *mod;
226 if (mask == MOD_REAL_MASK_ALL)
232 darray_enumerate(i, mod, keymap->mods) {
233 if (!(mask & (1 << i)))
236 len = snprintf(str, rem, "%s%s",
237 (str != buf) ? "+" : "",
238 xkb_atom_text(keymap->ctx, mod->name));
248 if (len >= sizeof(buf))
249 len = sizeof(buf) - 1;
251 return strcpy(xkb_context_get_buffer(keymap->ctx, len + 1), str);
256 ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
258 if (ndx == XKB_MOD_INVALID)
261 if (ndx >= darray_size(keymap->mods))
264 return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, ndx).name);
268 ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name,
272 const struct xkb_mod *mod;
274 darray_enumerate(i, mod, keymap->mods)
275 if ((mod->type & type) && name == mod->name)
278 return XKB_MOD_INVALID;
282 ActionTypeText(unsigned type)
284 const char *name = LookupValue(actionTypeNames, type);
285 return name ? name : "Private";
289 KeysymText(struct xkb_context *ctx, xkb_keysym_t sym)
291 char *buffer = xkb_context_get_buffer(ctx, 64);
292 xkb_keysym_get_name(sym, buffer, 64);
297 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
299 const char *sname = xkb_atom_text(ctx, name);
300 size_t len = strlen(sname) + 3;
301 char *buf = xkb_context_get_buffer(ctx, len);
302 snprintf(buf, len, "<%s>", sname);
307 SIMatchText(enum xkb_match_operation type)
309 return LookupValue(symInterpretMatchMaskNames, type);