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 ********************************************************/
33 LookupString(const LookupEntry tab[], const char *string,
34 unsigned int *value_rtrn)
39 for (const LookupEntry *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 for (const LookupEntry *entry = tab; entry->name; entry++)
53 if (entry->value == value)
59 const LookupEntry ctrlMaskNames[] = {
60 { "RepeatKeys", CONTROL_REPEAT },
61 { "Repeat", CONTROL_REPEAT },
62 { "AutoRepeat", CONTROL_REPEAT },
63 { "SlowKeys", CONTROL_SLOW },
64 { "BounceKeys", CONTROL_DEBOUNCE },
65 { "StickyKeys", CONTROL_STICKY },
66 { "MouseKeys", CONTROL_MOUSEKEYS },
67 { "MouseKeysAccel", CONTROL_MOUSEKEYS_ACCEL },
68 { "AccessXKeys", CONTROL_AX },
69 { "AccessXTimeout", CONTROL_AX_TIMEOUT },
70 { "AccessXFeedback", CONTROL_AX_FEEDBACK },
71 { "AudibleBell", CONTROL_BELL },
72 { "IgnoreGroupLock", CONTROL_IGNORE_GROUP_LOCK },
73 { "all", CONTROL_ALL },
80 const LookupEntry modComponentMaskNames[] = {
81 { "base", XKB_STATE_MODS_DEPRESSED },
82 { "latched", XKB_STATE_MODS_LATCHED },
83 { "locked", XKB_STATE_MODS_LOCKED },
84 { "effective", XKB_STATE_MODS_EFFECTIVE },
85 { "compat", XKB_STATE_MODS_EFFECTIVE },
86 { "any", XKB_STATE_MODS_EFFECTIVE },
91 const LookupEntry groupComponentMaskNames[] = {
92 { "base", XKB_STATE_LAYOUT_DEPRESSED },
93 { "latched", XKB_STATE_LAYOUT_LATCHED },
94 { "locked", XKB_STATE_LAYOUT_LOCKED },
95 { "effective", XKB_STATE_LAYOUT_EFFECTIVE },
96 { "any", XKB_STATE_LAYOUT_EFFECTIVE },
101 const LookupEntry groupMaskNames[] = {
115 const LookupEntry groupNames[] = {
127 const LookupEntry levelNames[] = {
139 const LookupEntry buttonNames[] = {
149 const LookupEntry useModMapValueNames[] = {
157 const LookupEntry actionTypeNames[] = {
158 { "NoAction", ACTION_TYPE_NONE },
159 { "SetMods", ACTION_TYPE_MOD_SET },
160 { "LatchMods", ACTION_TYPE_MOD_LATCH },
161 { "LockMods", ACTION_TYPE_MOD_LOCK },
162 { "SetGroup", ACTION_TYPE_GROUP_SET },
163 { "LatchGroup", ACTION_TYPE_GROUP_LATCH },
164 { "LockGroup", ACTION_TYPE_GROUP_LOCK },
165 { "MovePtr", ACTION_TYPE_PTR_MOVE },
166 { "MovePointer", ACTION_TYPE_PTR_MOVE },
167 { "PtrBtn", ACTION_TYPE_PTR_BUTTON },
168 { "PointerButton", ACTION_TYPE_PTR_BUTTON },
169 { "LockPtrBtn", ACTION_TYPE_PTR_LOCK },
170 { "LockPtrButton", ACTION_TYPE_PTR_LOCK },
171 { "LockPointerButton", ACTION_TYPE_PTR_LOCK },
172 { "LockPointerBtn", ACTION_TYPE_PTR_LOCK },
173 { "SetPtrDflt", ACTION_TYPE_PTR_DEFAULT },
174 { "SetPointerDefault", ACTION_TYPE_PTR_DEFAULT },
175 { "Terminate", ACTION_TYPE_TERMINATE },
176 { "TerminateServer", ACTION_TYPE_TERMINATE },
177 { "SwitchScreen", ACTION_TYPE_SWITCH_VT },
178 { "SetControls", ACTION_TYPE_CTRL_SET },
179 { "LockControls", ACTION_TYPE_CTRL_LOCK },
180 { "Private", ACTION_TYPE_PRIVATE },
181 /* deprecated actions below here - unused */
182 { "RedirectKey", ACTION_TYPE_NONE },
183 { "Redirect", ACTION_TYPE_NONE },
184 { "ISOLock", ACTION_TYPE_NONE },
185 { "ActionMessage", ACTION_TYPE_NONE },
186 { "MessageAction", ACTION_TYPE_NONE },
187 { "Message", ACTION_TYPE_NONE },
188 { "DeviceBtn", ACTION_TYPE_NONE },
189 { "DevBtn", ACTION_TYPE_NONE },
190 { "DevButton", ACTION_TYPE_NONE },
191 { "DeviceButton", ACTION_TYPE_NONE },
192 { "LockDeviceBtn", ACTION_TYPE_NONE },
193 { "LockDevBtn", ACTION_TYPE_NONE },
194 { "LockDevButton", ACTION_TYPE_NONE },
195 { "LockDeviceButton", ACTION_TYPE_NONE },
196 { "DeviceValuator", ACTION_TYPE_NONE },
197 { "DevVal", ACTION_TYPE_NONE },
198 { "DeviceVal", ACTION_TYPE_NONE },
199 { "DevValuator", ACTION_TYPE_NONE },
203 const LookupEntry symInterpretMatchMaskNames[] = {
204 { "NoneOf", MATCH_NONE },
205 { "AnyOfOrNone", MATCH_ANY_OR_NONE },
206 { "AnyOf", MATCH_ANY },
207 { "AllOf", MATCH_ALL },
208 { "Exactly", MATCH_EXACTLY },
213 ModIndexText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
216 if (ndx == XKB_MOD_INVALID)
219 if (ndx >= mods->num_mods)
222 return xkb_atom_text(ctx, mods->mods[ndx].name);
226 ActionTypeText(enum xkb_action_type type)
228 const char *name = LookupValue(actionTypeNames, type);
229 return name ? name : "Private";
233 KeysymText(struct xkb_context *ctx, xkb_keysym_t sym)
235 char *buffer = xkb_context_get_buffer(ctx, 64);
236 xkb_keysym_get_name(sym, buffer, 64);
241 KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
243 const char *sname = xkb_atom_text(ctx, name);
244 size_t len = strlen_safe(sname) + 3;
245 char *buf = xkb_context_get_buffer(ctx, len);
246 snprintf(buf, len, "<%s>", strempty(sname));
251 SIMatchText(enum xkb_match_operation type)
253 return LookupValue(symInterpretMatchMaskNames, type);
257 ModMaskText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
260 char buf[1024] = {0};
263 const struct xkb_mod *mod;
268 if (mask == MOD_REAL_MASK_ALL)
271 xkb_mods_enumerate(i, mod, mods) {
274 if (!(mask & (1u << i)))
277 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
279 xkb_atom_text(ctx, mod->name));
280 if (ret <= 0 || pos + ret >= sizeof(buf))
286 return strncpy(xkb_context_get_buffer(ctx, pos + 1), buf, pos + 1);
290 LedStateMaskText(struct xkb_context *ctx, enum xkb_state_component mask)
292 char buf[1024] = {0};
298 for (unsigned i = 0; mask; i++) {
301 if (!(mask & (1u << i)))
306 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
308 LookupValue(modComponentMaskNames, 1u << i));
309 if (ret <= 0 || pos + ret >= sizeof(buf))
315 return strncpy(xkb_context_get_buffer(ctx, pos + 1), buf, pos + 1);
319 ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
321 char buf[1024] = {0};
327 if (mask == CONTROL_ALL)
330 for (unsigned i = 0; mask; i++) {
333 if (!(mask & (1u << i)))
338 ret = snprintf(buf + pos, sizeof(buf) - pos, "%s%s",
340 LookupValue(ctrlMaskNames, 1u << i));
341 if (ret <= 0 || pos + ret >= sizeof(buf))
347 return strncpy(xkb_context_get_buffer(ctx, pos + 1), buf, pos + 1);