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>
89 #include "xkbcommon/xkbcommon.h"
95 /* The top level file which includes the other component files. */
96 FILE_TYPE_KEYMAP = (1 << 0),
98 /* Component files. */
99 FILE_TYPE_TYPES = (1 << 1),
100 FILE_TYPE_COMPAT = (1 << 2),
101 FILE_TYPE_SYMBOLS = (1 << 3),
102 FILE_TYPE_KEYCODES = (1 << 4),
103 FILE_TYPE_GEOMETRY = (1 << 5),
105 /* This one doesn't mix with the others, but useful here as well. */
106 FILE_TYPE_RULES = (1 << 6),
109 /* Files needed for a complete keymap. */
110 #define REQUIRED_FILE_TYPES (FILE_TYPE_TYPES | FILE_TYPE_COMPAT | \
111 FILE_TYPE_SYMBOLS | FILE_TYPE_KEYCODES)
112 #define LEGAL_FILE_TYPES REQUIRED_FILE_TYPES
115 * Legacy names for the components of an XKB keymap, also known as KcCGST.
117 struct xkb_component_names {
124 struct xkb_any_action {
129 struct xkb_mod_action {
137 struct xkb_group_action {
143 struct xkb_iso_action {
153 struct xkb_controls_action {
159 struct xkb_device_button_action {
167 struct xkb_device_valuator_action {
178 struct xkb_pointer_default_action {
185 struct xkb_switch_screen_action {
191 struct xkb_redirect_key_action {
193 xkb_keycode_t new_kc;
200 struct xkb_pointer_action {
207 struct xkb_message_action {
213 struct xkb_pointer_button_action {
221 struct xkb_any_action any;
222 struct xkb_mod_action mods;
223 struct xkb_group_action group;
224 struct xkb_iso_action iso;
225 struct xkb_controls_action ctrls;
226 struct xkb_device_button_action devbtn;
227 struct xkb_device_valuator_action devval;
228 struct xkb_pointer_default_action dflt;
229 struct xkb_switch_screen_action screen;
230 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
231 struct xkb_pointer_action ptr; /* XXX delete for DeviceValuator */
232 struct xkb_pointer_button_action btn; /* XXX delete for DeviceBtn */
233 struct xkb_message_action msg; /* XXX just delete */
238 uint32_t mask; /* effective mods */
243 struct xkb_kt_map_entry {
245 struct xkb_mods mods;
248 struct xkb_key_type {
249 struct xkb_mods mods;
251 darray(struct xkb_kt_map_entry) map;
252 struct xkb_mods * preserve;
257 struct xkb_sym_interpret {
262 uint32_t virtual_mod;
263 union xkb_action act;
266 struct xkb_behavior {
271 struct xkb_indicator_map {
273 unsigned char which_groups;
275 unsigned char which_mods;
276 struct xkb_mods mods;
280 struct xkb_key_alias {
281 char real[XkbKeyNameLength];
282 char alias[XkbKeyNameLength];
285 struct xkb_controls {
286 unsigned char groups_wrap;
287 struct xkb_mods internal;
288 struct xkb_mods ignore_lock;
289 unsigned short repeat_delay;
290 unsigned short repeat_interval;
291 unsigned short slow_keys_delay;
292 unsigned short debounce_delay;
293 unsigned short ax_options;
294 unsigned short ax_timeout;
295 unsigned short axt_opts_mask;
296 unsigned short axt_opts_values;
297 unsigned int axt_ctrls_mask;
298 unsigned int axt_ctrls_values;
302 char name[XkbKeyNameLength];
304 unsigned char explicit;
306 unsigned char modmap;
309 struct xkb_behavior behavior;
313 /* Index into keymap->acts */
316 unsigned char kt_index[XkbNumKbdGroups];
318 xkb_group_index_t num_groups;
319 /* How many levels the largest group has. */
322 uint8_t out_of_range_group_action;
323 xkb_group_index_t out_of_range_group_number;
325 /* per level/group index into 'syms' */
327 /* per level/group */
328 unsigned int *num_syms;
329 darray(xkb_keysym_t) syms;
332 /* Common keyboard description structure */
334 struct xkb_context *ctx;
337 enum xkb_map_compile_flags flags;
339 unsigned int enabled_ctrls;
341 xkb_keycode_t min_key_code;
342 xkb_keycode_t max_key_code;
344 darray(struct xkb_key) keys;
346 /* aliases in no particular order */
347 darray(struct xkb_key_alias) key_aliases;
349 darray(struct xkb_key_type) types;
351 darray(struct xkb_sym_interpret) sym_interpret;
353 /* vmod -> mod mapping */
354 uint32_t vmods[XkbNumVirtualMods];
355 char *vmod_names[XkbNumVirtualMods];
357 struct xkb_mods groups[XkbNumKbdGroups];
358 char *group_names[XkbNumKbdGroups];
360 darray(union xkb_action) acts;
362 struct xkb_indicator_map indicators[XkbNumIndicators];
363 char *indicator_names[XkbNumIndicators];
365 char *keycodes_section_name;
366 char *symbols_section_name;
367 char *types_section_name;
368 char *compat_section_name;
371 static inline struct xkb_key *
372 XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
374 return &darray_item(keymap->keys, kc);
377 static inline xkb_keycode_t
378 XkbKeyGetKeycode(struct xkb_keymap *keymap, struct xkb_key *key)
380 /* Hack to avoid having to keep the keycode inside the xkb_key. */
381 return (xkb_keycode_t)(key - keymap->keys.item);
384 #define xkb_foreach_key_from(iter, keymap, from) \
385 darray_foreach_from(iter, keymap->keys, from)
387 #define xkb_foreach_key(iter, keymap) \
388 xkb_foreach_key_from(iter, keymap, keymap->min_key_code)
390 static inline unsigned char
391 XkbKeyTypeIndex(struct xkb_key *key, xkb_group_index_t group)
393 return key->kt_index[group & 0x3];
396 static inline struct xkb_key_type *
397 XkbKeyType(struct xkb_keymap *keymap, struct xkb_key *key,
398 xkb_group_index_t group)
400 return &darray_item(keymap->types, XkbKeyTypeIndex(key, group));
403 static inline uint16_t
404 XkbKeyGroupWidth(struct xkb_keymap *keymap, struct xkb_key *key,
405 xkb_group_index_t group)
407 return XkbKeyType(keymap, key, group)->num_levels;
410 static inline unsigned int
411 XkbKeyNumSyms(struct xkb_key *key, xkb_group_index_t group, unsigned int level)
413 return key->num_syms[group * key->width + level];
416 static inline xkb_keysym_t *
417 XkbKeySym(struct xkb_key *key, int ndx)
419 return &darray_item(key->syms, ndx);
423 XkbKeySymOffset(struct xkb_key *key, xkb_group_index_t group,
426 return key->sym_index[group * key->width + level];
429 static inline xkb_keysym_t *
430 XkbKeySymEntry(struct xkb_key *key, xkb_group_index_t group, unsigned int level)
432 return XkbKeySym(key, XkbKeySymOffset(key, group, level));
436 XkbKeyHasActions(struct xkb_key *key)
438 return key->acts_index != 0;
441 static inline unsigned int
442 XkbKeyNumActions(struct xkb_key *key)
444 if (XkbKeyHasActions(key))
445 return key->width * key->num_groups;
449 static inline union xkb_action *
450 XkbKeyActionsPtr(struct xkb_keymap *keymap, struct xkb_key *key)
452 return darray_mem(keymap->acts, key->acts_index);
455 static inline union xkb_action *
456 XkbKeyActionEntry(struct xkb_keymap *keymap, struct xkb_key *key,
457 xkb_group_index_t group, unsigned int level)
459 if (XkbKeyHasActions(key))
460 return &XkbKeyActionsPtr(keymap, key)[key->width * group + level];
465 XkbKeycodeInRange(struct xkb_keymap *keymap, xkb_keycode_t kc)
467 return kc >= keymap->min_key_code && kc <= keymap->max_key_code;
470 typedef uint32_t xkb_atom_t;
472 #define XKB_ATOM_NONE 0
475 xkb_atom_intern(struct xkb_context *ctx, const char *string);
478 xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom);
481 xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
484 xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc);
487 xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
488 xkb_group_index_t group);
491 xkb_key_get_syms_by_level(struct xkb_keymap *keymap, struct xkb_key *key,
492 xkb_group_index_t group, unsigned int level,
493 const xkb_keysym_t **syms_out);
496 * Deprecated entrypoint for legacy users who need to be able to compile
497 * XKB keymaps by KcCGST (Keycodes + Compat + Geometry + Symbols + Types)
500 * You should not use this unless you are the X server. This entrypoint
501 * may well disappear in future releases. Please, please, don't use it.
503 * Geometry will be ignored since xkbcommon does not support it in any way.
506 xkb_map_new_from_kccgst(struct xkb_context *ctx,
507 const struct xkb_component_names *kccgst,
508 enum xkb_map_compile_flags flags);
511 xkb_context_take_file_id(struct xkb_context *ctx);
514 xkb_keysym_is_lower(xkb_keysym_t keysym);
517 xkb_keysym_is_upper(xkb_keysym_t keysym);
520 xkb_keysym_is_keypad(xkb_keysym_t keysym);
522 ATTR_PRINTF(3, 4) void
523 xkb_log(struct xkb_context *ctx, int priority, const char *fmt, ...);
525 #define xkb_log_cond(ctx, prio, ...) \
527 if (xkb_get_log_priority(ctx) >= (prio)) \
528 xkb_log((ctx), (prio), __VA_ARGS__); \
531 #define xkb_log_cond_lvl(ctx, prio, lvl, ...) \
533 if (xkb_get_log_verbosity(ctx) >= (lvl)) \
534 xkb_log_cond((ctx), (prio), __VA_ARGS__); \
538 * The format is not part of the argument list in order to avoid the
539 * "ISO C99 requires rest arguments to be used" warning when only the
540 * format is supplied without arguments. Not supplying it would still
541 * result in an error, though.
543 #define log_dbg(ctx, ...) xkb_log_cond((ctx), LOG_DEBUG, __VA_ARGS__)
544 #define log_info(ctx, ...) xkb_log_cond((ctx), LOG_INFO, __VA_ARGS__)
545 #define log_warn(ctx, ...) xkb_log_cond((ctx), LOG_WARNING, __VA_ARGS__)
546 #define log_err(ctx, ...) xkb_log_cond((ctx), LOG_ERR, __VA_ARGS__)
547 #define log_wsgo(ctx, ...) xkb_log_cond((ctx), LOG_CRIT, __VA_ARGS__)
548 #define log_lvl(ctx, lvl, ...) \
549 xkb_log_cond_lvl((ctx), LOG_WARNING, (lvl), __VA_ARGS__)
551 #endif /* XKB_PRIV_H */