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 © 2009-2012 Daniel Stone
56 * Copyright © 2012 Intel Corporation
57 * Copyright © 2012 Ran Benita
59 * Permission is hereby granted, free of charge, to any person obtaining a
60 * copy of this software and associated documentation files (the "Software"),
61 * to deal in the Software without restriction, including without limitation
62 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
63 * and/or sell copies of the Software, and to permit persons to whom the
64 * Software is furnished to do so, subject to the following conditions:
66 * The above copyright notice and this permission notice (including the next
67 * paragraph) shall be included in all copies or substantial portions of the
70 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
71 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
72 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
73 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
74 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
75 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
76 * DEALINGS IN THE SOFTWARE.
78 * Author: Daniel Stone <daniel@fooishbar.org>
88 #include <xkbcommon/xkbcommon-names.h>
89 #include <xkbcommon/xkbcommon-keysyms.h>
97 * Main libxkbcommon API.
101 * @struct xkb_context
102 * Opaque top level library context object.
104 * The context contains various general library data and state, like
105 * logging level and include paths.
107 * Objects are created in a specific context, and multiple contexts may
108 * coexist simultaneously. Objects from different contexts are completely
109 * separated and do not share any memory or state.
115 * Opaque compiled keymap object.
117 * The keymap object holds all of the static keyboard information obtained
118 * from compiling XKB files.
120 * A keymap is immutable after it is created (besides reference counts, etc.);
121 * if you need to change it, you must create a new one.
127 * Opaque keyboard state object.
129 * State objects contain the active state of a keyboard (or keyboards), such
130 * as the currently effective layout and the active modifiers. It acts as a
131 * simple state machine, wherein key presses and releases are the input, and
132 * key symbols (keysyms) are the output.
137 * A number used to represent a physical key on a keyboard.
139 * A standard PC-compatible keyboard might have 102 keys. An appropriate
140 * keymap would assign each of them a keycode, by which the user should
141 * refer to the key throughout the library.
143 * Historically, the X11 protocol, and consequentially the XKB protocol,
144 * assign only 8 bits for keycodes. This limits the number of different
145 * keys that can be used simultaneously in a single keymap to 256
146 * (disregarding other limitations). This library does not share this limit;
147 * keycodes beyond 255 ('extended keycodes') are not treated specially.
148 * Keymaps and applications which are compatible with X11 should not use
151 * The values of specific keycodes are determined by the keymap and the
152 * underlying input system. For example, with an X11-compatible keymap
153 * and Linux evdev scan codes (see linux/input.h), a fixed offset is used:
155 * The keymap defines a canonical name for each key, plus possible aliases.
156 * Historically, the XKB protocol restricts these names to at most 4 (ASCII)
157 * characters, but this library does not share this limit.
160 * xkb_keycode_t keycode_A = KEY_A + 8;
163 * @sa xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()
165 typedef uint32_t xkb_keycode_t;
168 * A number used to represent the symbols generated from a key on a keyboard.
170 * A key, represented by a keycode, may generate different symbols according
171 * to keyboard state. For example, on a QWERTY keyboard, pressing the key
172 * labled \<A\> generates the symbol 'a'. If the Shift key is held, it
173 * generates the symbol 'A'. If a different layout is used, say Greek,
174 * it generates the symbol 'α'. And so on.
176 * Each such symbol is represented by a keysym. Note that keysyms are
177 * somewhat more general, in that they can also represent some "function",
178 * such as "Left" or "Right" for the arrow keys. For more information,
180 * https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding
182 * Specifically named keysyms can be found in the
183 * xkbcommon/xkbcommon-keysyms.h header file. Their name does not include
184 * the XKB_KEY_ prefix.
186 * Besides those, any Unicode/ISO 10646 character in the range U0100 to
187 * U10FFFF can be represented by a keysym value in the range 0x01000100 to
188 * 0x0110FFFF. The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".
190 * The name of other unnamed keysyms is the hexadecimal representation of
191 * their value, e.g. "0xabcd1234".
193 * Keysym names are case-sensitive.
195 typedef uint32_t xkb_keysym_t;
198 * Index of a keyboard layout.
200 * The layout index is a state component which detemines which <em>keyboard
201 * layout</em> is active. These may be different alphabets, different key
204 * Layout indices are consecutive. The first layout has index 0.
206 * Each layout is not required to have a name, and the names are not
207 * guaranteed to be unique (though they are usually provided and unique).
208 * Therefore, it is not safe to use the name as a unique identifier for a
209 * layout. Layout names are case-sensitive.
211 * Layout names are specified in the layout's definition, for example
212 * "English (US)". These are different from the (conventionally) short names
213 * which are used to locate the layout, for example "us" or "us(intl)". These
214 * names are not present in a compiled keymap.
216 * If the user selects layouts from a list generated from the XKB registry
217 * (using libxkbregistry or directly), and this metadata is needed later on, it
218 * is recommended to store it along with the keymap.
220 * Layouts are also called "groups" by XKB.
222 * @sa xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()
224 typedef uint32_t xkb_layout_index_t;
225 /** A mask of layout indices. */
226 typedef uint32_t xkb_layout_mask_t;
229 * Index of a shift level.
231 * Any key, in any layout, can have several <em>shift levels</em>. Each
232 * shift level can assign different keysyms to the key. The shift level
233 * to use is chosen according to the current keyboard state; for example,
234 * if no keys are pressed, the first level may be used; if the Left Shift
235 * key is pressed, the second; if Num Lock is pressed, the third; and
236 * many such combinations are possible (see xkb_mod_index_t).
238 * Level indices are consecutive. The first level has index 0.
240 typedef uint32_t xkb_level_index_t;
243 * Index of a modifier.
245 * A @e modifier is a state component which changes the way keys are
246 * interpreted. A keymap defines a set of modifiers, such as Alt, Shift,
247 * Num Lock or Meta, and specifies which keys may @e activate which
248 * modifiers (in a many-to-many relationship, i.e. a key can activate
249 * several modifiers, and a modifier may be activated by several keys.
250 * Different keymaps do this differently).
252 * When retrieving the keysyms for a key, the active modifier set is
253 * consulted; this detemines the correct shift level to use within the
254 * currently active layout (see xkb_level_index_t).
256 * Modifier indices are consecutive. The first modifier has index 0.
258 * Each modifier must have a name, and the names are unique. Therefore, it
259 * is safe to use the name as a unique identifier for a modifier. The names
260 * of some common modifiers are provided in the xkbcommon/xkbcommon-names.h
261 * header file. Modifier names are case-sensitive.
263 * @sa xkb_keymap_num_mods()
265 typedef uint32_t xkb_mod_index_t;
266 /** A mask of modifier indices. */
267 typedef uint32_t xkb_mod_mask_t;
270 * Index of a keyboard LED.
272 * LEDs are logical objects which may be @e active or @e inactive. They
273 * typically correspond to the lights on the keyboard. Their state is
274 * determined by the current keyboard state.
276 * LED indices are non-consecutive. The first LED has index 0.
278 * Each LED must have a name, and the names are unique. Therefore,
279 * it is safe to use the name as a unique identifier for a LED. The names
280 * of some common LEDs are provided in the xkbcommon/xkbcommon-names.h
281 * header file. LED names are case-sensitive.
283 * @warning A given keymap may specify an exact index for a given LED.
284 * Therefore, LED indexing is not necessarily sequential, as opposed to
285 * modifiers and layouts. This means that when iterating over the LEDs
286 * in a keymap using e.g. xkb_keymap_num_leds(), some indices might be
287 * invalid. Given such an index, functions like xkb_keymap_led_get_name()
288 * will return NULL, and xkb_state_led_index_is_active() will return -1.
290 * LEDs are also called "indicators" by XKB.
292 * @sa xkb_keymap_num_leds()
294 typedef uint32_t xkb_led_index_t;
295 /** A mask of LED indices. */
296 typedef uint32_t xkb_led_mask_t;
298 #define XKB_KEYCODE_INVALID (0xffffffff)
299 #define XKB_LAYOUT_INVALID (0xffffffff)
300 #define XKB_LEVEL_INVALID (0xffffffff)
301 #define XKB_MOD_INVALID (0xffffffff)
302 #define XKB_LED_INVALID (0xffffffff)
304 #define XKB_KEYCODE_MAX (0xffffffff - 1)
307 * Test whether a value is a valid extended keycode.
310 #define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)
313 * Test whether a value is a valid X11 keycode.
316 #define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)
319 * Names to compile a keymap with, also known as RMLVO.
321 * The names are the common configuration values by which a user picks
324 * If the entire struct is NULL, then each field is taken to be NULL.
325 * You should prefer passing NULL instead of choosing your own defaults.
327 struct xkb_rule_names {
329 * The rules file to use. The rules file describes how to interpret
330 * the values of the model, layout, variant and options fields.
332 * If NULL or the empty string "", a default value is used.
333 * If the XKB_DEFAULT_RULES environment variable is set, it is used
334 * as the default. Otherwise the system default is used.
338 * The keyboard model by which to interpret keycodes and LEDs.
340 * If NULL or the empty string "", a default value is used.
341 * If the XKB_DEFAULT_MODEL environment variable is set, it is used
342 * as the default. Otherwise the system default is used.
346 * A comma separated list of layouts (languages) to include in the
349 * If NULL or the empty string "", a default value is used.
350 * If the XKB_DEFAULT_LAYOUT environment variable is set, it is used
351 * as the default. Otherwise the system default is used.
355 * A comma separated list of variants, one per layout, which may
356 * modify or augment the respective layout in various ways.
358 * If NULL or the empty string "", and a default value is also used
359 * for the layout, a default value is used. Otherwise no variant is
361 * If the XKB_DEFAULT_VARIANT environment variable is set, it is used
362 * as the default. Otherwise the system default is used.
366 * A comma separated list of options, through which the user specifies
367 * non-layout related preferences, like which key combinations are used
368 * for switching layouts, or which key is the Compose key.
370 * If NULL, a default value is used. If the empty string "", no
372 * If the XKB_DEFAULT_OPTIONS environment variable is set, it is used
373 * as the default. Otherwise the system default is used.
379 * @defgroup keysyms Keysyms
380 * Utility functions related to keysyms.
386 * @page keysym-transformations Keysym Transformations
388 * Keysym translation is subject to several "keysym transformations",
389 * as described in the XKB specification. These are:
391 * - Capitalization transformation. If the Caps Lock modifier is
392 * active and was not consumed by the translation process, a single
393 * keysym is transformed to its upper-case form (if applicable).
394 * Similarly, the UTF-8/UTF-32 string produced is capitalized.
396 * This is described in:
397 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier
399 * - Control transformation. If the Control modifier is active and
400 * was not consumed by the translation process, the string produced
401 * is transformed to its matching ASCII control character (if
402 * applicable). Keysyms are not affected.
404 * This is described in:
405 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
407 * Each relevant function discusses which transformations it performs.
409 * These transformations are not applicable when a key produces multiple
415 * Get the name of a keysym.
417 * For a description of how keysyms are named, see @ref xkb_keysym_t.
419 * @param[in] keysym The keysym.
420 * @param[out] buffer A string buffer to write the name into.
421 * @param[in] size Size of the buffer.
423 * @warning If the buffer passed is too small, the string is truncated
424 * (though still NUL-terminated); a size of at least 64 bytes is recommended.
426 * @returns The number of bytes in the name, excluding the NUL byte. If
427 * the keysym is invalid, returns -1.
429 * You may check if truncation has occurred by comparing the return value
430 * with the length of buffer, similarly to the snprintf(3) function.
435 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
437 /** Flags for xkb_keysym_from_name(). */
438 enum xkb_keysym_flags {
439 /** Do not apply any flags. */
440 XKB_KEYSYM_NO_FLAGS = 0,
441 /** Find keysym by case-insensitive search. */
442 XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
446 * Get a keysym from its name.
448 * @param name The name of a keysym. See remarks in xkb_keysym_get_name();
449 * this function will accept any name returned by that function.
450 * @param flags A set of flags controlling how the search is done. If
451 * invalid flags are passed, this will fail with XKB_KEY_NoSymbol.
453 * If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names
454 * differ only by case, then the lower-case keysym is returned. For
455 * instance, for KEY_a and KEY_A, this function would return KEY_a for the
456 * case-insensitive search. If this functionality is needed, it is
457 * recommended to first call this function without this flag; and if that
458 * fails, only then to try with this flag, while possibly warning the user
459 * he had misspelled the name, and might get wrong results.
461 * Case folding is done according to the C locale; the current locale is not
464 * @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.
469 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
472 * Get the Unicode/UTF-8 representation of a keysym.
474 * @param[in] keysym The keysym.
475 * @param[out] buffer A buffer to write the UTF-8 string into.
476 * @param[in] size The size of buffer. Must be at least 7.
478 * @returns The number of bytes written to the buffer (including the
479 * terminating byte). If the keysym does not have a Unicode
480 * representation, returns 0. If the buffer is too small, returns -1.
482 * This function does not perform any @ref keysym-transformations.
483 * Therefore, prefer to use xkb_state_key_get_utf8() if possible.
485 * @sa xkb_state_key_get_utf8()
488 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
491 * Get the Unicode/UTF-32 representation of a keysym.
493 * @returns The Unicode/UTF-32 representation of keysym, which is also
494 * compatible with UCS-4. If the keysym does not have a Unicode
495 * representation, returns 0.
497 * This function does not perform any @ref keysym-transformations.
498 * Therefore, prefer to use xkb_state_key_get_utf32() if possible.
500 * @sa xkb_state_key_get_utf32()
503 xkb_keysym_to_utf32(xkb_keysym_t keysym);
506 * Get the keysym corresponding to a Unicode/UTF-32 codepoint.
508 * @returns The keysym corresponding to the specified Unicode
509 * codepoint, or XKB_KEY_NoSymbol if there is none.
511 * This function is the inverse of @ref xkb_keysym_to_utf32. In cases
512 * where a single codepoint corresponds to multiple keysyms, returns
513 * the keysym with the lowest value.
515 * Unicode codepoints which do not have a special (legacy) keysym
516 * encoding use a direct encoding scheme. These keysyms don't usually
517 * have an associated keysym constant (XKB_KEY_*).
519 * For noncharacter Unicode codepoints and codepoints outside of the
520 * defined Unicode planes this function returns XKB_KEY_NoSymbol.
522 * @sa xkb_keysym_to_utf32()
526 xkb_utf32_to_keysym(uint32_t ucs);
529 * Convert a keysym to its uppercase form.
531 * If there is no such form, the keysym is returned unchanged.
533 * The conversion rules may be incomplete; prefer to work with the Unicode
534 * representation instead, when possible.
537 xkb_keysym_to_upper(xkb_keysym_t ks);
540 * Convert a keysym to its lowercase form.
542 * The conversion rules may be incomplete; prefer to work with the Unicode
543 * representation instead, when possible.
546 xkb_keysym_to_lower(xkb_keysym_t ks);
551 * @defgroup context Library Context
552 * Creating, destroying and using library contexts.
554 * Every keymap compilation request must have a context associated with
555 * it. The context keeps around state such as the include path.
561 * @page envvars Environment Variables
563 * The user may set some environment variables which affect the library:
565 * - `XKB_CONFIG_ROOT`, `XKB_EXTRA_PATH`, `XDG_CONFIG_DIR`, `HOME` - see @ref include-path.
566 * - `XKB_LOG_LEVEL` - see xkb_context_set_log_level().
567 * - `XKB_LOG_VERBOSITY` - see xkb_context_set_log_verbosity().
568 * - `XKB_DEFAULT_RULES`, `XKB_DEFAULT_MODEL`, `XKB_DEFAULT_LAYOUT`,
569 * `XKB_DEFAULT_VARIANT`, `XKB_DEFAULT_OPTIONS` - see xkb_rule_names.
572 /** Flags for context creation. */
573 enum xkb_context_flags {
574 /** Do not apply any context flags. */
575 XKB_CONTEXT_NO_FLAGS = 0,
576 /** Create this context with an empty include path. */
577 XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
579 * Don't take RMLVO names from the environment.
582 XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1)
586 * Create a new context.
588 * @param flags Optional flags for the context, or 0.
590 * @returns A new context, or NULL on failure.
592 * @memberof xkb_context
595 xkb_context_new(enum xkb_context_flags flags);
598 * Take a new reference on a context.
600 * @returns The passed in context.
602 * @memberof xkb_context
605 xkb_context_ref(struct xkb_context *context);
608 * Release a reference on a context, and possibly free it.
610 * @param context The context. If it is NULL, this function does nothing.
612 * @memberof xkb_context
615 xkb_context_unref(struct xkb_context *context);
618 * Store custom user data in the context.
620 * This may be useful in conjunction with xkb_context_set_log_fn() or other
623 * @memberof xkb_context
626 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
629 * Retrieves stored user data from the context.
631 * @returns The stored user data. If the user data wasn't set, or the
632 * passed in context is NULL, returns NULL.
634 * This may be useful to access private user data from callbacks like a
635 * custom logging function.
637 * @memberof xkb_context
640 xkb_context_get_user_data(struct xkb_context *context);
645 * @defgroup include-path Include Paths
646 * Manipulating the include paths in a context.
648 * The include paths are the file-system paths that are searched when an
649 * include statement is encountered during keymap compilation.
651 * The default include paths are, in that lookup order:
652 * - The path `$XDG_CONFIG_HOME/xkb`, with the usual `XDG_CONFIG_HOME`
653 * fallback to `$HOME/.config/` if unset.
654 * - The path `$HOME/.xkb`, where $HOME is the value of the environment
656 * - The `XKB_EXTRA_PATH` environment variable, if defined, otherwise the
657 * system configuration directory, defined at library configuration time
658 * (usually `/etc/xkb`).
659 * - The `XKB_CONFIG_ROOT` environment variable, if defined, otherwise
660 * the system XKB root, defined at library configuration time.
666 * Append a new entry to the context's include path.
668 * @returns 1 on success, or 0 if the include path could not be added or is
671 * @memberof xkb_context
674 xkb_context_include_path_append(struct xkb_context *context, const char *path);
677 * Append the default include paths to the context's include path.
679 * @returns 1 on success, or 0 if the primary include path could not be added.
681 * @memberof xkb_context
684 xkb_context_include_path_append_default(struct xkb_context *context);
687 * Reset the context's include path to the default.
689 * Removes all entries from the context's include path, and inserts the
692 * @returns 1 on success, or 0 if the primary include path could not be added.
694 * @memberof xkb_context
697 xkb_context_include_path_reset_defaults(struct xkb_context *context);
700 * Remove all entries from the context's include path.
702 * @memberof xkb_context
705 xkb_context_include_path_clear(struct xkb_context *context);
708 * Get the number of paths in the context's include path.
710 * @memberof xkb_context
713 xkb_context_num_include_paths(struct xkb_context *context);
716 * Get a specific include path from the context's include path.
718 * @returns The include path at the specified index. If the index is
719 * invalid, returns NULL.
721 * @memberof xkb_context
724 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
729 * @defgroup logging Logging Handling
730 * Manipulating how logging from this library is handled.
735 /** Specifies a logging level. */
737 XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
738 XKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */
739 XKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */
740 XKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */
741 XKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */
745 * Set the current logging level.
747 * @param context The context in which to set the logging level.
748 * @param level The logging level to use. Only messages from this level
749 * and below will be logged.
751 * The default level is XKB_LOG_LEVEL_ERROR. The environment variable
752 * XKB_LOG_LEVEL, if set in the time the context was created, overrides the
753 * default value. It may be specified as a level number or name.
755 * @memberof xkb_context
758 xkb_context_set_log_level(struct xkb_context *context,
759 enum xkb_log_level level);
762 * Get the current logging level.
764 * @memberof xkb_context
767 xkb_context_get_log_level(struct xkb_context *context);
770 * Sets the current logging verbosity.
772 * The library can generate a number of warnings which are not helpful to
773 * ordinary users of the library. The verbosity may be increased if more
774 * information is desired (e.g. when developing a new keymap).
776 * The default verbosity is 0. The environment variable XKB_LOG_VERBOSITY,
777 * if set in the time the context was created, overrides the default value.
779 * @param context The context in which to use the set verbosity.
780 * @param verbosity The verbosity to use. Currently used values are
781 * 1 to 10, higher values being more verbose. 0 would result in no verbose
782 * messages being logged.
784 * Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
786 * @memberof xkb_context
789 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
792 * Get the current logging verbosity of the context.
794 * @memberof xkb_context
797 xkb_context_get_log_verbosity(struct xkb_context *context);
800 * Set a custom function to handle logging messages.
802 * @param context The context in which to use the set logging function.
803 * @param log_fn The function that will be called for logging messages.
804 * Passing NULL restores the default function, which logs to stderr.
806 * By default, log messages from this library are printed to stderr. This
807 * function allows you to replace the default behavior with a custom
808 * handler. The handler is only called with messages which match the
809 * current logging level and verbosity settings for the context.
810 * level is the logging level of the message. @a format and @a args are
811 * the same as in the vprintf(3) function.
813 * You may use xkb_context_set_user_data() on the context, and then call
814 * xkb_context_get_user_data() from within the logging function to provide
815 * it with additional private context.
817 * @memberof xkb_context
820 xkb_context_set_log_fn(struct xkb_context *context,
821 void (*log_fn)(struct xkb_context *context,
822 enum xkb_log_level level,
823 const char *format, va_list args));
828 * @defgroup keymap Keymap Creation
829 * Creating and destroying keymaps.
834 /** Flags for keymap compilation. */
835 enum xkb_keymap_compile_flags {
836 /** Do not apply any flags. */
837 XKB_KEYMAP_COMPILE_NO_FLAGS = 0
841 * Create a keymap from RMLVO names.
843 * The primary keymap entry point: creates a new XKB keymap from a set of
844 * RMLVO (Rules + Model + Layouts + Variants + Options) names.
846 * @param context The context in which to create the keymap.
847 * @param names The RMLVO names to use. See xkb_rule_names.
848 * @param flags Optional flags for the keymap, or 0.
850 * @returns A keymap compiled according to the RMLVO names, or NULL if
851 * the compilation failed.
854 * @memberof xkb_keymap
857 xkb_keymap_new_from_names(struct xkb_context *context,
858 const struct xkb_rule_names *names,
859 enum xkb_keymap_compile_flags flags);
861 /** The possible keymap formats. */
862 enum xkb_keymap_format {
863 /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
864 XKB_KEYMAP_FORMAT_TEXT_V1 = 1
868 * Create a keymap from a keymap file.
870 * @param context The context in which to create the keymap.
871 * @param file The keymap file to compile.
872 * @param format The text format of the keymap file to compile.
873 * @param flags Optional flags for the keymap, or 0.
875 * @returns A keymap compiled from the given XKB keymap file, or NULL if
876 * the compilation failed.
878 * The file must contain a complete keymap. For example, in the
879 * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
880 * top level '%xkb_keymap' section, which in turn contains other required
883 * @memberof xkb_keymap
886 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
887 enum xkb_keymap_format format,
888 enum xkb_keymap_compile_flags flags);
891 * Create a keymap from a keymap string.
893 * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
894 * the keymap as one enormous string.
896 * @see xkb_keymap_new_from_file()
897 * @memberof xkb_keymap
900 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
901 enum xkb_keymap_format format,
902 enum xkb_keymap_compile_flags flags);
905 * Create a keymap from a memory buffer.
907 * This is just like xkb_keymap_new_from_string(), but takes a length argument
908 * so the input string does not have to be zero-terminated.
910 * @see xkb_keymap_new_from_string()
911 * @memberof xkb_keymap
915 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
916 size_t length, enum xkb_keymap_format format,
917 enum xkb_keymap_compile_flags flags);
920 * Take a new reference on a keymap.
922 * @returns The passed in keymap.
924 * @memberof xkb_keymap
927 xkb_keymap_ref(struct xkb_keymap *keymap);
930 * Release a reference on a keymap, and possibly free it.
932 * @param keymap The keymap. If it is NULL, this function does nothing.
934 * @memberof xkb_keymap
937 xkb_keymap_unref(struct xkb_keymap *keymap);
940 * Get the keymap as a string in the format from which it was created.
941 * @sa xkb_keymap_get_as_string()
943 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
946 * Get the compiled keymap as a string.
948 * @param keymap The keymap to get as a string.
949 * @param format The keymap format to use for the string. You can pass
950 * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
951 * from which the keymap was originally created.
953 * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
955 * The returned string may be fed back into xkb_keymap_new_from_string() to get
956 * the exact same keymap (possibly in another process, etc.).
958 * The returned string is dynamically allocated and should be freed by the
961 * @memberof xkb_keymap
964 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
965 enum xkb_keymap_format format);
970 * @defgroup components Keymap Components
971 * Enumeration of state components in a keymap.
977 * Get the minimum keycode in the keymap.
980 * @memberof xkb_keymap
984 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
987 * Get the maximum keycode in the keymap.
990 * @memberof xkb_keymap
994 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
997 * The iterator used by xkb_keymap_key_for_each().
999 * @sa xkb_keymap_key_for_each
1000 * @memberof xkb_keymap
1004 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
1008 * Run a specified function for every valid keycode in the keymap. If a
1009 * keymap is sparse, this function may be called fewer than
1010 * (max_keycode - min_keycode + 1) times.
1012 * @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t
1013 * @memberof xkb_keymap
1017 xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
1021 * Find the name of the key with the given keycode.
1023 * This function always returns the canonical name of the key (see
1024 * description in xkb_keycode_t).
1026 * @returns The key name. If no key with this keycode exists,
1030 * @memberof xkb_keymap
1034 xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);
1037 * Find the keycode of the key with the given name.
1039 * The name can be either a canonical name or an alias.
1041 * @returns The keycode. If no key with this name exists,
1042 * returns XKB_KEYCODE_INVALID.
1045 * @memberof xkb_keymap
1049 xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);
1052 * Get the number of modifiers in the keymap.
1054 * @sa xkb_mod_index_t
1055 * @memberof xkb_keymap
1058 xkb_keymap_num_mods(struct xkb_keymap *keymap);
1061 * Get the name of a modifier by index.
1063 * @returns The name. If the index is invalid, returns NULL.
1065 * @sa xkb_mod_index_t
1066 * @memberof xkb_keymap
1069 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
1072 * Get the index of a modifier by name.
1074 * @returns The index. If no modifier with this name exists, returns
1077 * @sa xkb_mod_index_t
1078 * @memberof xkb_keymap
1081 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
1084 * Get the number of layouts in the keymap.
1086 * @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()
1087 * @memberof xkb_keymap
1090 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
1093 * Get the name of a layout by index.
1095 * @returns The name. If the index is invalid, or the layout does not have
1096 * a name, returns NULL.
1098 * @sa xkb_layout_index_t
1099 * For notes on layout names.
1100 * @memberof xkb_keymap
1103 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
1106 * Get the index of a layout by name.
1108 * @returns The index. If no layout exists with this name, returns
1109 * XKB_LAYOUT_INVALID. If more than one layout in the keymap has this name,
1110 * returns the lowest index among them.
1112 * @sa xkb_layout_index_t
1113 * For notes on layout names.
1114 * @memberof xkb_keymap
1117 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
1120 * Get the number of LEDs in the keymap.
1122 * @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs
1123 * in the keymap, but may also contain inactive LEDs. When iterating over
1124 * this range, you need the handle this case when calling functions such as
1125 * xkb_keymap_led_get_name() or xkb_state_led_index_is_active().
1127 * @sa xkb_led_index_t
1128 * @memberof xkb_keymap
1131 xkb_keymap_num_leds(struct xkb_keymap *keymap);
1134 * Get the name of a LED by index.
1136 * @returns The name. If the index is invalid, returns NULL.
1138 * @memberof xkb_keymap
1141 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1144 * Get the index of a LED by name.
1146 * @returns The index. If no LED with this name exists, returns
1149 * @memberof xkb_keymap
1152 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1155 * Get the number of layouts for a specific key.
1157 * This number can be different from xkb_keymap_num_layouts(), but is always
1158 * smaller. It is the appropriate value to use when iterating over the
1161 * @sa xkb_layout_index_t
1162 * @memberof xkb_keymap
1165 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
1168 * Get the number of shift levels for a specific key and layout.
1170 * If @c layout is out of range for this key (that is, larger or equal to
1171 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1172 * back into range in a manner consistent with xkb_state_key_get_layout().
1174 * @sa xkb_level_index_t
1175 * @memberof xkb_keymap
1178 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
1179 xkb_layout_index_t layout);
1182 * Retrieves every possible modifier mask that produces the specified
1183 * shift level for a specific key and layout.
1185 * This API is useful for inverse key transformation; i.e. finding out
1186 * which modifiers need to be active in order to be able to type the
1187 * keysym(s) corresponding to the specific key code, layout and level.
1189 * @warning It returns only up to masks_size modifier masks. If the
1190 * buffer passed is too small, some of the possible modifier combinations
1191 * will not be returned.
1193 * @param[in] keymap The keymap.
1194 * @param[in] key The keycode of the key.
1195 * @param[in] layout The layout for which to get modifiers.
1196 * @param[in] level The shift level in the layout for which to get the
1197 * modifiers. This should be smaller than:
1198 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1199 * @param[out] masks_out A buffer in which the requested masks should be
1201 * @param[out] masks_size The size of the buffer pointed to by masks_out.
1203 * If @c layout is out of range for this key (that is, larger or equal to
1204 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1205 * back into range in a manner consistent with xkb_state_key_get_layout().
1207 * @returns The number of modifier masks stored in the masks_out array.
1208 * If the key is not in the keymap or if the specified shift level cannot
1209 * be reached it returns 0 and does not modify the masks_out buffer.
1211 * @sa xkb_level_index_t
1212 * @sa xkb_mod_mask_t
1213 * @memberof xkb_keymap
1217 xkb_keymap_key_get_mods_for_level(struct xkb_keymap *keymap,
1219 xkb_layout_index_t layout,
1220 xkb_level_index_t level,
1221 xkb_mod_mask_t *masks_out,
1225 * Get the keysyms obtained from pressing a key in a given layout and
1228 * This function is like xkb_state_key_get_syms(), only the layout and
1229 * shift level are not derived from the keyboard state but are instead
1230 * specified explicitly.
1232 * @param[in] keymap The keymap.
1233 * @param[in] key The keycode of the key.
1234 * @param[in] layout The layout for which to get the keysyms.
1235 * @param[in] level The shift level in the layout for which to get the
1236 * keysyms. This should be smaller than:
1237 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1238 * @param[out] syms_out An immutable array of keysyms corresponding to the
1239 * key in the given layout and shift level.
1241 * If @c layout is out of range for this key (that is, larger or equal to
1242 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1243 * back into range in a manner consistent with xkb_state_key_get_layout().
1245 * @returns The number of keysyms in the syms_out array. If no keysyms
1246 * are produced by the key in the given layout and shift level, returns 0
1247 * and sets syms_out to NULL.
1249 * @sa xkb_state_key_get_syms()
1250 * @memberof xkb_keymap
1253 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
1255 xkb_layout_index_t layout,
1256 xkb_level_index_t level,
1257 const xkb_keysym_t **syms_out);
1260 * Determine whether a key should repeat or not.
1262 * A keymap may specify different repeat behaviors for different keys.
1263 * Most keys should generally exhibit repeat behavior; for example, holding
1264 * the 'a' key down in a text editor should normally insert a single 'a'
1265 * character every few milliseconds, until the key is released. However,
1266 * there are keys which should not or do not need to be repeated. For
1267 * example, repeating modifier keys such as Left/Right Shift or Caps Lock
1268 * is not generally useful or desired.
1270 * @returns 1 if the key should repeat, 0 otherwise.
1272 * @memberof xkb_keymap
1275 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1280 * @defgroup state Keyboard State
1281 * Creating, destroying and manipulating keyboard state objects.
1287 * Create a new keyboard state object.
1289 * @param keymap The keymap which the state will use.
1291 * @returns A new keyboard state object, or NULL on failure.
1293 * @memberof xkb_state
1296 xkb_state_new(struct xkb_keymap *keymap);
1299 * Take a new reference on a keyboard state object.
1301 * @returns The passed in object.
1303 * @memberof xkb_state
1306 xkb_state_ref(struct xkb_state *state);
1309 * Release a reference on a keybaord state object, and possibly free it.
1311 * @param state The state. If it is NULL, this function does nothing.
1313 * @memberof xkb_state
1316 xkb_state_unref(struct xkb_state *state);
1319 * Get the keymap which a keyboard state object is using.
1321 * @returns The keymap which was passed to xkb_state_new() when creating
1322 * this state object.
1324 * This function does not take a new reference on the keymap; you must
1325 * explicitly reference it yourself if you plan to use it beyond the
1326 * lifetime of the state.
1328 * @memberof xkb_state
1331 xkb_state_get_keymap(struct xkb_state *state);
1333 /** Specifies the direction of the key (press / release). */
1334 enum xkb_key_direction {
1335 XKB_KEY_UP, /**< The key was released. */
1336 XKB_KEY_DOWN /**< The key was pressed. */
1340 * Modifier and layout types for state objects. This enum is bitmaskable,
1341 * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
1342 * exclude locked modifiers.
1344 * In XKB, the DEPRESSED components are also known as 'base'.
1346 enum xkb_state_component {
1347 /** Depressed modifiers, i.e. a key is physically holding them. */
1348 XKB_STATE_MODS_DEPRESSED = (1 << 0),
1349 /** Latched modifiers, i.e. will be unset after the next non-modifier
1351 XKB_STATE_MODS_LATCHED = (1 << 1),
1352 /** Locked modifiers, i.e. will be unset after the key provoking the
1353 * lock has been pressed again. */
1354 XKB_STATE_MODS_LOCKED = (1 << 2),
1355 /** Effective modifiers, i.e. currently active and affect key
1356 * processing (derived from the other state components).
1357 * Use this unless you explicitly care how the state came about. */
1358 XKB_STATE_MODS_EFFECTIVE = (1 << 3),
1359 /** Depressed layout, i.e. a key is physically holding it. */
1360 XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
1361 /** Latched layout, i.e. will be unset after the next non-modifier
1363 XKB_STATE_LAYOUT_LATCHED = (1 << 5),
1364 /** Locked layout, i.e. will be unset after the key provoking the lock
1365 * has been pressed again. */
1366 XKB_STATE_LAYOUT_LOCKED = (1 << 6),
1367 /** Effective layout, i.e. currently active and affects key processing
1368 * (derived from the other state components).
1369 * Use this unless you explicitly care how the state came about. */
1370 XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
1371 /** LEDs (derived from the other state components). */
1372 XKB_STATE_LEDS = (1 << 8)
1376 * Update the keyboard state to reflect a given key being pressed or
1379 * This entry point is intended for programs which track the keyboard state
1380 * explicitly (like an evdev client). If the state is serialized to you by
1381 * a master process (like a Wayland compositor) using functions like
1382 * xkb_state_serialize_mods(), you should use xkb_state_update_mask() instead.
1383 * The two functions should not generally be used together.
1385 * A series of calls to this function should be consistent; that is, a call
1386 * with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key
1387 * is pressed twice, it should be released twice; etc. Otherwise (e.g. due
1388 * to missed input events), situations like "stuck modifiers" may occur.
1390 * This function is often used in conjunction with the function
1391 * xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,
1392 * when handling a key event. In this case, you should prefer to get the
1393 * keysyms *before* updating the key, such that the keysyms reported for
1394 * the key event are not affected by the event itself. This is the
1395 * conventional behavior.
1397 * @returns A mask of state components that have changed as a result of
1398 * the update. If nothing in the state has changed, returns 0.
1400 * @memberof xkb_state
1402 * @sa xkb_state_update_mask()
1404 enum xkb_state_component
1405 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1406 enum xkb_key_direction direction);
1409 * Update a keyboard state from a set of explicit masks.
1411 * This entry point is intended for window systems and the like, where a
1412 * master process holds an xkb_state, then serializes it over a wire
1413 * protocol, and clients then use the serialization to feed in to their own
1416 * All parameters must always be passed, or the resulting state may be
1419 * The serialization is lossy and will not survive round trips; it must only
1420 * be used to feed slave state objects, and must not be used to update the
1423 * If you do not fit the description above, you should use
1424 * xkb_state_update_key() instead. The two functions should not generally be
1427 * @returns A mask of state components that have changed as a result of
1428 * the update. If nothing in the state has changed, returns 0.
1430 * @memberof xkb_state
1432 * @sa xkb_state_component
1433 * @sa xkb_state_update_key
1435 enum xkb_state_component
1436 xkb_state_update_mask(struct xkb_state *state,
1437 xkb_mod_mask_t depressed_mods,
1438 xkb_mod_mask_t latched_mods,
1439 xkb_mod_mask_t locked_mods,
1440 xkb_layout_index_t depressed_layout,
1441 xkb_layout_index_t latched_layout,
1442 xkb_layout_index_t locked_layout);
1445 * Get the keysyms obtained from pressing a particular key in a given
1448 * Get the keysyms for a key according to the current active layout,
1449 * modifiers and shift level for the key, as determined by a keyboard
1452 * @param[in] state The keyboard state object.
1453 * @param[in] key The keycode of the key.
1454 * @param[out] syms_out An immutable array of keysyms corresponding the
1455 * key in the given keyboard state.
1457 * As an extension to XKB, this function can return more than one keysym.
1458 * If you do not want to handle this case, you can use
1459 * xkb_state_key_get_one_sym() for a simpler interface.
1461 * This function does not perform any @ref keysym-transformations.
1462 * (This might change).
1464 * @returns The number of keysyms in the syms_out array. If no keysyms
1465 * are produced by the key in the given keyboard state, returns 0 and sets
1468 * @memberof xkb_state
1471 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
1472 const xkb_keysym_t **syms_out);
1475 * Get the Unicode/UTF-8 string obtained from pressing a particular key
1476 * in a given keyboard state.
1478 * @param[in] state The keyboard state object.
1479 * @param[in] key The keycode of the key.
1480 * @param[out] buffer A buffer to write the string into.
1481 * @param[in] size Size of the buffer.
1483 * @warning If the buffer passed is too small, the string is truncated
1484 * (though still NUL-terminated).
1486 * @returns The number of bytes required for the string, excluding the
1487 * NUL byte. If there is nothing to write, returns 0.
1489 * You may check if truncation has occurred by comparing the return value
1490 * with the size of @p buffer, similarly to the snprintf(3) function.
1491 * You may safely pass NULL and 0 to @p buffer and @p size to find the
1492 * required size (without the NUL-byte).
1494 * This function performs Capitalization and Control @ref
1495 * keysym-transformations.
1497 * @memberof xkb_state
1501 xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,
1502 char *buffer, size_t size);
1505 * Get the Unicode/UTF-32 codepoint obtained from pressing a particular
1506 * key in a a given keyboard state.
1508 * @returns The UTF-32 representation for the key, if it consists of only
1509 * a single codepoint. Otherwise, returns 0.
1511 * This function performs Capitalization and Control @ref
1512 * keysym-transformations.
1514 * @memberof xkb_state
1518 xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);
1521 * Get the single keysym obtained from pressing a particular key in a
1522 * given keyboard state.
1524 * This function is similar to xkb_state_key_get_syms(), but intended
1525 * for users which cannot or do not want to handle the case where
1526 * multiple keysyms are returned (in which case this function is
1529 * @returns The keysym. If the key does not have exactly one keysym,
1530 * returns XKB_KEY_NoSymbol
1532 * This function performs Capitalization @ref keysym-transformations.
1534 * @sa xkb_state_key_get_syms()
1535 * @memberof xkb_state
1538 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
1541 * Get the effective layout index for a key in a given keyboard state.
1543 * @returns The layout index for the key in the given keyboard state. If
1544 * the given keycode is invalid, or if the key is not included in any
1545 * layout at all, returns XKB_LAYOUT_INVALID.
1547 * @invariant If the returned layout is valid, the following always holds:
1549 * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
1552 * @memberof xkb_state
1555 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
1558 * Get the effective shift level for a key in a given keyboard state and
1561 * @param state The keyboard state.
1562 * @param key The keycode of the key.
1563 * @param layout The layout for which to get the shift level. This must be
1565 * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
1566 * usually it would be:
1567 * @code xkb_state_key_get_layout(state, key) @endcode
1569 * @return The shift level index. If the key or layout are invalid,
1570 * returns XKB_LEVEL_INVALID.
1572 * @invariant If the returned level is valid, the following always holds:
1574 * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
1577 * @memberof xkb_state
1580 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
1581 xkb_layout_index_t layout);
1584 * Match flags for xkb_state_mod_indices_are_active() and
1585 * xkb_state_mod_names_are_active(), specifying the conditions for a
1586 * successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
1589 enum xkb_state_match {
1590 /** Returns true if any of the modifiers are active. */
1591 XKB_STATE_MATCH_ANY = (1 << 0),
1592 /** Returns true if all of the modifiers are active. */
1593 XKB_STATE_MATCH_ALL = (1 << 1),
1594 /** Makes matching non-exclusive, i.e. will not return false if a
1595 * modifier not specified in the arguments is active. */
1596 XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
1600 * The counterpart to xkb_state_update_mask for modifiers, to be used on
1601 * the server side of serialization.
1603 * @param state The keyboard state.
1604 * @param components A mask of the modifier state components to serialize.
1605 * State components other than XKB_STATE_MODS_* are ignored.
1606 * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
1609 * @returns A xkb_mod_mask_t representing the given components of the
1612 * This function should not be used in regular clients; please use the
1613 * xkb_state_mod_*_is_active API instead.
1615 * @memberof xkb_state
1618 xkb_state_serialize_mods(struct xkb_state *state,
1619 enum xkb_state_component components);
1622 * The counterpart to xkb_state_update_mask for layouts, to be used on
1623 * the server side of serialization.
1625 * @param state The keyboard state.
1626 * @param components A mask of the layout state components to serialize.
1627 * State components other than XKB_STATE_LAYOUT_* are ignored.
1628 * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
1631 * @returns A layout index representing the given components of the
1634 * This function should not be used in regular clients; please use the
1635 * xkb_state_layout_*_is_active API instead.
1637 * @memberof xkb_state
1640 xkb_state_serialize_layout(struct xkb_state *state,
1641 enum xkb_state_component components);
1644 * Test whether a modifier is active in a given keyboard state by name.
1646 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
1647 * name does not exist in the keymap, returns -1.
1649 * @memberof xkb_state
1652 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
1653 enum xkb_state_component type);
1656 * Test whether a set of modifiers are active in a given keyboard state by
1659 * @param state The keyboard state.
1660 * @param type The component of the state against which to match the
1662 * @param match The manner by which to match the state against the
1664 * @param ... The set of of modifier names to test, terminated by a NULL
1665 * argument (sentinel).
1667 * @returns 1 if the modifiers are active, 0 if they are not. If any of
1668 * the modifier names do not exist in the keymap, returns -1.
1670 * @memberof xkb_state
1673 xkb_state_mod_names_are_active(struct xkb_state *state,
1674 enum xkb_state_component type,
1675 enum xkb_state_match match,
1679 * Test whether a modifier is active in a given keyboard state by index.
1681 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
1682 * index is invalid in the keymap, returns -1.
1684 * @memberof xkb_state
1687 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
1688 enum xkb_state_component type);
1691 * Test whether a set of modifiers are active in a given keyboard state by
1694 * @param state The keyboard state.
1695 * @param type The component of the state against which to match the
1697 * @param match The manner by which to match the state against the
1699 * @param ... The set of of modifier indices to test, terminated by a
1700 * XKB_MOD_INVALID argument (sentinel).
1702 * @returns 1 if the modifiers are active, 0 if they are not. If any of
1703 * the modifier indices are invalid in the keymap, returns -1.
1705 * @memberof xkb_state
1708 xkb_state_mod_indices_are_active(struct xkb_state *state,
1709 enum xkb_state_component type,
1710 enum xkb_state_match match,
1714 * @page consumed-modifiers Consumed Modifiers
1717 * Some functions, like xkb_state_key_get_syms(), look at the state of
1718 * the modifiers in the keymap and derive from it the correct shift level
1719 * to use for the key. For example, in a US layout, pressing the key
1720 * labeled \<A\> while the Shift modifier is active, generates the keysym
1721 * 'A'. In this case, the Shift modifier is said to be "consumed".
1722 * However, the Num Lock modifier does not affect this translation at all,
1723 * even if it is active, so it is not consumed by this translation.
1725 * It may be desirable for some application to not reuse consumed modifiers
1726 * for further processing, e.g. for hotkeys or keyboard shortcuts. To
1727 * understand why, consider some requirements from a standard shortcut
1728 * mechanism, and how they are implemented:
1730 * 1. The shortcut's modifiers must match exactly to the state. For
1731 * example, it is possible to bind separate actions to \<Alt\>\<Tab\>
1732 * and to \<Alt\>\<Shift\>\<Tab\>. Further, if only \<Alt\>\<Tab\> is
1733 * bound to an action, pressing \<Alt\>\<Shift\>\<Tab\> should not
1734 * trigger the shortcut.
1735 * Effectively, this means that the modifiers are compared using the
1736 * equality operator (==).
1738 * 2. Only relevant modifiers are considered for the matching. For example,
1739 * Caps Lock and Num Lock should not generally affect the matching, e.g.
1740 * when matching \<Alt\>\<Tab\> against the state, it does not matter
1741 * whether Num Lock is active or not. These relevant, or "significant",
1742 * modifiers usually include Alt, Control, Shift, Super and similar.
1743 * Effectively, this means that non-significant modifiers are masked out,
1744 * before doing the comparison as described above.
1746 * 3. The matching must be independent of the layout/keymap. For example,
1747 * the \<Plus\> (+) symbol is found on the first level on some layouts,
1748 * but requires holding Shift on others. If you simply bind the action
1749 * to the \<Plus\> keysym, it would work for the unshifted kind, but
1750 * not for the others, because the match against Shift would fail. If
1751 * you bind the action to \<Shift\>\<Plus\>, only the shifted kind would
1752 * work. So what is needed is to recognize that Shift is used up in the
1753 * translation of the keysym itself, and therefore should not be included
1755 * Effectively, this means that consumed modifiers (Shift in this example)
1756 * are masked out as well, before doing the comparison.
1758 * In summary, this is approximately how the matching would be performed:
1760 * (keysym == shortcut_keysym) &&
1761 * ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)
1764 * @c state_mods are the modifiers reported by
1765 * xkb_state_mod_index_is_active() and similar functions.
1766 * @c consumed_mods are the modifiers reported by
1767 * xkb_state_mod_index_is_consumed() and similar functions.
1768 * @c significant_mods are decided upon by the application/toolkit/user;
1769 * it is up to them to decide whether these are configurable or hard-coded.
1775 * Consumed modifiers mode.
1777 * There are several possible methods for deciding which modifiers are
1778 * consumed and which are not, each applicable for different systems or
1779 * situations. The mode selects the method to use.
1781 * Keep in mind that in all methods, the keymap may decide to "preserve"
1782 * a modifier, meaning it is not reported as consumed even if it would
1785 enum xkb_consumed_mode {
1787 * This is the mode defined in the XKB specification and used by libX11.
1789 * A modifier is consumed if and only if it *may affect* key translation.
1791 * For example, if `Control+Alt+<Backspace>` produces some assigned keysym,
1792 * then when pressing just `<Backspace>`, `Control` and `Alt` are consumed,
1793 * even though they are not active, since if they *were* active they would
1794 * have affected key translation.
1796 XKB_CONSUMED_MODE_XKB,
1798 * This is the mode used by the GTK+ toolkit.
1800 * The mode consists of the following two independent heuristics:
1802 * - The currently active set of modifiers, excluding modifiers which do
1803 * not affect the key (as described for @ref XKB_CONSUMED_MODE_XKB), are
1804 * considered consumed, if the keysyms produced when all of them are
1805 * active are different from the keysyms produced when no modifiers are
1808 * - A single modifier is considered consumed if the keysyms produced for
1809 * the key when it is the only active modifier are different from the
1810 * keysyms produced when no modifiers are active.
1812 XKB_CONSUMED_MODE_GTK
1816 * Get the mask of modifiers consumed by translating a given key.
1818 * @param state The keyboard state.
1819 * @param key The keycode of the key.
1820 * @param mode The consumed modifiers mode to use; see enum description.
1822 * @returns a mask of the consumed modifiers.
1824 * @memberof xkb_state
1828 xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t key,
1829 enum xkb_consumed_mode mode);
1832 * Same as xkb_state_key_get_consumed_mods2() with mode XKB_CONSUMED_MODE_XKB.
1834 * @memberof xkb_state
1838 xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
1841 * Test whether a modifier is consumed by keyboard state translation for
1844 * @param state The keyboard state.
1845 * @param key The keycode of the key.
1846 * @param idx The index of the modifier to check.
1847 * @param mode The consumed modifiers mode to use; see enum description.
1849 * @returns 1 if the modifier is consumed, 0 if it is not. If the modifier
1850 * index is not valid in the keymap, returns -1.
1852 * @sa xkb_state_mod_mask_remove_consumed()
1853 * @sa xkb_state_key_get_consumed_mods()
1854 * @memberof xkb_state
1858 xkb_state_mod_index_is_consumed2(struct xkb_state *state,
1860 xkb_mod_index_t idx,
1861 enum xkb_consumed_mode mode);
1864 * Same as xkb_state_mod_index_is_consumed2() with mode XKB_CONSUMED_MOD_XKB.
1866 * @memberof xkb_state
1870 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
1871 xkb_mod_index_t idx);
1874 * Remove consumed modifiers from a modifier mask for a key.
1876 * @deprecated Use xkb_state_key_get_consumed_mods2() instead.
1878 * Takes the given modifier mask, and removes all modifiers which are
1879 * consumed for that particular key (as in xkb_state_mod_index_is_consumed()).
1881 * @sa xkb_state_mod_index_is_consumed()
1882 * @memberof xkb_state
1885 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
1886 xkb_mod_mask_t mask);
1889 * Test whether a layout is active in a given keyboard state by name.
1891 * @returns 1 if the layout is active, 0 if it is not. If no layout with
1892 * this name exists in the keymap, return -1.
1894 * If multiple layouts in the keymap have this name, the one with the lowest
1897 * @sa xkb_layout_index_t
1898 * @memberof xkb_state
1901 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
1902 enum xkb_state_component type);
1905 * Test whether a layout is active in a given keyboard state by index.
1907 * @returns 1 if the layout is active, 0 if it is not. If the layout index
1908 * is not valid in the keymap, returns -1.
1910 * @sa xkb_layout_index_t
1911 * @memberof xkb_state
1914 xkb_state_layout_index_is_active(struct xkb_state *state,
1915 xkb_layout_index_t idx,
1916 enum xkb_state_component type);
1919 * Test whether a LED is active in a given keyboard state by name.
1921 * @returns 1 if the LED is active, 0 if it not. If no LED with this name
1922 * exists in the keymap, returns -1.
1924 * @sa xkb_led_index_t
1925 * @memberof xkb_state
1928 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
1931 * Test whether a LED is active in a given keyboard state by index.
1933 * @returns 1 if the LED is active, 0 if it not. If the LED index is not
1934 * valid in the keymap, returns -1.
1936 * @sa xkb_led_index_t
1937 * @memberof xkb_state
1940 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
1944 /* Leave this include last, so it can pick up our types, etc. */
1945 #include <xkbcommon/xkbcommon-compat.h>
1951 #endif /* _XKBCOMMON_H_ */