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>
86 #include <X11/extensions/XKB.h>
88 #include "xkbcommon/xkbcommon.h"
93 typedef uint16_t xkb_level_index_t;
96 /* The top level file which includes the other component files. */
97 FILE_TYPE_KEYMAP = (1 << 0),
99 /* Component files. */
100 FILE_TYPE_TYPES = (1 << 1),
101 FILE_TYPE_COMPAT = (1 << 2),
102 FILE_TYPE_SYMBOLS = (1 << 3),
103 FILE_TYPE_KEYCODES = (1 << 4),
104 FILE_TYPE_GEOMETRY = (1 << 5),
106 /* This one doesn't mix with the others, but useful here as well. */
107 FILE_TYPE_RULES = (1 << 6),
110 /* Files needed for a complete keymap. */
111 #define REQUIRED_FILE_TYPES (FILE_TYPE_TYPES | FILE_TYPE_COMPAT | \
112 FILE_TYPE_SYMBOLS | FILE_TYPE_KEYCODES)
113 #define LEGAL_FILE_TYPES REQUIRED_FILE_TYPES
116 * Legacy names for the components of an XKB keymap, also known as KcCGST.
118 struct xkb_component_names {
125 struct xkb_any_action {
130 struct xkb_mod_action {
138 struct xkb_group_action {
144 struct xkb_iso_action {
154 struct xkb_controls_action {
160 struct xkb_device_button_action {
168 struct xkb_device_valuator_action {
179 struct xkb_pointer_default_action {
186 struct xkb_switch_screen_action {
192 struct xkb_redirect_key_action {
194 xkb_keycode_t new_kc;
201 struct xkb_pointer_action {
208 struct xkb_message_action {
214 struct xkb_pointer_button_action {
222 struct xkb_any_action any;
223 struct xkb_mod_action mods;
224 struct xkb_group_action group;
225 struct xkb_iso_action iso;
226 struct xkb_controls_action ctrls;
227 struct xkb_device_button_action devbtn;
228 struct xkb_device_valuator_action devval;
229 struct xkb_pointer_default_action dflt;
230 struct xkb_switch_screen_action screen;
231 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
232 struct xkb_pointer_action ptr; /* XXX delete for DeviceValuator */
233 struct xkb_pointer_button_action btn; /* XXX delete for DeviceBtn */
234 struct xkb_message_action msg; /* XXX just delete */
239 xkb_mod_mask_t mask; /* effective mods */
240 xkb_mod_mask_t vmods;
244 struct xkb_kt_map_entry {
245 xkb_level_index_t level;
246 struct xkb_mods mods;
249 struct xkb_key_type {
250 struct xkb_mods mods;
251 xkb_level_index_t num_levels;
252 darray(struct xkb_kt_map_entry) map;
253 struct xkb_mods *preserve;
255 const char **level_names;
258 struct xkb_sym_interpret {
263 xkb_mod_index_t virtual_mod;
264 union xkb_action act;
267 struct xkb_indicator_map {
269 unsigned char which_groups;
271 unsigned char which_mods;
272 struct xkb_mods mods;
276 struct xkb_key_alias {
277 char real[XkbKeyNameLength];
278 char alias[XkbKeyNameLength];
281 struct xkb_controls {
282 unsigned char groups_wrap;
283 struct xkb_mods internal;
284 struct xkb_mods ignore_lock;
285 unsigned short repeat_delay;
286 unsigned short repeat_interval;
287 unsigned short slow_keys_delay;
288 unsigned short debounce_delay;
289 unsigned short ax_options;
290 unsigned short ax_timeout;
291 unsigned short axt_opts_mask;
292 unsigned short axt_opts_values;
293 unsigned int axt_ctrls_mask;
294 unsigned int axt_ctrls_values;
298 char name[XkbKeyNameLength];
300 unsigned char explicit;
302 unsigned char modmap;
303 xkb_mod_mask_t vmodmap;
307 /* Index into keymap->acts */
310 unsigned char kt_index[XkbNumKbdGroups];
312 xkb_group_index_t num_groups;
313 /* How many levels the largest group has. */
314 xkb_level_index_t width;
316 uint8_t out_of_range_group_action;
317 xkb_group_index_t out_of_range_group_number;
319 /* per level/group index into 'syms' */
321 /* per level/group */
322 unsigned int *num_syms;
323 darray(xkb_keysym_t) syms;
326 /* Common keyboard description structure */
328 struct xkb_context *ctx;
331 enum xkb_map_compile_flags flags;
333 unsigned int enabled_ctrls;
335 xkb_keycode_t min_key_code;
336 xkb_keycode_t max_key_code;
338 darray(struct xkb_key) keys;
340 /* aliases in no particular order */
341 darray(struct xkb_key_alias) key_aliases;
343 darray(struct xkb_key_type) types;
345 darray(struct xkb_sym_interpret) sym_interpret;
347 /* vmod -> mod mapping */
348 xkb_mod_index_t vmods[XkbNumVirtualMods];
349 const char *vmod_names[XkbNumVirtualMods];
351 struct xkb_mods groups[XkbNumKbdGroups];
352 const char *group_names[XkbNumKbdGroups];
354 darray(union xkb_action) acts;
356 struct xkb_indicator_map indicators[XkbNumIndicators];
357 const char *indicator_names[XkbNumIndicators];
359 char *keycodes_section_name;
360 char *symbols_section_name;
361 char *types_section_name;
362 char *compat_section_name;
365 static inline struct xkb_key *
366 XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
368 return &darray_item(keymap->keys, kc);
371 static inline xkb_keycode_t
372 XkbKeyGetKeycode(struct xkb_keymap *keymap, struct xkb_key *key)
374 /* Hack to avoid having to keep the keycode inside the xkb_key. */
375 return (xkb_keycode_t)(key - keymap->keys.item);
378 #define xkb_foreach_key_from(iter, keymap, from) \
379 darray_foreach_from(iter, keymap->keys, from)
381 #define xkb_foreach_key(iter, keymap) \
382 xkb_foreach_key_from(iter, keymap, keymap->min_key_code)
384 static inline unsigned char
385 XkbKeyTypeIndex(struct xkb_key *key, xkb_group_index_t group)
387 return key->kt_index[group & 0x3];
390 static inline struct xkb_key_type *
391 XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
392 xkb_group_index_t group)
394 return &darray_item(keymap->types, XkbKeyTypeIndex(key, group));
397 static inline xkb_level_index_t
398 XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
399 xkb_group_index_t group)
401 return XkbKeyType(keymap, key, group)->num_levels;
404 static inline unsigned int
405 XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group,
406 xkb_level_index_t level)
408 return key->num_syms[group * key->width + level];
411 static inline xkb_keysym_t *
412 XkbKeySym(struct xkb_key *key, int ndx)
414 return &darray_item(key->syms, ndx);
418 XkbKeySymOffset(struct xkb_key *key, xkb_group_index_t group,
419 xkb_level_index_t level)
421 return key->sym_index[group * key->width + level];
424 static inline xkb_keysym_t *
425 XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group,
426 xkb_level_index_t level)
428 return XkbKeySym(key, XkbKeySymOffset(key, group, level));
432 XkbKeyHasActions(struct xkb_key *key)
434 return key->acts_index != 0;
437 static inline unsigned int
438 XkbKeyNumActions(struct xkb_key *key)
440 if (XkbKeyHasActions(key))
441 return key->width * key->num_groups;
445 static inline union xkb_action *
446 XkbKeyActionsPtr(struct xkb_keymap *keymap, struct xkb_key *key)
448 return darray_mem(keymap->acts, key->acts_index);
451 static inline union xkb_action *
452 XkbKeyActionEntry(struct xkb_keymap *keymap, struct xkb_key *key,
453 xkb_group_index_t group, xkb_level_index_t level)
455 if (XkbKeyHasActions(key))
456 return &XkbKeyActionsPtr(keymap, key)[key->width * group + level];
461 XkbKeycodeInRange(struct xkb_keymap *keymap, xkb_keycode_t kc)
463 return kc >= keymap->min_key_code && kc <= keymap->max_key_code;
466 typedef uint32_t xkb_atom_t;
468 #define XKB_ATOM_NONE 0
471 xkb_atom_intern(struct xkb_context *ctx, const char *string);
474 * If @string is dynamically allocated, free'd immediately after
475 * being interned, and not used afterwards, use this function
476 * instead of xkb_atom_intern to avoid some unnecessary allocations.
477 * The caller should not use or free the passed in string afterwards.
480 xkb_atom_steal(struct xkb_context *ctx, char *string);
483 xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom);
486 xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
489 xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc);
492 xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
493 xkb_group_index_t group);
496 xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
497 xkb_group_index_t group, xkb_level_index_t level,
498 const xkb_keysym_t **syms_out);
501 * Deprecated entrypoint for legacy users who need to be able to compile
502 * XKB keymaps by KcCGST (Keycodes + Compat + Geometry + Symbols + Types)
505 * You should not use this unless you are the X server. This entrypoint
506 * may well disappear in future releases. Please, please, don't use it.
508 * Geometry will be ignored since xkbcommon does not support it in any way.
511 xkb_map_new_from_kccgst(struct xkb_context *ctx,
512 const struct xkb_component_names *kccgst,
513 enum xkb_map_compile_flags flags);
516 xkb_context_take_file_id(struct xkb_context *ctx);
519 xkb_keysym_is_lower(xkb_keysym_t keysym);
522 xkb_keysym_is_upper(xkb_keysym_t keysym);
525 xkb_keysym_is_keypad(xkb_keysym_t keysym);
527 ATTR_PRINTF(3, 4) void
528 xkb_log(struct xkb_context *ctx, int priority, const char *fmt, ...);
530 #define xkb_log_cond(ctx, prio, ...) \
532 if (xkb_get_log_priority(ctx) >= (prio)) \
533 xkb_log((ctx), (prio), __VA_ARGS__); \
536 #define xkb_log_cond_lvl(ctx, prio, lvl, ...) \
538 if (xkb_get_log_verbosity(ctx) >= (lvl)) \
539 xkb_log_cond((ctx), (prio), __VA_ARGS__); \
543 * The format is not part of the argument list in order to avoid the
544 * "ISO C99 requires rest arguments to be used" warning when only the
545 * format is supplied without arguments. Not supplying it would still
546 * result in an error, though.
548 #define log_dbg(ctx, ...) xkb_log_cond((ctx), LOG_DEBUG, __VA_ARGS__)
549 #define log_info(ctx, ...) xkb_log_cond((ctx), LOG_INFO, __VA_ARGS__)
550 #define log_warn(ctx, ...) xkb_log_cond((ctx), LOG_WARNING, __VA_ARGS__)
551 #define log_err(ctx, ...) xkb_log_cond((ctx), LOG_ERR, __VA_ARGS__)
552 #define log_wsgo(ctx, ...) xkb_log_cond((ctx), LOG_CRIT, __VA_ARGS__)
553 #define log_lvl(ctx, lvl, ...) \
554 xkb_log_cond_lvl((ctx), LOG_WARNING, (lvl), __VA_ARGS__)
556 #endif /* XKB_PRIV_H */