2 * Copyright 1985, 1987, 1990, 1998 The Open Group
3 * Copyright 2008 Dan Nicholson
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * Except as contained in this notice, the names of the authors or their
23 * institutions shall not be used in advertising or otherwise to promote the
24 * sale, use or other dealings in this Software without prior written
25 * authorization from the authors.
28 /************************************************************
29 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
31 * Permission to use, copy, modify, and distribute this
32 * software and its documentation for any purpose and without
33 * fee is hereby granted, provided that the above copyright
34 * notice appear in all copies and that both that copyright
35 * notice and this permission notice appear in supporting
36 * documentation, and that the name of Silicon Graphics not be
37 * used in advertising or publicity pertaining to distribution
38 * of the software without specific prior written permission.
39 * Silicon Graphics makes no representation about the suitability
40 * of this software for any purpose. It is provided "as is"
41 * without any express or implied warranty.
43 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
44 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
46 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
47 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
48 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
49 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
50 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 ********************************************************/
55 * Copyright © 2012 Intel Corporation
57 * Permission is hereby granted, free of charge, to any person obtaining a
58 * copy of this software and associated documentation files (the "Software"),
59 * to deal in the Software without restriction, including without limitation
60 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
61 * and/or sell copies of the Software, and to permit persons to whom the
62 * Software is furnished to do so, subject to the following conditions:
64 * The above copyright notice and this permission notice (including the next
65 * paragraph) shall be included in all copies or substantial portions of the
68 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
71 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
73 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
74 * DEALINGS IN THE SOFTWARE.
76 * Author: Daniel Stone <daniel@fooishbar.org>
85 #include <X11/extensions/XKB.h>
87 #include "xkbcommon/xkbcommon.h"
92 typedef uint32_t xkb_level_index_t;
93 typedef uint32_t xkb_atom_t;
95 #define XKB_ATOM_NONE 0
96 #define XKB_LEVEL_INVALID 0xffffffff
98 #define XKB_KEY_NAME_LENGTH 4
100 /* These should all be dynamic. */
101 #define XKB_NUM_GROUPS 4
102 #define XKB_NUM_INDICATORS 32
103 #define XKB_NUM_VIRTUAL_MODS 16
104 #define XKB_NUM_CORE_MODS 8
109 ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx,
110 enum xkb_log_level level,
111 const char *fmt, va_list args);
112 enum xkb_log_level log_level;
116 darray(char *) includes;
117 darray(char *) failed_includes;
119 /* xkbcomp needs to assign sequential IDs to XkbFile's it creates. */
122 struct atom_table *atom_table;
126 * Legacy names for the components of an XKB keymap, also known as KcCGST.
128 struct xkb_component_names {
136 xkb_mod_mask_t mods; /* original real+virtual mods in definition */
137 xkb_mod_mask_t mask; /* computed effective mask */
140 struct xkb_mod_action {
143 struct xkb_mods mods;
146 struct xkb_group_action {
152 struct xkb_controls_action {
158 struct xkb_pointer_default_action {
165 struct xkb_switch_screen_action {
171 struct xkb_redirect_key_action {
173 xkb_keycode_t new_kc;
180 struct xkb_pointer_action {
187 struct xkb_pointer_button_action {
194 /* Instead of non-sequential XkbSA_XFree86Private. */
195 #define PrivateAction (XkbSA_LastAction + 1)
197 struct xkb_private_action {
203 struct xkb_mod_action mods;
204 struct xkb_group_action group;
205 struct xkb_controls_action ctrls;
206 struct xkb_pointer_default_action dflt;
207 struct xkb_switch_screen_action screen;
208 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
209 struct xkb_pointer_action ptr;
210 struct xkb_pointer_button_action btn;
211 struct xkb_private_action priv;
215 struct xkb_kt_map_entry {
216 xkb_level_index_t level;
217 struct xkb_mods mods;
218 struct xkb_mods preserve;
221 struct xkb_key_type {
222 struct xkb_mods mods;
223 xkb_level_index_t num_levels;
224 struct xkb_kt_map_entry *map;
225 unsigned int num_entries;
227 xkb_atom_t *level_names;
230 struct xkb_sym_interpret {
235 xkb_mod_index_t virtual_mod;
236 union xkb_action act;
239 struct xkb_indicator_map {
241 unsigned char which_groups;
243 unsigned char which_mods;
244 struct xkb_mods mods;
248 struct xkb_key_alias {
249 char real[XKB_KEY_NAME_LENGTH];
250 char alias[XKB_KEY_NAME_LENGTH];
253 struct xkb_controls {
254 unsigned char groups_wrap;
255 struct xkb_mods internal;
256 struct xkb_mods ignore_lock;
257 unsigned short repeat_delay;
258 unsigned short repeat_interval;
259 unsigned short slow_keys_delay;
260 unsigned short debounce_delay;
261 unsigned short ax_options;
262 unsigned short ax_timeout;
263 unsigned short axt_opts_mask;
264 unsigned short axt_opts_values;
265 unsigned int axt_ctrls_mask;
266 unsigned int axt_ctrls_values;
270 char name[XKB_KEY_NAME_LENGTH];
272 unsigned char explicit;
274 unsigned char modmap;
275 xkb_mod_mask_t vmodmap;
279 union xkb_action *actions;
281 unsigned kt_index[XKB_NUM_GROUPS];
283 xkb_group_index_t num_groups;
284 /* How many levels the largest group has. */
285 xkb_level_index_t width;
287 uint8_t out_of_range_group_action;
288 xkb_group_index_t out_of_range_group_number;
290 /* per level/group index into 'syms' */
292 /* per level/group */
293 unsigned int *num_syms;
294 darray(xkb_keysym_t) syms;
297 /* Common keyboard description structure */
299 struct xkb_context *ctx;
302 enum xkb_map_compile_flags flags;
304 unsigned int enabled_ctrls;
306 xkb_keycode_t min_key_code;
307 xkb_keycode_t max_key_code;
309 darray(struct xkb_key) keys;
311 /* aliases in no particular order */
312 darray(struct xkb_key_alias) key_aliases;
314 struct xkb_key_type *types;
315 unsigned int num_types;
317 darray(struct xkb_sym_interpret) sym_interpret;
319 /* vmod -> mod mapping */
320 xkb_mod_mask_t vmods[XKB_NUM_VIRTUAL_MODS];
321 xkb_atom_t vmod_names[XKB_NUM_VIRTUAL_MODS];
323 /* Number of groups in the key with the most groups. */
324 xkb_group_index_t num_groups;
325 xkb_atom_t group_names[XKB_NUM_GROUPS];
327 struct xkb_indicator_map indicators[XKB_NUM_INDICATORS];
329 char *keycodes_section_name;
330 char *symbols_section_name;
331 char *types_section_name;
332 char *compat_section_name;
335 static inline struct xkb_key *
336 XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
338 return &darray_item(keymap->keys, kc);
341 static inline xkb_keycode_t
342 XkbKeyGetKeycode(struct xkb_keymap *keymap, struct xkb_key *key)
344 /* Hack to avoid having to keep the keycode inside the xkb_key. */
345 return (xkb_keycode_t)(key - keymap->keys.item);
348 #define xkb_foreach_key_from(iter, keymap, from) \
349 darray_foreach_from(iter, keymap->keys, from)
351 #define xkb_foreach_key(iter, keymap) \
352 xkb_foreach_key_from(iter, keymap, keymap->min_key_code)
354 static inline struct xkb_key_type *
355 XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
356 xkb_group_index_t group)
358 return &keymap->types[key->kt_index[group]];
361 static inline xkb_level_index_t
362 XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
363 xkb_group_index_t group)
365 return XkbKeyType(keymap, key, group)->num_levels;
368 static inline unsigned int
369 XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group,
370 xkb_level_index_t level)
372 return key->num_syms[group * key->width + level];
375 static inline xkb_keysym_t *
376 XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group,
377 xkb_level_index_t level)
379 return &darray_item(key->syms,
380 key->sym_index[group * key->width + level]);
383 static inline union xkb_action *
384 XkbKeyActionEntry(struct xkb_key *key, xkb_group_index_t group,
385 xkb_level_index_t level)
387 return &key->actions[key->width * group + level];
391 XkbKeycodeInRange(struct xkb_keymap *keymap, xkb_keycode_t kc)
393 return kc >= keymap->min_key_code && kc <= keymap->max_key_code;
397 xkb_map_new(struct xkb_context *ctx);
400 * Returns XKB_ATOM_NONE if @string was not previously interned,
401 * otherwise returns the atom.
404 xkb_atom_lookup(struct xkb_context *ctx, const char *string);
407 xkb_atom_intern(struct xkb_context *ctx, const char *string);
410 * If @string is dynamically allocated, free'd immediately after
411 * being interned, and not used afterwards, use this function
412 * instead of xkb_atom_intern to avoid some unnecessary allocations.
413 * The caller should not use or free the passed in string afterwards.
416 xkb_atom_steal(struct xkb_context *ctx, char *string);
419 xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom);
422 xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
425 xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc);
428 xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
429 xkb_group_index_t group);
432 xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
433 xkb_group_index_t group, xkb_level_index_t level,
434 const xkb_keysym_t **syms_out);
437 xkb_context_take_file_id(struct xkb_context *ctx);
440 xkb_keysym_is_lower(xkb_keysym_t keysym);
443 xkb_keysym_is_upper(xkb_keysym_t keysym);
446 xkb_keysym_is_keypad(xkb_keysym_t keysym);
448 ATTR_PRINTF(3, 4) void
449 xkb_log(struct xkb_context *ctx, enum xkb_log_level level,
450 const char *fmt, ...);
452 #define xkb_log_cond_level(ctx, level, ...) do { \
453 if (xkb_get_log_level(ctx) >= (level)) \
454 xkb_log((ctx), (level), __VA_ARGS__); \
457 #define xkb_log_cond_verbosity(ctx, level, vrb, ...) do { \
458 if (xkb_get_log_verbosity(ctx) >= (vrb)) \
459 xkb_log_cond_level((ctx), (level), __VA_ARGS__); \
463 * The format is not part of the argument list in order to avoid the
464 * "ISO C99 requires rest arguments to be used" warning when only the
465 * format is supplied without arguments. Not supplying it would still
466 * result in an error, though.
468 #define log_dbg(ctx, ...) \
469 xkb_log_cond_level((ctx), XKB_LOG_LEVEL_DEBUG, __VA_ARGS__)
470 #define log_info(ctx, ...) \
471 xkb_log_cond_level((ctx), XKB_LOG_LEVEL_INFO, __VA_ARGS__)
472 #define log_warn(ctx, ...) \
473 xkb_log_cond_level((ctx), XKB_LOG_LEVEL_WARNING, __VA_ARGS__)
474 #define log_err(ctx, ...) \
475 xkb_log_cond_level((ctx), XKB_LOG_LEVEL_ERROR, __VA_ARGS__)
476 #define log_wsgo(ctx, ...) \
477 xkb_log_cond_level((ctx), XKB_LOG_LEVEL_CRITICAL, __VA_ARGS__)
478 #define log_vrb(ctx, vrb, ...) \
479 xkb_log_cond_verbosity((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__)
481 #endif /* XKB_PRIV_H */