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 * Generally, should either be empty or have the same number of values
359 * as the number of layouts. You may use empty values as in "intl,,neo".
361 * If NULL or the empty string "", and a default value is also used
362 * for the layout, a default value is used. Otherwise no variant is
364 * If the XKB_DEFAULT_VARIANT environment variable is set, it is used
365 * as the default. Otherwise the system default is used.
369 * A comma separated list of options, through which the user specifies
370 * non-layout related preferences, like which key combinations are used
371 * for switching layouts, or which key is the Compose key.
373 * If NULL, a default value is used. If the empty string "", no
375 * If the XKB_DEFAULT_OPTIONS environment variable is set, it is used
376 * as the default. Otherwise the system default is used.
382 * @defgroup keysyms Keysyms
383 * Utility functions related to keysyms.
389 * @page keysym-transformations Keysym Transformations
391 * Keysym translation is subject to several "keysym transformations",
392 * as described in the XKB specification. These are:
394 * - Capitalization transformation. If the Caps Lock modifier is
395 * active and was not consumed by the translation process, a single
396 * keysym is transformed to its upper-case form (if applicable).
397 * Similarly, the UTF-8/UTF-32 string produced is capitalized.
399 * This is described in:
400 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier
402 * - Control transformation. If the Control modifier is active and
403 * was not consumed by the translation process, the string produced
404 * is transformed to its matching ASCII control character (if
405 * applicable). Keysyms are not affected.
407 * This is described in:
408 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
410 * Each relevant function discusses which transformations it performs.
412 * These transformations are not applicable when a key produces multiple
418 * Get the name of a keysym.
420 * For a description of how keysyms are named, see @ref xkb_keysym_t.
422 * @param[in] keysym The keysym.
423 * @param[out] buffer A string buffer to write the name into.
424 * @param[in] size Size of the buffer.
426 * @warning If the buffer passed is too small, the string is truncated
427 * (though still NUL-terminated); a size of at least 64 bytes is recommended.
429 * @returns The number of bytes in the name, excluding the NUL byte. If
430 * the keysym is invalid, returns -1.
432 * You may check if truncation has occurred by comparing the return value
433 * with the length of buffer, similarly to the snprintf(3) function.
438 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
440 /** Flags for xkb_keysym_from_name(). */
441 enum xkb_keysym_flags {
442 /** Do not apply any flags. */
443 XKB_KEYSYM_NO_FLAGS = 0,
444 /** Find keysym by case-insensitive search. */
445 XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
449 * Get a keysym from its name.
451 * @param name The name of a keysym. See remarks in xkb_keysym_get_name();
452 * this function will accept any name returned by that function.
453 * @param flags A set of flags controlling how the search is done. If
454 * invalid flags are passed, this will fail with XKB_KEY_NoSymbol.
456 * If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names
457 * differ only by case, then the lower-case keysym is returned. For
458 * instance, for KEY_a and KEY_A, this function would return KEY_a for the
459 * case-insensitive search. If this functionality is needed, it is
460 * recommended to first call this function without this flag; and if that
461 * fails, only then to try with this flag, while possibly warning the user
462 * he had misspelled the name, and might get wrong results.
464 * Case folding is done according to the C locale; the current locale is not
467 * @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.
472 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
475 * Get the Unicode/UTF-8 representation of a keysym.
477 * @param[in] keysym The keysym.
478 * @param[out] buffer A buffer to write the UTF-8 string into.
479 * @param[in] size The size of buffer. Must be at least 7.
481 * @returns The number of bytes written to the buffer (including the
482 * terminating byte). If the keysym does not have a Unicode
483 * representation, returns 0. If the buffer is too small, returns -1.
485 * This function does not perform any @ref keysym-transformations.
486 * Therefore, prefer to use xkb_state_key_get_utf8() if possible.
488 * @sa xkb_state_key_get_utf8()
491 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
494 * Get the Unicode/UTF-32 representation of a keysym.
496 * @returns The Unicode/UTF-32 representation of keysym, which is also
497 * compatible with UCS-4. If the keysym does not have a Unicode
498 * representation, returns 0.
500 * This function does not perform any @ref keysym-transformations.
501 * Therefore, prefer to use xkb_state_key_get_utf32() if possible.
503 * @sa xkb_state_key_get_utf32()
506 xkb_keysym_to_utf32(xkb_keysym_t keysym);
509 * Get the keysym corresponding to a Unicode/UTF-32 codepoint.
511 * @returns The keysym corresponding to the specified Unicode
512 * codepoint, or XKB_KEY_NoSymbol if there is none.
514 * This function is the inverse of @ref xkb_keysym_to_utf32. In cases
515 * where a single codepoint corresponds to multiple keysyms, returns
516 * the keysym with the lowest value.
518 * Unicode codepoints which do not have a special (legacy) keysym
519 * encoding use a direct encoding scheme. These keysyms don't usually
520 * have an associated keysym constant (XKB_KEY_*).
522 * For noncharacter Unicode codepoints and codepoints outside of the
523 * defined Unicode planes this function returns XKB_KEY_NoSymbol.
525 * @sa xkb_keysym_to_utf32()
529 xkb_utf32_to_keysym(uint32_t ucs);
532 * Convert a keysym to its uppercase form.
534 * If there is no such form, the keysym is returned unchanged.
536 * The conversion rules may be incomplete; prefer to work with the Unicode
537 * representation instead, when possible.
540 xkb_keysym_to_upper(xkb_keysym_t ks);
543 * Convert a keysym to its lowercase form.
545 * The conversion rules may be incomplete; prefer to work with the Unicode
546 * representation instead, when possible.
549 xkb_keysym_to_lower(xkb_keysym_t ks);
554 * @defgroup context Library Context
555 * Creating, destroying and using library contexts.
557 * Every keymap compilation request must have a context associated with
558 * it. The context keeps around state such as the include path.
564 * @page envvars Environment Variables
566 * The user may set some environment variables which affect the library:
568 * - `XKB_CONFIG_ROOT`, `XKB_CONFIG_EXTRA_PATH`, `XDG_CONFIG_DIR`, `HOME` - see @ref include-path.
569 * - `XKB_LOG_LEVEL` - see xkb_context_set_log_level().
570 * - `XKB_LOG_VERBOSITY` - see xkb_context_set_log_verbosity().
571 * - `XKB_DEFAULT_RULES`, `XKB_DEFAULT_MODEL`, `XKB_DEFAULT_LAYOUT`,
572 * `XKB_DEFAULT_VARIANT`, `XKB_DEFAULT_OPTIONS` - see xkb_rule_names.
575 /** Flags for context creation. */
576 enum xkb_context_flags {
577 /** Do not apply any context flags. */
578 XKB_CONTEXT_NO_FLAGS = 0,
579 /** Create this context with an empty include path. */
580 XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
582 * Don't take RMLVO names from the environment.
586 XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1),
588 * Disable the use of secure_getenv for this context, so that privileged
589 * processes can use environment variables. Client uses at their own risk.
593 XKB_CONTEXT_NO_SECURE_GETENV = (1 << 2)
597 * Create a new context.
599 * @param flags Optional flags for the context, or 0.
601 * @returns A new context, or NULL on failure.
603 * @memberof xkb_context
606 xkb_context_new(enum xkb_context_flags flags);
609 * Take a new reference on a context.
611 * @returns The passed in context.
613 * @memberof xkb_context
616 xkb_context_ref(struct xkb_context *context);
619 * Release a reference on a context, and possibly free it.
621 * @param context The context. If it is NULL, this function does nothing.
623 * @memberof xkb_context
626 xkb_context_unref(struct xkb_context *context);
629 * Store custom user data in the context.
631 * This may be useful in conjunction with xkb_context_set_log_fn() or other
634 * @memberof xkb_context
637 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
640 * Retrieves stored user data from the context.
642 * @returns The stored user data. If the user data wasn't set, or the
643 * passed in context is NULL, returns NULL.
645 * This may be useful to access private user data from callbacks like a
646 * custom logging function.
648 * @memberof xkb_context
651 xkb_context_get_user_data(struct xkb_context *context);
656 * @defgroup include-path Include Paths
657 * Manipulating the include paths in a context.
659 * The include paths are the file-system paths that are searched when an
660 * include statement is encountered during keymap compilation.
662 * The default include paths are, in that lookup order:
663 * - The path `$XDG_CONFIG_HOME/xkb`, with the usual `XDG_CONFIG_HOME`
664 * fallback to `$HOME/.config/` if unset.
665 * - The path `$HOME/.xkb`, where $HOME is the value of the environment
667 * - The `XKB_CONFIG_EXTRA_PATH` environment variable, if defined, otherwise the
668 * system configuration directory, defined at library configuration time
669 * (usually `/etc/xkb`).
670 * - The `XKB_CONFIG_ROOT` environment variable, if defined, otherwise
671 * the system XKB root, defined at library configuration time.
677 * Append a new entry to the context's include path.
679 * @returns 1 on success, or 0 if the include path could not be added or is
682 * @memberof xkb_context
685 xkb_context_include_path_append(struct xkb_context *context, const char *path);
688 * Append the default include paths to the context's include path.
690 * @returns 1 on success, or 0 if the primary include path could not be added.
692 * @memberof xkb_context
695 xkb_context_include_path_append_default(struct xkb_context *context);
698 * Reset the context's include path to the default.
700 * Removes all entries from the context's include path, and inserts the
703 * @returns 1 on success, or 0 if the primary include path could not be added.
705 * @memberof xkb_context
708 xkb_context_include_path_reset_defaults(struct xkb_context *context);
711 * Remove all entries from the context's include path.
713 * @memberof xkb_context
716 xkb_context_include_path_clear(struct xkb_context *context);
719 * Get the number of paths in the context's include path.
721 * @memberof xkb_context
724 xkb_context_num_include_paths(struct xkb_context *context);
727 * Get a specific include path from the context's include path.
729 * @returns The include path at the specified index. If the index is
730 * invalid, returns NULL.
732 * @memberof xkb_context
735 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
740 * @defgroup logging Logging Handling
741 * Manipulating how logging from this library is handled.
746 /** Specifies a logging level. */
748 XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
749 XKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */
750 XKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */
751 XKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */
752 XKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */
756 * Set the current logging level.
758 * @param context The context in which to set the logging level.
759 * @param level The logging level to use. Only messages from this level
760 * and below will be logged.
762 * The default level is XKB_LOG_LEVEL_ERROR. The environment variable
763 * XKB_LOG_LEVEL, if set in the time the context was created, overrides the
764 * default value. It may be specified as a level number or name.
766 * @memberof xkb_context
769 xkb_context_set_log_level(struct xkb_context *context,
770 enum xkb_log_level level);
773 * Get the current logging level.
775 * @memberof xkb_context
778 xkb_context_get_log_level(struct xkb_context *context);
781 * Sets the current logging verbosity.
783 * The library can generate a number of warnings which are not helpful to
784 * ordinary users of the library. The verbosity may be increased if more
785 * information is desired (e.g. when developing a new keymap).
787 * The default verbosity is 0. The environment variable XKB_LOG_VERBOSITY,
788 * if set in the time the context was created, overrides the default value.
790 * @param context The context in which to use the set verbosity.
791 * @param verbosity The verbosity to use. Currently used values are
792 * 1 to 10, higher values being more verbose. 0 would result in no verbose
793 * messages being logged.
795 * Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
797 * @memberof xkb_context
800 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
803 * Get the current logging verbosity of the context.
805 * @memberof xkb_context
808 xkb_context_get_log_verbosity(struct xkb_context *context);
811 * Set a custom function to handle logging messages.
813 * @param context The context in which to use the set logging function.
814 * @param log_fn The function that will be called for logging messages.
815 * Passing NULL restores the default function, which logs to stderr.
817 * By default, log messages from this library are printed to stderr. This
818 * function allows you to replace the default behavior with a custom
819 * handler. The handler is only called with messages which match the
820 * current logging level and verbosity settings for the context.
821 * level is the logging level of the message. @a format and @a args are
822 * the same as in the vprintf(3) function.
824 * You may use xkb_context_set_user_data() on the context, and then call
825 * xkb_context_get_user_data() from within the logging function to provide
826 * it with additional private context.
828 * @memberof xkb_context
831 xkb_context_set_log_fn(struct xkb_context *context,
832 void (*log_fn)(struct xkb_context *context,
833 enum xkb_log_level level,
834 const char *format, va_list args));
839 * @defgroup keymap Keymap Creation
840 * Creating and destroying keymaps.
845 /** Flags for keymap compilation. */
846 enum xkb_keymap_compile_flags {
847 /** Do not apply any flags. */
848 XKB_KEYMAP_COMPILE_NO_FLAGS = 0
852 * Create a keymap from RMLVO names.
854 * The primary keymap entry point: creates a new XKB keymap from a set of
855 * RMLVO (Rules + Model + Layouts + Variants + Options) names.
857 * @param context The context in which to create the keymap.
858 * @param names The RMLVO names to use. See xkb_rule_names.
859 * @param flags Optional flags for the keymap, or 0.
861 * @returns A keymap compiled according to the RMLVO names, or NULL if
862 * the compilation failed.
865 * @memberof xkb_keymap
868 xkb_keymap_new_from_names(struct xkb_context *context,
869 const struct xkb_rule_names *names,
870 enum xkb_keymap_compile_flags flags);
872 /** The possible keymap formats. */
873 enum xkb_keymap_format {
874 /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
875 XKB_KEYMAP_FORMAT_TEXT_V1 = 1
879 * Create a keymap from a keymap file.
881 * @param context The context in which to create the keymap.
882 * @param file The keymap file to compile.
883 * @param format The text format of the keymap file to compile.
884 * @param flags Optional flags for the keymap, or 0.
886 * @returns A keymap compiled from the given XKB keymap file, or NULL if
887 * the compilation failed.
889 * The file must contain a complete keymap. For example, in the
890 * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
891 * top level '%xkb_keymap' section, which in turn contains other required
894 * @memberof xkb_keymap
897 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
898 enum xkb_keymap_format format,
899 enum xkb_keymap_compile_flags flags);
902 * Create a keymap from a keymap string.
904 * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
905 * the keymap as one enormous string.
907 * @see xkb_keymap_new_from_file()
908 * @memberof xkb_keymap
911 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
912 enum xkb_keymap_format format,
913 enum xkb_keymap_compile_flags flags);
916 * Create a keymap from a memory buffer.
918 * This is just like xkb_keymap_new_from_string(), but takes a length argument
919 * so the input string does not have to be zero-terminated.
921 * @see xkb_keymap_new_from_string()
922 * @memberof xkb_keymap
926 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
927 size_t length, enum xkb_keymap_format format,
928 enum xkb_keymap_compile_flags flags);
931 * Take a new reference on a keymap.
933 * @returns The passed in keymap.
935 * @memberof xkb_keymap
938 xkb_keymap_ref(struct xkb_keymap *keymap);
941 * Release a reference on a keymap, and possibly free it.
943 * @param keymap The keymap. If it is NULL, this function does nothing.
945 * @memberof xkb_keymap
948 xkb_keymap_unref(struct xkb_keymap *keymap);
951 * Get the keymap as a string in the format from which it was created.
952 * @sa xkb_keymap_get_as_string()
954 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
957 * Get the compiled keymap as a string.
959 * @param keymap The keymap to get as a string.
960 * @param format The keymap format to use for the string. You can pass
961 * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
962 * from which the keymap was originally created.
964 * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
966 * The returned string may be fed back into xkb_keymap_new_from_string() to get
967 * the exact same keymap (possibly in another process, etc.).
969 * The returned string is dynamically allocated and should be freed by the
972 * @memberof xkb_keymap
975 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
976 enum xkb_keymap_format format);
981 * @defgroup components Keymap Components
982 * Enumeration of state components in a keymap.
988 * Get the minimum keycode in the keymap.
991 * @memberof xkb_keymap
995 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
998 * Get the maximum keycode in the keymap.
1001 * @memberof xkb_keymap
1005 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
1008 * The iterator used by xkb_keymap_key_for_each().
1010 * @sa xkb_keymap_key_for_each
1011 * @memberof xkb_keymap
1015 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
1019 * Run a specified function for every valid keycode in the keymap. If a
1020 * keymap is sparse, this function may be called fewer than
1021 * (max_keycode - min_keycode + 1) times.
1023 * @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t
1024 * @memberof xkb_keymap
1028 xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
1032 * Find the name of the key with the given keycode.
1034 * This function always returns the canonical name of the key (see
1035 * description in xkb_keycode_t).
1037 * @returns The key name. If no key with this keycode exists,
1041 * @memberof xkb_keymap
1045 xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);
1048 * Find the keycode of the key with the given name.
1050 * The name can be either a canonical name or an alias.
1052 * @returns The keycode. If no key with this name exists,
1053 * returns XKB_KEYCODE_INVALID.
1056 * @memberof xkb_keymap
1060 xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);
1063 * Get the number of modifiers in the keymap.
1065 * @sa xkb_mod_index_t
1066 * @memberof xkb_keymap
1069 xkb_keymap_num_mods(struct xkb_keymap *keymap);
1072 * Get the name of a modifier by index.
1074 * @returns The name. If the index is invalid, returns NULL.
1076 * @sa xkb_mod_index_t
1077 * @memberof xkb_keymap
1080 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
1083 * Get the index of a modifier by name.
1085 * @returns The index. If no modifier with this name exists, returns
1088 * @sa xkb_mod_index_t
1089 * @memberof xkb_keymap
1092 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
1095 * Get the number of layouts in the keymap.
1097 * @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()
1098 * @memberof xkb_keymap
1101 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
1104 * Get the name of a layout by index.
1106 * @returns The name. If the index is invalid, or the layout does not have
1107 * a name, returns NULL.
1109 * @sa xkb_layout_index_t
1110 * For notes on layout names.
1111 * @memberof xkb_keymap
1114 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
1117 * Get the index of a layout by name.
1119 * @returns The index. If no layout exists with this name, returns
1120 * XKB_LAYOUT_INVALID. If more than one layout in the keymap has this name,
1121 * returns the lowest index among them.
1123 * @sa xkb_layout_index_t
1124 * For notes on layout names.
1125 * @memberof xkb_keymap
1128 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
1131 * Get the number of LEDs in the keymap.
1133 * @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs
1134 * in the keymap, but may also contain inactive LEDs. When iterating over
1135 * this range, you need the handle this case when calling functions such as
1136 * xkb_keymap_led_get_name() or xkb_state_led_index_is_active().
1138 * @sa xkb_led_index_t
1139 * @memberof xkb_keymap
1142 xkb_keymap_num_leds(struct xkb_keymap *keymap);
1145 * Get the name of a LED by index.
1147 * @returns The name. If the index is invalid, returns NULL.
1149 * @memberof xkb_keymap
1152 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1155 * Get the index of a LED by name.
1157 * @returns The index. If no LED with this name exists, returns
1160 * @memberof xkb_keymap
1163 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1166 * Get the number of layouts for a specific key.
1168 * This number can be different from xkb_keymap_num_layouts(), but is always
1169 * smaller. It is the appropriate value to use when iterating over the
1172 * @sa xkb_layout_index_t
1173 * @memberof xkb_keymap
1176 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
1179 * Get the number of shift levels for a specific key and layout.
1181 * If @c layout is out of range for this key (that is, larger or equal to
1182 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1183 * back into range in a manner consistent with xkb_state_key_get_layout().
1185 * @sa xkb_level_index_t
1186 * @memberof xkb_keymap
1189 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
1190 xkb_layout_index_t layout);
1193 * Retrieves every possible modifier mask that produces the specified
1194 * shift level for a specific key and layout.
1196 * This API is useful for inverse key transformation; i.e. finding out
1197 * which modifiers need to be active in order to be able to type the
1198 * keysym(s) corresponding to the specific key code, layout and level.
1200 * @warning It returns only up to masks_size modifier masks. If the
1201 * buffer passed is too small, some of the possible modifier combinations
1202 * will not be returned.
1204 * @param[in] keymap The keymap.
1205 * @param[in] key The keycode of the key.
1206 * @param[in] layout The layout for which to get modifiers.
1207 * @param[in] level The shift level in the layout for which to get the
1208 * modifiers. This should be smaller than:
1209 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1210 * @param[out] masks_out A buffer in which the requested masks should be
1212 * @param[out] masks_size The number of elements in the buffer pointed to by
1215 * If @c layout is out of range for this key (that is, larger or equal to
1216 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1217 * back into range in a manner consistent with xkb_state_key_get_layout().
1219 * @returns The number of modifier masks stored in the masks_out array.
1220 * If the key is not in the keymap or if the specified shift level cannot
1221 * be reached it returns 0 and does not modify the masks_out buffer.
1223 * @sa xkb_level_index_t
1224 * @sa xkb_mod_mask_t
1225 * @memberof xkb_keymap
1229 xkb_keymap_key_get_mods_for_level(struct xkb_keymap *keymap,
1231 xkb_layout_index_t layout,
1232 xkb_level_index_t level,
1233 xkb_mod_mask_t *masks_out,
1237 * Get the keysyms obtained from pressing a key in a given layout and
1240 * This function is like xkb_state_key_get_syms(), only the layout and
1241 * shift level are not derived from the keyboard state but are instead
1242 * specified explicitly.
1244 * @param[in] keymap The keymap.
1245 * @param[in] key The keycode of the key.
1246 * @param[in] layout The layout for which to get the keysyms.
1247 * @param[in] level The shift level in the layout for which to get the
1248 * keysyms. This should be smaller than:
1249 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1250 * @param[out] syms_out An immutable array of keysyms corresponding to the
1251 * key in the given layout and shift level.
1253 * If @c layout is out of range for this key (that is, larger or equal to
1254 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1255 * back into range in a manner consistent with xkb_state_key_get_layout().
1257 * @returns The number of keysyms in the syms_out array. If no keysyms
1258 * are produced by the key in the given layout and shift level, returns 0
1259 * and sets syms_out to NULL.
1261 * @sa xkb_state_key_get_syms()
1262 * @memberof xkb_keymap
1265 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
1267 xkb_layout_index_t layout,
1268 xkb_level_index_t level,
1269 const xkb_keysym_t **syms_out);
1272 * Determine whether a key should repeat or not.
1274 * A keymap may specify different repeat behaviors for different keys.
1275 * Most keys should generally exhibit repeat behavior; for example, holding
1276 * the 'a' key down in a text editor should normally insert a single 'a'
1277 * character every few milliseconds, until the key is released. However,
1278 * there are keys which should not or do not need to be repeated. For
1279 * example, repeating modifier keys such as Left/Right Shift or Caps Lock
1280 * is not generally useful or desired.
1282 * @returns 1 if the key should repeat, 0 otherwise.
1284 * @memberof xkb_keymap
1287 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1292 * @defgroup state Keyboard State
1293 * Creating, destroying and manipulating keyboard state objects.
1299 * Create a new keyboard state object.
1301 * @param keymap The keymap which the state will use.
1303 * @returns A new keyboard state object, or NULL on failure.
1305 * @memberof xkb_state
1308 xkb_state_new(struct xkb_keymap *keymap);
1311 * Take a new reference on a keyboard state object.
1313 * @returns The passed in object.
1315 * @memberof xkb_state
1318 xkb_state_ref(struct xkb_state *state);
1321 * Release a reference on a keybaord state object, and possibly free it.
1323 * @param state The state. If it is NULL, this function does nothing.
1325 * @memberof xkb_state
1328 xkb_state_unref(struct xkb_state *state);
1331 * Get the keymap which a keyboard state object is using.
1333 * @returns The keymap which was passed to xkb_state_new() when creating
1334 * this state object.
1336 * This function does not take a new reference on the keymap; you must
1337 * explicitly reference it yourself if you plan to use it beyond the
1338 * lifetime of the state.
1340 * @memberof xkb_state
1343 xkb_state_get_keymap(struct xkb_state *state);
1346 * @page server-client-state Server State and Client State
1349 * The xkb_state API is used by two distinct actors in most window-system
1352 * 1. A *server* - for example, a Wayland compositor, an X11 server, an evdev
1355 * Servers maintain the XKB state for a device according to input events from
1356 * the device, such as key presses and releases, and out-of-band events from
1357 * the user, like UI layout switchers.
1359 * 2. A *client* - for example, a Wayland client, an X11 client.
1361 * Clients do not listen to input from the device; instead, whenever the
1362 * server state changes, the server serializes the state and notifies the
1363 * clients that the state has changed; the clients then update the state
1364 * from the serialization.
1366 * Some entry points in the xkb_state API are only meant for servers and some
1367 * are only meant for clients, and the two should generally not be mixed.
1372 /** Specifies the direction of the key (press / release). */
1373 enum xkb_key_direction {
1374 XKB_KEY_UP, /**< The key was released. */
1375 XKB_KEY_DOWN /**< The key was pressed. */
1379 * Modifier and layout types for state objects. This enum is bitmaskable,
1380 * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
1381 * exclude locked modifiers.
1383 * In XKB, the DEPRESSED components are also known as 'base'.
1385 enum xkb_state_component {
1386 /** Depressed modifiers, i.e. a key is physically holding them. */
1387 XKB_STATE_MODS_DEPRESSED = (1 << 0),
1388 /** Latched modifiers, i.e. will be unset after the next non-modifier
1390 XKB_STATE_MODS_LATCHED = (1 << 1),
1391 /** Locked modifiers, i.e. will be unset after the key provoking the
1392 * lock has been pressed again. */
1393 XKB_STATE_MODS_LOCKED = (1 << 2),
1394 /** Effective modifiers, i.e. currently active and affect key
1395 * processing (derived from the other state components).
1396 * Use this unless you explicitly care how the state came about. */
1397 XKB_STATE_MODS_EFFECTIVE = (1 << 3),
1398 /** Depressed layout, i.e. a key is physically holding it. */
1399 XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
1400 /** Latched layout, i.e. will be unset after the next non-modifier
1402 XKB_STATE_LAYOUT_LATCHED = (1 << 5),
1403 /** Locked layout, i.e. will be unset after the key provoking the lock
1404 * has been pressed again. */
1405 XKB_STATE_LAYOUT_LOCKED = (1 << 6),
1406 /** Effective layout, i.e. currently active and affects key processing
1407 * (derived from the other state components).
1408 * Use this unless you explicitly care how the state came about. */
1409 XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
1410 /** LEDs (derived from the other state components). */
1411 XKB_STATE_LEDS = (1 << 8)
1415 * Update the keyboard state to reflect a given key being pressed or
1418 * This entry point is intended for *server* applications and should not be used
1419 * by *client* applications; see @ref server-client-state for details.
1421 * A series of calls to this function should be consistent; that is, a call
1422 * with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key
1423 * is pressed twice, it should be released twice; etc. Otherwise (e.g. due
1424 * to missed input events), situations like "stuck modifiers" may occur.
1426 * This function is often used in conjunction with the function
1427 * xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,
1428 * when handling a key event. In this case, you should prefer to get the
1429 * keysyms *before* updating the key, such that the keysyms reported for
1430 * the key event are not affected by the event itself. This is the
1431 * conventional behavior.
1433 * @returns A mask of state components that have changed as a result of
1434 * the update. If nothing in the state has changed, returns 0.
1436 * @memberof xkb_state
1438 * @sa xkb_state_update_mask()
1440 enum xkb_state_component
1441 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1442 enum xkb_key_direction direction);
1445 * Update a keyboard state from a set of explicit masks.
1447 * This entry point is intended for *client* applications; see @ref
1448 * server-client-state for details. *Server* applications should use
1449 * xkb_state_update_key() instead.
1451 * All parameters must always be passed, or the resulting state may be
1454 * The serialization is lossy and will not survive round trips; it must only
1455 * be used to feed client state objects, and must not be used to update the
1458 * @returns A mask of state components that have changed as a result of
1459 * the update. If nothing in the state has changed, returns 0.
1461 * @memberof xkb_state
1463 * @sa xkb_state_component
1464 * @sa xkb_state_update_key
1466 enum xkb_state_component
1467 xkb_state_update_mask(struct xkb_state *state,
1468 xkb_mod_mask_t depressed_mods,
1469 xkb_mod_mask_t latched_mods,
1470 xkb_mod_mask_t locked_mods,
1471 xkb_layout_index_t depressed_layout,
1472 xkb_layout_index_t latched_layout,
1473 xkb_layout_index_t locked_layout);
1476 * Get the keysyms obtained from pressing a particular key in a given
1479 * Get the keysyms for a key according to the current active layout,
1480 * modifiers and shift level for the key, as determined by a keyboard
1483 * @param[in] state The keyboard state object.
1484 * @param[in] key The keycode of the key.
1485 * @param[out] syms_out An immutable array of keysyms corresponding the
1486 * key in the given keyboard state.
1488 * As an extension to XKB, this function can return more than one keysym.
1489 * If you do not want to handle this case, you can use
1490 * xkb_state_key_get_one_sym() for a simpler interface.
1492 * This function does not perform any @ref keysym-transformations.
1493 * (This might change).
1495 * @returns The number of keysyms in the syms_out array. If no keysyms
1496 * are produced by the key in the given keyboard state, returns 0 and sets
1499 * @memberof xkb_state
1502 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
1503 const xkb_keysym_t **syms_out);
1506 * Get the Unicode/UTF-8 string obtained from pressing a particular key
1507 * in a given keyboard state.
1509 * @param[in] state The keyboard state object.
1510 * @param[in] key The keycode of the key.
1511 * @param[out] buffer A buffer to write the string into.
1512 * @param[in] size Size of the buffer.
1514 * @warning If the buffer passed is too small, the string is truncated
1515 * (though still NUL-terminated).
1517 * @returns The number of bytes required for the string, excluding the
1518 * NUL byte. If there is nothing to write, returns 0.
1520 * You may check if truncation has occurred by comparing the return value
1521 * with the size of @p buffer, similarly to the snprintf(3) function.
1522 * You may safely pass NULL and 0 to @p buffer and @p size to find the
1523 * required size (without the NUL-byte).
1525 * This function performs Capitalization and Control @ref
1526 * keysym-transformations.
1528 * @memberof xkb_state
1532 xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,
1533 char *buffer, size_t size);
1536 * Get the Unicode/UTF-32 codepoint obtained from pressing a particular
1537 * key in a a given keyboard state.
1539 * @returns The UTF-32 representation for the key, if it consists of only
1540 * a single codepoint. Otherwise, returns 0.
1542 * This function performs Capitalization and Control @ref
1543 * keysym-transformations.
1545 * @memberof xkb_state
1549 xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);
1552 * Get the single keysym obtained from pressing a particular key in a
1553 * given keyboard state.
1555 * This function is similar to xkb_state_key_get_syms(), but intended
1556 * for users which cannot or do not want to handle the case where
1557 * multiple keysyms are returned (in which case this function is
1560 * @returns The keysym. If the key does not have exactly one keysym,
1561 * returns XKB_KEY_NoSymbol
1563 * This function performs Capitalization @ref keysym-transformations.
1565 * @sa xkb_state_key_get_syms()
1566 * @memberof xkb_state
1569 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
1572 * Get the effective layout index for a key in a given keyboard state.
1574 * @returns The layout index for the key in the given keyboard state. If
1575 * the given keycode is invalid, or if the key is not included in any
1576 * layout at all, returns XKB_LAYOUT_INVALID.
1578 * @invariant If the returned layout is valid, the following always holds:
1580 * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
1583 * @memberof xkb_state
1586 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
1589 * Get the effective shift level for a key in a given keyboard state and
1592 * @param state The keyboard state.
1593 * @param key The keycode of the key.
1594 * @param layout The layout for which to get the shift level. This must be
1596 * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
1597 * usually it would be:
1598 * @code xkb_state_key_get_layout(state, key) @endcode
1600 * @return The shift level index. If the key or layout are invalid,
1601 * returns XKB_LEVEL_INVALID.
1603 * @invariant If the returned level is valid, the following always holds:
1605 * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
1608 * @memberof xkb_state
1611 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
1612 xkb_layout_index_t layout);
1615 * Match flags for xkb_state_mod_indices_are_active() and
1616 * xkb_state_mod_names_are_active(), specifying the conditions for a
1617 * successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
1620 enum xkb_state_match {
1621 /** Returns true if any of the modifiers are active. */
1622 XKB_STATE_MATCH_ANY = (1 << 0),
1623 /** Returns true if all of the modifiers are active. */
1624 XKB_STATE_MATCH_ALL = (1 << 1),
1625 /** Makes matching non-exclusive, i.e. will not return false if a
1626 * modifier not specified in the arguments is active. */
1627 XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
1631 * The counterpart to xkb_state_update_mask for modifiers, to be used on
1632 * the server side of serialization.
1634 * This entry point is intended for *server* applications; see @ref
1635 * server-client-state for details. *Client* applications should use the
1636 * xkb_state_mod_*_is_active API.
1638 * @param state The keyboard state.
1639 * @param components A mask of the modifier state components to serialize.
1640 * State components other than XKB_STATE_MODS_* are ignored.
1641 * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
1644 * @returns A xkb_mod_mask_t representing the given components of the
1647 * @memberof xkb_state
1650 xkb_state_serialize_mods(struct xkb_state *state,
1651 enum xkb_state_component components);
1654 * The counterpart to xkb_state_update_mask for layouts, to be used on
1655 * the server side of serialization.
1657 * This entry point is intended for *server* applications; see @ref
1658 * server-client-state for details. *Client* applications should use the
1659 * xkb_state_layout_*_is_active API.
1661 * @param state The keyboard state.
1662 * @param components A mask of the layout state components to serialize.
1663 * State components other than XKB_STATE_LAYOUT_* are ignored.
1664 * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
1667 * @returns A layout index representing the given components of the
1670 * @memberof xkb_state
1673 xkb_state_serialize_layout(struct xkb_state *state,
1674 enum xkb_state_component components);
1677 * Test whether a modifier is active in a given keyboard state by name.
1679 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
1680 * name does not exist in the keymap, returns -1.
1682 * @memberof xkb_state
1685 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
1686 enum xkb_state_component type);
1689 * Test whether a set of modifiers are active in a given keyboard state by
1692 * @param state The keyboard state.
1693 * @param type The component of the state against which to match the
1695 * @param match The manner by which to match the state against the
1697 * @param ... The set of of modifier names to test, terminated by a NULL
1698 * argument (sentinel).
1700 * @returns 1 if the modifiers are active, 0 if they are not. If any of
1701 * the modifier names do not exist in the keymap, returns -1.
1703 * @memberof xkb_state
1706 xkb_state_mod_names_are_active(struct xkb_state *state,
1707 enum xkb_state_component type,
1708 enum xkb_state_match match,
1712 * Test whether a modifier is active in a given keyboard state by index.
1714 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
1715 * index is invalid in the keymap, returns -1.
1717 * @memberof xkb_state
1720 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
1721 enum xkb_state_component type);
1724 * Test whether a set of modifiers are active in a given keyboard state by
1727 * @param state The keyboard state.
1728 * @param type The component of the state against which to match the
1730 * @param match The manner by which to match the state against the
1732 * @param ... The set of of modifier indices to test, terminated by a
1733 * XKB_MOD_INVALID argument (sentinel).
1735 * @returns 1 if the modifiers are active, 0 if they are not. If any of
1736 * the modifier indices are invalid in the keymap, returns -1.
1738 * @memberof xkb_state
1741 xkb_state_mod_indices_are_active(struct xkb_state *state,
1742 enum xkb_state_component type,
1743 enum xkb_state_match match,
1747 * @page consumed-modifiers Consumed Modifiers
1750 * Some functions, like xkb_state_key_get_syms(), look at the state of
1751 * the modifiers in the keymap and derive from it the correct shift level
1752 * to use for the key. For example, in a US layout, pressing the key
1753 * labeled \<A\> while the Shift modifier is active, generates the keysym
1754 * 'A'. In this case, the Shift modifier is said to be "consumed".
1755 * However, the Num Lock modifier does not affect this translation at all,
1756 * even if it is active, so it is not consumed by this translation.
1758 * It may be desirable for some application to not reuse consumed modifiers
1759 * for further processing, e.g. for hotkeys or keyboard shortcuts. To
1760 * understand why, consider some requirements from a standard shortcut
1761 * mechanism, and how they are implemented:
1763 * 1. The shortcut's modifiers must match exactly to the state. For
1764 * example, it is possible to bind separate actions to \<Alt\>\<Tab\>
1765 * and to \<Alt\>\<Shift\>\<Tab\>. Further, if only \<Alt\>\<Tab\> is
1766 * bound to an action, pressing \<Alt\>\<Shift\>\<Tab\> should not
1767 * trigger the shortcut.
1768 * Effectively, this means that the modifiers are compared using the
1769 * equality operator (==).
1771 * 2. Only relevant modifiers are considered for the matching. For example,
1772 * Caps Lock and Num Lock should not generally affect the matching, e.g.
1773 * when matching \<Alt\>\<Tab\> against the state, it does not matter
1774 * whether Num Lock is active or not. These relevant, or "significant",
1775 * modifiers usually include Alt, Control, Shift, Super and similar.
1776 * Effectively, this means that non-significant modifiers are masked out,
1777 * before doing the comparison as described above.
1779 * 3. The matching must be independent of the layout/keymap. For example,
1780 * the \<Plus\> (+) symbol is found on the first level on some layouts,
1781 * but requires holding Shift on others. If you simply bind the action
1782 * to the \<Plus\> keysym, it would work for the unshifted kind, but
1783 * not for the others, because the match against Shift would fail. If
1784 * you bind the action to \<Shift\>\<Plus\>, only the shifted kind would
1785 * work. So what is needed is to recognize that Shift is used up in the
1786 * translation of the keysym itself, and therefore should not be included
1788 * Effectively, this means that consumed modifiers (Shift in this example)
1789 * are masked out as well, before doing the comparison.
1791 * In summary, this is approximately how the matching would be performed:
1793 * (keysym == shortcut_keysym) &&
1794 * ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)
1797 * @c state_mods are the modifiers reported by
1798 * xkb_state_mod_index_is_active() and similar functions.
1799 * @c consumed_mods are the modifiers reported by
1800 * xkb_state_mod_index_is_consumed() and similar functions.
1801 * @c significant_mods are decided upon by the application/toolkit/user;
1802 * it is up to them to decide whether these are configurable or hard-coded.
1808 * Consumed modifiers mode.
1810 * There are several possible methods for deciding which modifiers are
1811 * consumed and which are not, each applicable for different systems or
1812 * situations. The mode selects the method to use.
1814 * Keep in mind that in all methods, the keymap may decide to "preserve"
1815 * a modifier, meaning it is not reported as consumed even if it would
1818 enum xkb_consumed_mode {
1820 * This is the mode defined in the XKB specification and used by libX11.
1822 * A modifier is consumed if and only if it *may affect* key translation.
1824 * For example, if `Control+Alt+<Backspace>` produces some assigned keysym,
1825 * then when pressing just `<Backspace>`, `Control` and `Alt` are consumed,
1826 * even though they are not active, since if they *were* active they would
1827 * have affected key translation.
1829 XKB_CONSUMED_MODE_XKB,
1831 * This is the mode used by the GTK+ toolkit.
1833 * The mode consists of the following two independent heuristics:
1835 * - The currently active set of modifiers, excluding modifiers which do
1836 * not affect the key (as described for @ref XKB_CONSUMED_MODE_XKB), are
1837 * considered consumed, if the keysyms produced when all of them are
1838 * active are different from the keysyms produced when no modifiers are
1841 * - A single modifier is considered consumed if the keysyms produced for
1842 * the key when it is the only active modifier are different from the
1843 * keysyms produced when no modifiers are active.
1845 XKB_CONSUMED_MODE_GTK
1849 * Get the mask of modifiers consumed by translating a given key.
1851 * @param state The keyboard state.
1852 * @param key The keycode of the key.
1853 * @param mode The consumed modifiers mode to use; see enum description.
1855 * @returns a mask of the consumed modifiers.
1857 * @memberof xkb_state
1861 xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t key,
1862 enum xkb_consumed_mode mode);
1865 * Same as xkb_state_key_get_consumed_mods2() with mode XKB_CONSUMED_MODE_XKB.
1867 * @memberof xkb_state
1871 xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
1874 * Test whether a modifier is consumed by keyboard state translation for
1877 * @param state The keyboard state.
1878 * @param key The keycode of the key.
1879 * @param idx The index of the modifier to check.
1880 * @param mode The consumed modifiers mode to use; see enum description.
1882 * @returns 1 if the modifier is consumed, 0 if it is not. If the modifier
1883 * index is not valid in the keymap, returns -1.
1885 * @sa xkb_state_mod_mask_remove_consumed()
1886 * @sa xkb_state_key_get_consumed_mods()
1887 * @memberof xkb_state
1891 xkb_state_mod_index_is_consumed2(struct xkb_state *state,
1893 xkb_mod_index_t idx,
1894 enum xkb_consumed_mode mode);
1897 * Same as xkb_state_mod_index_is_consumed2() with mode XKB_CONSUMED_MOD_XKB.
1899 * @memberof xkb_state
1903 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
1904 xkb_mod_index_t idx);
1907 * Remove consumed modifiers from a modifier mask for a key.
1909 * @deprecated Use xkb_state_key_get_consumed_mods2() instead.
1911 * Takes the given modifier mask, and removes all modifiers which are
1912 * consumed for that particular key (as in xkb_state_mod_index_is_consumed()).
1914 * @sa xkb_state_mod_index_is_consumed()
1915 * @memberof xkb_state
1918 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
1919 xkb_mod_mask_t mask);
1922 * Test whether a layout is active in a given keyboard state by name.
1924 * @returns 1 if the layout is active, 0 if it is not. If no layout with
1925 * this name exists in the keymap, return -1.
1927 * If multiple layouts in the keymap have this name, the one with the lowest
1930 * @sa xkb_layout_index_t
1931 * @memberof xkb_state
1934 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
1935 enum xkb_state_component type);
1938 * Test whether a layout is active in a given keyboard state by index.
1940 * @returns 1 if the layout is active, 0 if it is not. If the layout index
1941 * is not valid in the keymap, returns -1.
1943 * @sa xkb_layout_index_t
1944 * @memberof xkb_state
1947 xkb_state_layout_index_is_active(struct xkb_state *state,
1948 xkb_layout_index_t idx,
1949 enum xkb_state_component type);
1952 * Test whether a LED is active in a given keyboard state by name.
1954 * @returns 1 if the LED is active, 0 if it not. If no LED with this name
1955 * exists in the keymap, returns -1.
1957 * @sa xkb_led_index_t
1958 * @memberof xkb_state
1961 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
1964 * Test whether a LED is active in a given keyboard state by index.
1966 * @returns 1 if the LED is active, 0 if it not. If the LED index is not
1967 * valid in the keymap, returns -1.
1969 * @sa xkb_led_index_t
1970 * @memberof xkb_state
1973 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
1977 /* Leave this include last, so it can pick up our types, etc. */
1978 #include <xkbcommon/xkbcommon-compat.h>
1984 #endif /* _XKBCOMMON_H_ */