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)
37 for (const LookupEntry *entry = tab; entry->name; entry++) {
38 if (istreq(entry->name, string)) {
39 *value_rtrn = entry->value;
48 LookupValue(const LookupEntry tab[], unsigned int value)
50 for (const LookupEntry *entry = tab; entry->name; entry++)
51 if (entry->value == value)
57 const LookupEntry ctrlMaskNames[] = {
58 { "RepeatKeys", CONTROL_REPEAT },
59 { "Repeat", CONTROL_REPEAT },
60 { "AutoRepeat", CONTROL_REPEAT },
61 { "SlowKeys", CONTROL_SLOW },
62 { "BounceKeys", CONTROL_DEBOUNCE },
63 { "StickyKeys", CONTROL_STICKY },
64 { "MouseKeys", CONTROL_MOUSEKEYS },
65 { "MouseKeysAccel", CONTROL_MOUSEKEYS_ACCEL },
66 { "AccessXKeys", CONTROL_AX },
67 { "AccessXTimeout", CONTROL_AX_TIMEOUT },
68 { "AccessXFeedback", CONTROL_AX_FEEDBACK },
69 { "AudibleBell", CONTROL_BELL },
70 { "IgnoreGroupLock", CONTROL_IGNORE_GROUP_LOCK },
71 { "all", CONTROL_ALL },
78 const LookupEntry modComponentMaskNames[] = {
79 { "base", XKB_STATE_MODS_DEPRESSED },
80 { "latched", XKB_STATE_MODS_LATCHED },
81 { "locked", XKB_STATE_MODS_LOCKED },
82 { "effective", XKB_STATE_MODS_EFFECTIVE },
83 { "compat", XKB_STATE_MODS_EFFECTIVE },
84 { "any", XKB_STATE_MODS_EFFECTIVE },
89 const LookupEntry groupComponentMaskNames[] = {
90 { "base", XKB_STATE_LAYOUT_DEPRESSED },
91 { "latched", XKB_STATE_LAYOUT_LATCHED },
92 { "locked", XKB_STATE_LAYOUT_LOCKED },
93 { "effective", XKB_STATE_LAYOUT_EFFECTIVE },
94 { "any", XKB_STATE_LAYOUT_EFFECTIVE },
99 const LookupEntry groupMaskNames[] = {
113 const LookupEntry groupNames[] = {
125 const LookupEntry levelNames[] = {
137 const LookupEntry buttonNames[] = {
147 const LookupEntry useModMapValueNames[] = {
155 const LookupEntry actionTypeNames[] = {
156 { "NoAction", ACTION_TYPE_NONE },
157 { "SetMods", ACTION_TYPE_MOD_SET },
158 { "LatchMods", ACTION_TYPE_MOD_LATCH },
159 { "LockMods", ACTION_TYPE_MOD_LOCK },
160 { "SetGroup", ACTION_TYPE_GROUP_SET },
161 { "LatchGroup", ACTION_TYPE_GROUP_LATCH },
162 { "LockGroup", ACTION_TYPE_GROUP_LOCK },
163 { "MovePtr", ACTION_TYPE_PTR_MOVE },
164 { "MovePointer", ACTION_TYPE_PTR_MOVE },
165 { "PtrBtn", ACTION_TYPE_PTR_BUTTON },
166 { "PointerButton", ACTION_TYPE_PTR_BUTTON },
167 { "LockPtrBtn", ACTION_TYPE_PTR_LOCK },
168 { "LockPtrButton", ACTION_TYPE_PTR_LOCK },
169 { "LockPointerButton", ACTION_TYPE_PTR_LOCK },
170 { "LockPointerBtn", ACTION_TYPE_PTR_LOCK },
171 { "SetPtrDflt", ACTION_TYPE_PTR_DEFAULT },
172 { "SetPointerDefault", ACTION_TYPE_PTR_DEFAULT },
173 { "Terminate", ACTION_TYPE_TERMINATE },
174 { "TerminateServer", ACTION_TYPE_TERMINATE },
175 { "SwitchScreen", ACTION_TYPE_SWITCH_VT },
176 { "SetControls", ACTION_TYPE_CTRL_SET },
177 { "LockControls", ACTION_TYPE_CTRL_LOCK },
178 { "Private", ACTION_TYPE_PRIVATE },
179 /* deprecated actions below here - unused */
180 { "RedirectKey", ACTION_TYPE_NONE },
181 { "Redirect", ACTION_TYPE_NONE },
182 { "ISOLock", ACTION_TYPE_NONE },
183 { "ActionMessage", ACTION_TYPE_NONE },
184 { "MessageAction", ACTION_TYPE_NONE },
185 { "Message", ACTION_TYPE_NONE },
186 { "DeviceBtn", ACTION_TYPE_NONE },
187 { "DevBtn", ACTION_TYPE_NONE },
188 { "DevButton", ACTION_TYPE_NONE },
189 { "DeviceButton", ACTION_TYPE_NONE },
190 { "LockDeviceBtn", ACTION_TYPE_NONE },
191 { "LockDevBtn", ACTION_TYPE_NONE },
192 { "LockDevButton", ACTION_TYPE_NONE },
193 { "LockDeviceButton", ACTION_TYPE_NONE },
194 { "DeviceValuator", ACTION_TYPE_NONE },
195 { "DevVal", ACTION_TYPE_NONE },
196 { "DeviceVal", ACTION_TYPE_NONE },
197 { "DevValuator", ACTION_TYPE_NONE },
201 const LookupEntry symInterpretMatchMaskNames[] = {
202 { "NoneOf", MATCH_NONE },
203 { "AnyOfOrNone", MATCH_ANY_OR_NONE },
204 { "AnyOf", MATCH_ANY },
205 { "AllOf", MATCH_ALL },
206 { "Exactly", MATCH_EXACTLY },
210 ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
212 if (ndx == XKB_MOD_INVALID)
215 if (ndx >= darray_size(keymap->mods))
218 return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, ndx).name);
222 ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name,
226 const struct xkb_mod *mod;
228 darray_enumerate(i, mod, keymap->mods)
229 if ((mod->type & type) && name == mod->name)
232 return XKB_MOD_INVALID;
236 ActionTypeText(enum xkb_action_type type)
238 const char *name = LookupValue(actionTypeNames, type);
239 return name ? name : "Private";
243 KeysymText(struct xkb_context *ctx, xkb_keysym_t sym)
245 char *buffer = xkb_context_get_buffer(ctx, 64);
246 xkb_keysym_get_name(sym, buffer, 64);
251 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
253 const char *sname = xkb_atom_text(ctx, name);
254 size_t len = strlen_safe(sname) + 3;
255 char *buf = xkb_context_get_buffer(ctx, len);
256 snprintf(buf, len, "<%s>", strempty(sname));
261 SIMatchText(enum xkb_match_operation type)
263 return LookupValue(symInterpretMatchMaskNames, type);
267 ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
272 const struct xkb_mod *mod;
277 if (mask == MOD_REAL_MASK_ALL)
280 darray_enumerate(i, mod, keymap->mods) {
283 if (!(mask & (1 << i)))
286 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
288 xkb_atom_text(keymap->ctx, mod->name));
289 if (ret <= 0 || pos + ret >= sizeof(buf))
295 return strcpy(xkb_context_get_buffer(keymap->ctx, pos + 1), buf);
299 LedStateMaskText(struct xkb_context *ctx, enum xkb_state_component mask)
307 for (unsigned i = 0; mask; i++) {
310 if (!(mask & (1 << i)))
315 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
317 LookupValue(modComponentMaskNames, 1 << i));
318 if (ret <= 0 || pos + ret >= sizeof(buf))
324 return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
328 ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
336 if (mask == CONTROL_ALL)
339 for (unsigned i = 0; mask; i++) {
342 if (!(mask & (1 << i)))
347 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
349 LookupValue(ctrlMaskNames, 1 << i));
350 if (ret <= 0 || pos + ret >= sizeof(buf))
356 return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);