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(struct xkb_context *ctx, const struct xkb_mod_set *mods,
213 if (ndx == XKB_MOD_INVALID)
216 if (ndx >= darray_size(mods->mods))
219 return xkb_atom_text(ctx, darray_item(mods->mods, ndx).name);
223 ActionTypeText(enum xkb_action_type type)
225 const char *name = LookupValue(actionTypeNames, type);
226 return name ? name : "Private";
230 KeysymText(struct xkb_context *ctx, xkb_keysym_t sym)
232 char *buffer = xkb_context_get_buffer(ctx, 64);
233 xkb_keysym_get_name(sym, buffer, 64);
238 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
240 const char *sname = xkb_atom_text(ctx, name);
241 size_t len = strlen_safe(sname) + 3;
242 char *buf = xkb_context_get_buffer(ctx, len);
243 snprintf(buf, len, "<%s>", strempty(sname));
248 SIMatchText(enum xkb_match_operation type)
250 return LookupValue(symInterpretMatchMaskNames, type);
254 ModMaskText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
260 const struct xkb_mod *mod;
265 if (mask == MOD_REAL_MASK_ALL)
268 xkb_mods_enumerate(i, mod, mods) {
271 if (!(mask & (1u << i)))
274 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
276 xkb_atom_text(ctx, mod->name));
277 if (ret <= 0 || pos + ret >= sizeof(buf))
283 return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
287 LedStateMaskText(struct xkb_context *ctx, enum xkb_state_component mask)
295 for (unsigned i = 0; mask; i++) {
298 if (!(mask & (1u << i)))
303 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
305 LookupValue(modComponentMaskNames, 1u << i));
306 if (ret <= 0 || pos + ret >= sizeof(buf))
312 return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
316 ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
324 if (mask == CONTROL_ALL)
327 for (unsigned i = 0; mask; i++) {
330 if (!(mask & (1u << i)))
335 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
337 LookupValue(ctrlMaskNames, 1u << i));
338 if (ret <= 0 || pos + ret >= sizeof(buf))
344 return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);