1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
/************************************************************
* Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting
* documentation, and that the name of Silicon Graphics not be
* used in advertising or publicity pertaining to distribution
* of the software without specific prior written permission.
* Silicon Graphics makes no representation about the suitability
* of this software for any purpose. It is provided "as is"
* without any express or implied warranty.
*
* SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
* THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
********************************************************/
#include "keymap.h"
#include "text.h"
bool
LookupString(const LookupEntry tab[], const char *string,
unsigned int *value_rtrn)
{
const LookupEntry *entry;
if (!string)
return false;
for (entry = tab; entry->name; entry++) {
if (istreq(entry->name, string)) {
*value_rtrn = entry->value;
return true;
}
}
return false;
}
const char *
LookupValue(const LookupEntry tab[], unsigned int value)
{
const LookupEntry *entry;
for (entry = tab; entry->name; entry++)
if (entry->value == value)
return entry->name;
return NULL;
}
const LookupEntry ctrlMaskNames[] = {
{ "RepeatKeys", CONTROL_REPEAT },
{ "Repeat", CONTROL_REPEAT },
{ "AutoRepeat", CONTROL_REPEAT },
{ "SlowKeys", CONTROL_SLOW },
{ "BounceKeys", CONTROL_DEBOUNCE },
{ "StickyKeys", CONTROL_STICKY },
{ "MouseKeys", CONTROL_MOUSEKEYS },
{ "MouseKeysAccel", CONTROL_MOUSEKEYS_ACCEL },
{ "AccessXKeys", CONTROL_AX },
{ "AccessXTimeout", CONTROL_AX_TIMEOUT },
{ "AccessXFeedback", CONTROL_AX_FEEDBACK },
{ "AudibleBell", CONTROL_BELL },
{ "IgnoreGroupLock", CONTROL_IGNORE_GROUP_LOCK },
{ "all", CONTROL_ALL },
{ "none", 0 },
{ "Overlay1", 0 },
{ "Overlay2", 0 },
{ NULL, 0 }
};
const LookupEntry modComponentMaskNames[] = {
{"base", XKB_STATE_DEPRESSED},
{"latched", XKB_STATE_LATCHED},
{"locked", XKB_STATE_LOCKED},
{"effective", XKB_STATE_EFFECTIVE},
{"compat", XKB_STATE_EFFECTIVE},
{"any", XKB_STATE_EFFECTIVE},
{"none", 0},
{NULL, 0}
};
const LookupEntry groupComponentMaskNames[] = {
{"base", XKB_STATE_DEPRESSED},
{"latched", XKB_STATE_LATCHED},
{"locked", XKB_STATE_LOCKED},
{"effective", XKB_STATE_EFFECTIVE},
{"any", XKB_STATE_EFFECTIVE},
{"none", 0},
{NULL, 0}
};
const LookupEntry groupMaskNames[] = {
{"group1", 0x01},
{"group2", 0x02},
{"group3", 0x04},
{"group4", 0x08},
{"group5", 0x10},
{"group6", 0x20},
{"group7", 0x40},
{"group8", 0x80},
{"none", 0x00},
{"all", 0xff},
{NULL, 0}
};
const LookupEntry groupNames[] = {
{"group1", 1},
{"group2", 2},
{"group3", 3},
{"group4", 4},
{"group5", 5},
{"group6", 6},
{"group7", 7},
{"group8", 8},
{NULL, 0}
};
const LookupEntry levelNames[] = {
{ "level1", 1 },
{ "level2", 2 },
{ "level3", 3 },
{ "level4", 4 },
{ "level5", 5 },
{ "level6", 6 },
{ "level7", 7 },
{ "level8", 8 },
{ NULL, 0 }
};
const LookupEntry buttonNames[] = {
{ "button1", 1 },
{ "button2", 2 },
{ "button3", 3 },
{ "button4", 4 },
{ "button5", 5 },
{ "default", 0 },
{ NULL, 0 }
};
const LookupEntry useModMapValueNames[] = {
{ "levelone", 1 },
{ "level1", 1 },
{ "anylevel", 0 },
{ "any", 0 },
{ NULL, 0 }
};
const LookupEntry actionTypeNames[] = {
{ "NoAction", ACTION_TYPE_NONE },
{ "SetMods", ACTION_TYPE_MOD_SET },
{ "LatchMods", ACTION_TYPE_MOD_LATCH },
{ "LockMods", ACTION_TYPE_MOD_LOCK },
{ "SetGroup", ACTION_TYPE_GROUP_SET },
{ "LatchGroup", ACTION_TYPE_GROUP_LATCH },
{ "LockGroup", ACTION_TYPE_GROUP_LOCK },
{ "MovePtr", ACTION_TYPE_PTR_MOVE },
{ "MovePointer", ACTION_TYPE_PTR_MOVE },
{ "PtrBtn", ACTION_TYPE_PTR_BUTTON },
{ "PointerButton", ACTION_TYPE_PTR_BUTTON },
{ "LockPtrBtn", ACTION_TYPE_PTR_LOCK },
{ "LockPtrButton", ACTION_TYPE_PTR_LOCK },
{ "LockPointerButton", ACTION_TYPE_PTR_LOCK },
{ "LockPointerBtn", ACTION_TYPE_PTR_LOCK },
{ "SetPtrDflt", ACTION_TYPE_PTR_DEFAULT },
{ "SetPointerDefault", ACTION_TYPE_PTR_DEFAULT },
{ "Terminate", ACTION_TYPE_TERMINATE },
{ "TerminateServer", ACTION_TYPE_TERMINATE },
{ "SwitchScreen", ACTION_TYPE_SWITCH_VT },
{ "SetControls", ACTION_TYPE_CTRL_SET },
{ "LockControls", ACTION_TYPE_CTRL_LOCK },
{ "RedirectKey", ACTION_TYPE_KEY_REDIRECT },
{ "Redirect", ACTION_TYPE_KEY_REDIRECT },
{ "Private", ACTION_TYPE_PRIVATE },
/* deprecated actions below here - unused */
{ "ISOLock", ACTION_TYPE_NONE },
{ "ActionMessage", ACTION_TYPE_NONE },
{ "MessageAction", ACTION_TYPE_NONE },
{ "Message", ACTION_TYPE_NONE },
{ "DeviceBtn", ACTION_TYPE_NONE },
{ "DevBtn", ACTION_TYPE_NONE },
{ "DevButton", ACTION_TYPE_NONE },
{ "DeviceButton", ACTION_TYPE_NONE },
{ "LockDeviceBtn", ACTION_TYPE_NONE },
{ "LockDevBtn", ACTION_TYPE_NONE },
{ "LockDevButton", ACTION_TYPE_NONE },
{ "LockDeviceButton", ACTION_TYPE_NONE },
{ "DeviceValuator", ACTION_TYPE_NONE },
{ "DevVal", ACTION_TYPE_NONE },
{ "DeviceVal", ACTION_TYPE_NONE },
{ "DevValuator", ACTION_TYPE_NONE },
{ NULL, 0 },
};
const LookupEntry symInterpretMatchMaskNames[] = {
{ "NoneOf", MATCH_NONE },
{ "AnyOfOrNone", MATCH_ANY_OR_NONE },
{ "AnyOf", MATCH_ANY },
{ "AllOf", MATCH_ALL },
{ "Exactly", MATCH_EXACTLY },
};
#define BUFFER_SIZE 1024
static char *
GetBuffer(size_t size)
{
static char buffer[BUFFER_SIZE];
static size_t next;
char *rtrn;
if (size >= BUFFER_SIZE)
return NULL;
if (BUFFER_SIZE - next <= size)
next = 0;
rtrn = &buffer[next];
next += size;
return rtrn;
}
static const char *
mod_mask_text(const struct xkb_keymap *keymap, xkb_mod_mask_t mask,
enum mod_type type)
{
xkb_mod_index_t i;
xkb_mod_mask_t rmask, vmask;
size_t len;
ssize_t rem;
char *str;
char buf[BUFFER_SIZE];
const struct xkb_mod *mod;
rmask = (type & MOD_REAL ? mask : 0) & 0xff;
vmask = (type & MOD_VIRT ? mask : 0) & (~0xff);
if (rmask == 0 && vmask == 0)
return "none";
if (rmask == 0xff && vmask == 0)
return "all";
str = buf;
buf[0] = '\0';
rem = BUFFER_SIZE;
darray_enumerate(i, mod, keymap->mods) {
if (!(mod->type & type) || !(mask & (1 << i)))
continue;
len = snprintf(str, rem, "%s%s",
(str != buf) ? "+" : "",
xkb_atom_text(keymap->ctx, mod->name));
rem -= len;
str += len;
if (rem <= 1)
break;
}
str = buf;
len = strlen(str);
if (len >= BUFFER_SIZE)
len = BUFFER_SIZE - 1;
return strcpy(GetBuffer(len + 1), str);
}
const char *
ModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
{
return mod_mask_text(keymap, mask, MOD_REAL);
}
const char *
VModMaskText(const struct xkb_keymap *keymap, xkb_mod_mask_t mask)
{
return mod_mask_text(keymap, mask, MOD_BOTH);
}
static xkb_mod_index_t
mod_name_to_index(const struct xkb_keymap *keymap, xkb_atom_t name,
enum mod_type type)
{
xkb_mod_index_t i;
const struct xkb_mod *mod;
darray_enumerate(i, mod, keymap->mods)
if ((mod->type & type) && name == mod->name)
return i;
return XKB_MOD_INVALID;
}
xkb_mod_index_t
ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name)
{
return mod_name_to_index(keymap, name, MOD_REAL);
}
static xkb_mod_index_t
mod_index_to_name(const struct xkb_keymap *keymap, xkb_mod_index_t ndx,
enum mod_type type)
{
if (ndx >= darray_size(keymap->mods) ||
!(darray_item(keymap->mods, ndx).type & type))
return XKB_ATOM_NONE;
return darray_item(keymap->mods, ndx).name;
}
xkb_atom_t
ModIndexToName(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
{
return mod_index_to_name(keymap, ndx, MOD_REAL);
}
static const char *
mod_index_text(const struct xkb_keymap *keymap, xkb_mod_index_t ndx,
enum mod_type type)
{
xkb_atom_t name;
name = mod_index_to_name(keymap, ndx, type);
if (name)
return xkb_atom_text(keymap->ctx, name);
if (ndx == XKB_MOD_INVALID)
return "none";
return NULL;
}
const char *
ModIndexText(const struct xkb_keymap *keymap, xkb_mod_index_t ndx)
{
return mod_index_text(keymap, ndx, MOD_REAL);
}
const char *
ActionTypeText(unsigned type)
{
const char *name = LookupValue(actionTypeNames, type);
return name ? name : "Private";
}
const char *
KeysymText(xkb_keysym_t sym)
{
static char buffer[64];
xkb_keysym_get_name(sym, buffer, sizeof buffer);
return buffer;
}
const char *
KeyNameText(struct xkb_context *ctx, xkb_atom_t name)
{
const char *sname = xkb_atom_text(ctx, name);
size_t len = strlen(sname) + 3;
char *buf = GetBuffer(len);
snprintf(buf, len, "<%s>", sname);
return buf;
}
const char *
SIMatchText(enum xkb_match_operation type)
{
const char *name;
char *buf;
type &= MATCH_OP_MASK;
name = LookupValue(symInterpretMatchMaskNames, type);
if (name)
return name;
buf = GetBuffer(40);
snprintf(buf, 40, "0x%x", type);
return buf;
}
|