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 * http://www.x.org/releases/X11R7.7/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 * Layouts are also called "groups" by XKB.
213 * @sa xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()
215 typedef uint32_t xkb_layout_index_t;
216 /** A mask of layout indices. */
217 typedef uint32_t xkb_layout_mask_t;
220 * Index of a shift level.
222 * Any key, in any layout, can have several <em>shift levels</em>. Each
223 * shift level can assign different keysyms to the key. The shift level
224 * to use is chosen according to the current keyboard state; for example,
225 * if no keys are pressed, the first level may be used; if the Left Shift
226 * key is pressed, the second; if Num Lock is pressed, the third; and
227 * many such combinations are possible (see xkb_mod_index_t).
229 * Level indices are consecutive. The first level has index 0.
231 typedef uint32_t xkb_level_index_t;
234 * Index of a modifier.
236 * A @e modifier is a state component which changes the way keys are
237 * interpreted. A keymap defines a set of modifiers, such as Alt, Shift,
238 * Num Lock or Meta, and specifies which keys may @e activate which
239 * modifiers (in a many-to-many relationship, i.e. a key can activate
240 * several modifiers, and a modifier may be activated by several keys.
241 * Different keymaps do this differently).
243 * When retrieving the keysyms for a key, the active modifier set is
244 * consulted; this detemines the correct shift level to use within the
245 * currently active layout (see xkb_level_index_t).
247 * Modifier indices are consecutive. The first modifier has index 0.
249 * Each modifier must have a name, and the names are unique. Therefore, it
250 * is safe to use the name as a unique identifier for a modifier. The names
251 * of some common modifiers are provided in the xkbcommon/xkbcommon-names.h
252 * header file. Modifier names are case-sensitive.
254 * @sa xkb_keymap_num_mods()
256 typedef uint32_t xkb_mod_index_t;
257 /** A mask of modifier indices. */
258 typedef uint32_t xkb_mod_mask_t;
261 * Index of a keyboard LED.
263 * LEDs are logical objects which may be @e active or @e inactive. They
264 * typically correspond to the lights on the keyboard. Their state is
265 * determined by the current keyboard state.
267 * LED indices are non-consecutive. The first LED has index 0.
269 * Each LED must have a name, and the names are unique. Therefore,
270 * it is safe to use the name as a unique identifier for a LED. The names
271 * of some common LEDs are provided in the xkbcommon/xkbcommon-names.h
272 * header file. LED names are case-sensitive.
274 * @warning A given keymap may specify an exact index for a given LED.
275 * Therefore, LED indexing is not necessarily sequential, as opposed to
276 * modifiers and layouts. This means that when iterating over the LEDs
277 * in a keymap using e.g. xkb_keymap_num_leds(), some indices might be
278 * invalid. Given such an index, functions like xkb_keymap_led_get_name()
279 * will return NULL, and xkb_state_led_index_is_active() will return -1.
281 * LEDs are also called "indicators" by XKB.
283 * @sa xkb_keymap_num_leds()
285 typedef uint32_t xkb_led_index_t;
286 /** A mask of LED indices. */
287 typedef uint32_t xkb_led_mask_t;
289 #define XKB_KEYCODE_INVALID (0xffffffff)
290 #define XKB_LAYOUT_INVALID (0xffffffff)
291 #define XKB_LEVEL_INVALID (0xffffffff)
292 #define XKB_MOD_INVALID (0xffffffff)
293 #define XKB_LED_INVALID (0xffffffff)
295 #define XKB_KEYCODE_MAX (0xffffffff - 1)
298 * Test whether a value is a valid extended keycode.
301 #define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)
304 * Test whether a value is a valid X11 keycode.
307 #define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)
310 * Names to compile a keymap with, also known as RMLVO.
312 * The names are the common configuration values by which a user picks
315 * If the entire struct is NULL, then each field is taken to be NULL.
316 * You should prefer passing NULL instead of choosing your own defaults.
318 struct xkb_rule_names {
320 * The rules file to use. The rules file describes how to interpret
321 * the values of the model, layout, variant and options fields.
323 * If NULL or the empty string "", a default value is used.
324 * If the XKB_DEFAULT_RULES environment variable is set, it is used
325 * as the default. Otherwise the system default is used.
329 * The keyboard model by which to interpret keycodes and LEDs.
331 * If NULL or the empty string "", a default value is used.
332 * If the XKB_DEFAULT_MODEL environment variable is set, it is used
333 * as the default. Otherwise the system default is used.
337 * A comma separated list of layouts (languages) to include in the
340 * If NULL or the empty string "", a default value is used.
341 * If the XKB_DEFAULT_LAYOUT environment variable is set, it is used
342 * as the default. Otherwise the system default is used.
346 * A comma separated list of variants, one per layout, which may
347 * modify or augment the respective layout in various ways.
349 * If NULL or the empty string "", and a default value is also used
350 * for the layout, a default value is used. Otherwise no variant is
352 * If the XKB_DEFAULT_VARIANT environment variable is set, it is used
353 * as the default. Otherwise the system default is used.
357 * A comma separated list of options, through which the user specifies
358 * non-layout related preferences, like which key combinations are used
359 * for switching layouts, or which key is the Compose key.
361 * If NULL, a default value is used. If the empty string "", no
363 * If the XKB_DEFAULT_OPTIONS environment variable is set, it is used
364 * as the default. Otherwise the system default is used.
370 * @defgroup keysyms Keysyms
371 * Utility functions related to keysyms.
377 * @page keysym-transformations Keysym Transformations
379 * Keysym translation is subject to several "keysym transformations",
380 * as described in the XKB specification. These are:
382 * - Capitalization transformation. If the Caps Lock modifier is
383 * active and was not consumed by the translation process, a single
384 * keysym is transformed to its upper-case form (if applicable).
385 * Similarly, the UTF-8/UTF-32 string produced is capitalized.
387 * This is described in:
388 * http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier
390 * - Control transformation. If the Control modifier is active and
391 * was not consumed by the translation process, the string produced
392 * is transformed to its matching ASCII control character (if
393 * applicable). Keysyms are not affected.
395 * This is described in:
396 * http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
398 * Each relevant function discusses which transformations it performs.
400 * These transformations are not applicable when a key produces multiple
406 * Get the name of a keysym.
408 * For a description of how keysyms are named, see @ref xkb_keysym_t.
410 * @param[in] keysym The keysym.
411 * @param[out] buffer A string buffer to write the name into.
412 * @param[in] size Size of the buffer.
414 * @warning If the buffer passed is too small, the string is truncated
415 * (though still NUL-terminated); a size of at least 64 bytes is recommended.
417 * @returns The number of bytes in the name, excluding the NUL byte. If
418 * the keysym is invalid, returns -1.
420 * You may check if truncation has occurred by comparing the return value
421 * with the length of buffer, similarly to the snprintf(3) function.
426 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
428 /** Flags for xkb_keysym_from_name(). */
429 enum xkb_keysym_flags {
430 /** Do not apply any flags. */
431 XKB_KEYSYM_NO_FLAGS = 0,
432 /** Find keysym by case-insensitive search. */
433 XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
437 * Get a keysym from its name.
439 * @param name The name of a keysym. See remarks in xkb_keysym_get_name();
440 * this function will accept any name returned by that function.
441 * @param flags A set of flags controlling how the search is done. If
442 * invalid flags are passed, this will fail with XKB_KEY_NoSymbol.
444 * If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names
445 * differ only by case, then the lower-case keysym is returned. For
446 * instance, for KEY_a and KEY_A, this function would return KEY_a for the
447 * case-insensitive search. If this functionality is needed, it is
448 * recommended to first call this function without this flag; and if that
449 * fails, only then to try with this flag, while possibly warning the user
450 * he had misspelled the name, and might get wrong results.
452 * @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.
457 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
460 * Get the Unicode/UTF-8 representation of a keysym.
462 * @param[in] keysym The keysym.
463 * @param[out] buffer A buffer to write the UTF-8 string into.
464 * @param[in] size The size of buffer. Must be at least 7.
466 * @returns The number of bytes written to the buffer (including the
467 * terminating byte). If the keysym does not have a Unicode
468 * representation, returns 0. If the buffer is too small, returns -1.
470 * This function does not perform any @ref keysym-transformations.
471 * Therefore, prefer to use xkb_state_key_get_utf8() if possible.
473 * @sa xkb_state_key_get_utf8()
476 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
479 * Get the Unicode/UTF-32 representation of a keysym.
481 * @returns The Unicode/UTF-32 representation of keysym, which is also
482 * compatible with UCS-4. If the keysym does not have a Unicode
483 * representation, returns 0.
485 * This function does not perform any @ref keysym-transformations.
486 * Therefore, prefer to use xkb_state_key_get_utf32() if possible.
488 * @sa xkb_state_key_get_utf32()
491 xkb_keysym_to_utf32(xkb_keysym_t keysym);
496 * @defgroup context Library Context
497 * Creating, destroying and using library contexts.
499 * Every keymap compilation request must have a context associated with
500 * it. The context keeps around state such as the include path.
505 /** Flags for context creation. */
506 enum xkb_context_flags {
507 /** Do not apply any context flags. */
508 XKB_CONTEXT_NO_FLAGS = 0,
509 /** Create this context with an empty include path. */
510 XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
512 * Don't take RMLVO names from the environment.
515 XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1)
519 * Create a new context.
521 * @param flags Optional flags for the context, or 0.
523 * @returns A new context, or NULL on failure.
525 * The user may set some environment variables to affect default values in
526 * the context. See e.g. xkb_context_set_log_level() and
527 * xkb_context_set_log_verbosity().
529 * @memberof xkb_context
532 xkb_context_new(enum xkb_context_flags flags);
535 * Take a new reference on a context.
537 * @returns The passed in context.
539 * @memberof xkb_context
542 xkb_context_ref(struct xkb_context *context);
545 * Release a reference on a context, and possibly free it.
547 * @param context The context. If it is NULL, this function does nothing.
549 * @memberof xkb_context
552 xkb_context_unref(struct xkb_context *context);
555 * Store custom user data in the context.
557 * This may be useful in conjunction with xkb_context_set_log_fn() or other
560 * @memberof xkb_context
563 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
566 * Retrieves stored user data from the context.
568 * @returns The stored user data. If the user data wasn't set, or the
569 * passed in context is NULL, returns NULL.
571 * This may be useful to access private user data from callbacks like a
572 * custom logging function.
574 * @memberof xkb_context
577 xkb_context_get_user_data(struct xkb_context *context);
582 * @defgroup include-path Include Paths
583 * Manipulating the include paths in a context.
585 * The include paths are the file-system paths that are searched when an
586 * include statement is encountered during keymap compilation.
587 * In most cases, the default include paths are sufficient.
593 * Append a new entry to the context's include path.
595 * @returns 1 on success, or 0 if the include path could not be added or is
598 * @memberof xkb_context
601 xkb_context_include_path_append(struct xkb_context *context, const char *path);
604 * Append the default include paths to the context's include path.
606 * @returns 1 on success, or 0 if the primary include path could not be added.
608 * @memberof xkb_context
611 xkb_context_include_path_append_default(struct xkb_context *context);
614 * Reset the context's include path to the default.
616 * Removes all entries from the context's include path, and inserts the
619 * @returns 1 on success, or 0 if the primary include path could not be added.
621 * @memberof xkb_context
624 xkb_context_include_path_reset_defaults(struct xkb_context *context);
627 * Remove all entries from the context's include path.
629 * @memberof xkb_context
632 xkb_context_include_path_clear(struct xkb_context *context);
635 * Get the number of paths in the context's include path.
637 * @memberof xkb_context
640 xkb_context_num_include_paths(struct xkb_context *context);
643 * Get a specific include path from the context's include path.
645 * @returns The include path at the specified index. If the index is
646 * invalid, returns NULL.
648 * @memberof xkb_context
651 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
656 * @defgroup logging Logging Handling
657 * Manipulating how logging from this library is handled.
662 /** Specifies a logging level. */
664 XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
665 XKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */
666 XKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */
667 XKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */
668 XKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */
672 * Set the current logging level.
674 * @param context The context in which to set the logging level.
675 * @param level The logging level to use. Only messages from this level
676 * and below will be logged.
678 * The default level is XKB_LOG_LEVEL_ERROR. The environment variable
679 * XKB_LOG_LEVEL, if set in the time the context was created, overrides the
680 * default value. It may be specified as a level number or name.
682 * @memberof xkb_context
685 xkb_context_set_log_level(struct xkb_context *context,
686 enum xkb_log_level level);
689 * Get the current logging level.
691 * @memberof xkb_context
694 xkb_context_get_log_level(struct xkb_context *context);
697 * Sets the current logging verbosity.
699 * The library can generate a number of warnings which are not helpful to
700 * ordinary users of the library. The verbosity may be increased if more
701 * information is desired (e.g. when developing a new keymap).
703 * The default verbosity is 0. The environment variable XKB_LOG_VERBOSITY,
704 * if set in the time the context was created, overrides the default value.
706 * @param context The context in which to use the set verbosity.
707 * @param verbosity The verbosity to use. Currently used values are
708 * 1 to 10, higher values being more verbose. 0 would result in no verbose
709 * messages being logged.
711 * Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
713 * @memberof xkb_context
716 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
719 * Get the current logging verbosity of the context.
721 * @memberof xkb_context
724 xkb_context_get_log_verbosity(struct xkb_context *context);
727 * Set a custom function to handle logging messages.
729 * @param context The context in which to use the set logging function.
730 * @param log_fn The function that will be called for logging messages.
731 * Passing NULL restores the default function, which logs to stderr.
733 * By default, log messages from this library are printed to stderr. This
734 * function allows you to replace the default behavior with a custom
735 * handler. The handler is only called with messages which match the
736 * current logging level and verbosity settings for the context.
737 * level is the logging level of the message. @a format and @a args are
738 * the same as in the vprintf(3) function.
740 * You may use xkb_context_set_user_data() on the context, and then call
741 * xkb_context_get_user_data() from within the logging function to provide
742 * it with additional private context.
744 * @memberof xkb_context
747 xkb_context_set_log_fn(struct xkb_context *context,
748 void (*log_fn)(struct xkb_context *context,
749 enum xkb_log_level level,
750 const char *format, va_list args));
755 * @defgroup keymap Keymap Creation
756 * Creating and destroying keymaps.
761 /** Flags for keymap compilation. */
762 enum xkb_keymap_compile_flags {
763 /** Do not apply any flags. */
764 XKB_KEYMAP_COMPILE_NO_FLAGS = 0
768 * Create a keymap from RMLVO names.
770 * The primary keymap entry point: creates a new XKB keymap from a set of
771 * RMLVO (Rules + Model + Layouts + Variants + Options) names.
773 * @param context The context in which to create the keymap.
774 * @param names The RMLVO names to use. See xkb_rule_names.
775 * @param flags Optional flags for the keymap, or 0.
777 * @returns A keymap compiled according to the RMLVO names, or NULL if
778 * the compilation failed.
781 * @memberof xkb_keymap
784 xkb_keymap_new_from_names(struct xkb_context *context,
785 const struct xkb_rule_names *names,
786 enum xkb_keymap_compile_flags flags);
788 /** The possible keymap formats. */
789 enum xkb_keymap_format {
790 /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
791 XKB_KEYMAP_FORMAT_TEXT_V1 = 1
795 * Create a keymap from a keymap file.
797 * @param context The context in which to create the keymap.
798 * @param file The keymap file to compile.
799 * @param format The text format of the keymap file to compile.
800 * @param flags Optional flags for the keymap, or 0.
802 * @returns A keymap compiled from the given XKB keymap file, or NULL if
803 * the compilation failed.
805 * The file must contain a complete keymap. For example, in the
806 * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
807 * top level '%xkb_keymap' section, which in turn contains other required
810 * @memberof xkb_keymap
813 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
814 enum xkb_keymap_format format,
815 enum xkb_keymap_compile_flags flags);
818 * Create a keymap from a keymap string.
820 * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
821 * the keymap as one enormous string.
823 * @see xkb_keymap_new_from_file()
824 * @memberof xkb_keymap
827 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
828 enum xkb_keymap_format format,
829 enum xkb_keymap_compile_flags flags);
832 * Create a keymap from a memory buffer.
834 * This is just like xkb_keymap_new_from_string(), but takes a length argument
835 * so the input string does not have to be zero-terminated.
837 * @see xkb_keymap_new_from_string()
838 * @memberof xkb_keymap
842 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
843 size_t length, enum xkb_keymap_format format,
844 enum xkb_keymap_compile_flags flags);
847 * Take a new reference on a keymap.
849 * @returns The passed in keymap.
851 * @memberof xkb_keymap
854 xkb_keymap_ref(struct xkb_keymap *keymap);
857 * Release a reference on a keymap, and possibly free it.
859 * @param keymap The keymap. If it is NULL, this function does nothing.
861 * @memberof xkb_keymap
864 xkb_keymap_unref(struct xkb_keymap *keymap);
867 * Get the keymap as a string in the format from which it was created.
868 * @sa xkb_keymap_get_as_string()
870 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
873 * Get the compiled keymap as a string.
875 * @param keymap The keymap to get as a string.
876 * @param format The keymap format to use for the string. You can pass
877 * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
878 * from which the keymap was originally created.
880 * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
882 * The returned string may be fed back into xkb_map_new_from_string() to get
883 * the exact same keymap (possibly in another process, etc.).
885 * The returned string is dynamically allocated and should be freed by the
888 * @memberof xkb_keymap
891 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
892 enum xkb_keymap_format format);
897 * @defgroup components Keymap Components
898 * Enumeration of state components in a keymap.
904 * Get the minimum keycode in the keymap.
907 * @memberof xkb_keymap
911 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
914 * Get the maximum keycode in the keymap.
917 * @memberof xkb_keymap
921 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
924 * The iterator used by xkb_keymap_key_for_each().
926 * @sa xkb_keymap_key_for_each
927 * @memberof xkb_keymap
931 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
935 * Run a specified function for every valid keycode in the keymap. If a
936 * keymap is sparse, this function may be called fewer than
937 * (max_keycode - min_keycode + 1) times.
939 * @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t
940 * @memberof xkb_keymap
944 xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
948 * Find the name of the key with the given keycode.
950 * This function always returns the canonical name of the key (see
951 * description in xkb_keycode_t).
953 * @returns The key name. If no key with this keycode exists,
957 * @memberof xkb_keymap
961 xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);
964 * Find the keycode of the key with the given name.
966 * The name can be either a canonical name or an alias.
968 * @returns The keycode. If no key with this name exists,
969 * returns XKB_KEYCODE_INVALID.
972 * @memberof xkb_keymap
976 xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);
979 * Get the number of modifiers in the keymap.
981 * @sa xkb_mod_index_t
982 * @memberof xkb_keymap
985 xkb_keymap_num_mods(struct xkb_keymap *keymap);
988 * Get the name of a modifier by index.
990 * @returns The name. If the index is invalid, returns NULL.
992 * @sa xkb_mod_index_t
993 * @memberof xkb_keymap
996 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
999 * Get the index of a modifier by name.
1001 * @returns The index. If no modifier with this name exists, returns
1004 * @sa xkb_mod_index_t
1005 * @memberof xkb_keymap
1008 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
1011 * Get the number of layouts in the keymap.
1013 * @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()
1014 * @memberof xkb_keymap
1017 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
1020 * Get the name of a layout by index.
1022 * @returns The name. If the index is invalid, or the layout does not have
1023 * a name, returns NULL.
1025 * @sa xkb_layout_index_t
1026 * @memberof xkb_keymap
1029 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
1032 * Get the index of a layout by name.
1034 * @returns The index. If no layout exists with this name, returns
1035 * XKB_LAYOUT_INVALID. If more than one layout in the keymap has this name,
1036 * returns the lowest index among them.
1038 * @memberof xkb_keymap
1041 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
1044 * Get the number of LEDs in the keymap.
1046 * @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs
1047 * in the keymap, but may also contain inactive LEDs. When iterating over
1048 * this range, you need the handle this case when calling functions such as
1049 * xkb_keymap_led_get_name() or xkb_state_led_index_is_active().
1051 * @sa xkb_led_index_t
1052 * @memberof xkb_keymap
1055 xkb_keymap_num_leds(struct xkb_keymap *keymap);
1058 * Get the name of a LED by index.
1060 * @returns The name. If the index is invalid, returns NULL.
1062 * @memberof xkb_keymap
1065 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1068 * Get the index of a LED by name.
1070 * @returns The index. If no LED with this name exists, returns
1073 * @memberof xkb_keymap
1076 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1079 * Get the number of layouts for a specific key.
1081 * This number can be different from xkb_keymap_num_layouts(), but is always
1082 * smaller. It is the appropriate value to use when iterating over the
1085 * @sa xkb_layout_index_t
1086 * @memberof xkb_keymap
1089 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
1092 * Get the number of shift levels for a specific key and layout.
1094 * If @c layout is out of range for this key (that is, larger or equal to
1095 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1096 * back into range in a manner consistent with xkb_state_key_get_layout().
1098 * @sa xkb_level_index_t
1099 * @memberof xkb_keymap
1102 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
1103 xkb_layout_index_t layout);
1106 * Get the keysyms obtained from pressing a key in a given layout and
1109 * This function is like xkb_state_key_get_syms(), only the layout and
1110 * shift level are not derived from the keyboard state but are instead
1111 * specified explicitly.
1113 * @param[in] keymap The keymap.
1114 * @param[in] key The keycode of the key.
1115 * @param[in] layout The layout for which to get the keysyms.
1116 * @param[in] level The shift level in the layout for which to get the
1117 * keysyms. This must be smaller than:
1118 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1119 * @param[out] syms_out An immutable array of keysyms corresponding to the
1120 * key in the given layout and shift level.
1122 * If @c layout is out of range for this key (that is, larger or equal to
1123 * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1124 * back into range in a manner consistent with xkb_state_key_get_layout().
1126 * @returns The number of keysyms in the syms_out array. If no keysyms
1127 * are produced by the key in the given layout and shift level, returns 0
1128 * and sets syms_out to NULL.
1130 * @sa xkb_state_key_get_syms()
1131 * @memberof xkb_keymap
1134 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
1136 xkb_layout_index_t layout,
1137 xkb_level_index_t level,
1138 const xkb_keysym_t **syms_out);
1141 * Determine whether a key should repeat or not.
1143 * A keymap may specify different repeat behaviors for different keys.
1144 * Most keys should generally exhibit repeat behavior; for example, holding
1145 * the 'a' key down in a text editor should normally insert a single 'a'
1146 * character every few milliseconds, until the key is released. However,
1147 * there are keys which should not or do not need to be repeated. For
1148 * example, repeating modifier keys such as Left/Right Shift or Caps Lock
1149 * is not generally useful or desired.
1151 * @returns 1 if the key should repeat, 0 otherwise.
1153 * @memberof xkb_keymap
1156 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1161 * @defgroup state Keyboard State
1162 * Creating, destroying and manipulating keyboard state objects.
1168 * Create a new keyboard state object.
1170 * @param keymap The keymap which the state will use.
1172 * @returns A new keyboard state object, or NULL on failure.
1174 * @memberof xkb_state
1177 xkb_state_new(struct xkb_keymap *keymap);
1180 * Take a new reference on a keyboard state object.
1182 * @returns The passed in object.
1184 * @memberof xkb_state
1187 xkb_state_ref(struct xkb_state *state);
1190 * Release a reference on a keybaord state object, and possibly free it.
1192 * @param state The state. If it is NULL, this function does nothing.
1194 * @memberof xkb_state
1197 xkb_state_unref(struct xkb_state *state);
1200 * Get the keymap which a keyboard state object is using.
1202 * @returns The keymap which was passed to xkb_state_new() when creating
1203 * this state object.
1205 * This function does not take a new reference on the keymap; you must
1206 * explicitly reference it yourself if you plan to use it beyond the
1207 * lifetime of the state.
1209 * @memberof xkb_state
1212 xkb_state_get_keymap(struct xkb_state *state);
1214 /** Specifies the direction of the key (press / release). */
1215 enum xkb_key_direction {
1216 XKB_KEY_UP, /**< The key was released. */
1217 XKB_KEY_DOWN /**< The key was pressed. */
1221 * Modifier and layout types for state objects. This enum is bitmaskable,
1222 * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
1223 * exclude locked modifiers.
1225 * In XKB, the DEPRESSED components are also known as 'base'.
1227 enum xkb_state_component {
1228 /** Depressed modifiers, i.e. a key is physically holding them. */
1229 XKB_STATE_MODS_DEPRESSED = (1 << 0),
1230 /** Latched modifiers, i.e. will be unset after the next non-modifier
1232 XKB_STATE_MODS_LATCHED = (1 << 1),
1233 /** Locked modifiers, i.e. will be unset after the key provoking the
1234 * lock has been pressed again. */
1235 XKB_STATE_MODS_LOCKED = (1 << 2),
1236 /** Effective modifiers, i.e. currently active and affect key
1237 * processing (derived from the other state components).
1238 * Use this unless you explictly care how the state came about. */
1239 XKB_STATE_MODS_EFFECTIVE = (1 << 3),
1240 /** Depressed layout, i.e. a key is physically holding it. */
1241 XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
1242 /** Latched layout, i.e. will be unset after the next non-modifier
1244 XKB_STATE_LAYOUT_LATCHED = (1 << 5),
1245 /** Locked layout, i.e. will be unset after the key provoking the lock
1246 * has been pressed again. */
1247 XKB_STATE_LAYOUT_LOCKED = (1 << 6),
1248 /** Effective layout, i.e. currently active and affects key processing
1249 * (derived from the other state components).
1250 * Use this unless you explictly care how the state came about. */
1251 XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
1252 /** LEDs (derived from the other state components). */
1253 XKB_STATE_LEDS = (1 << 8)
1257 * Update the keyboard state to reflect a given key being pressed or
1260 * This entry point is intended for programs which track the keyboard state
1261 * explictly (like an evdev client). If the state is serialized to you by
1262 * a master process (like a Wayland compositor) using functions like
1263 * xkb_state_serialize_mods(), you should use xkb_state_update_mask() instead.
1264 * The two functins should not generally be used together.
1266 * A series of calls to this function should be consistent; that is, a call
1267 * with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key
1268 * is pressed twice, it should be released twice; etc. Otherwise (e.g. due
1269 * to missed input events), situations like "stuck modifiers" may occur.
1271 * This function is often used in conjunction with the function
1272 * xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,
1273 * when handling a key event. In this case, you should prefer to get the
1274 * keysyms *before* updating the key, such that the keysyms reported for
1275 * the key event are not affected by the event itself. This is the
1276 * conventional behavior.
1278 * @returns A mask of state components that have changed as a result of
1279 * the update. If nothing in the state has changed, returns 0.
1281 * @memberof xkb_state
1283 * @sa xkb_state_update_mask()
1285 enum xkb_state_component
1286 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1287 enum xkb_key_direction direction);
1290 * Update a keyboard state from a set of explicit masks.
1292 * This entry point is intended for window systems and the like, where a
1293 * master process holds an xkb_state, then serializes it over a wire
1294 * protocol, and clients then use the serialization to feed in to their own
1297 * All parameters must always be passed, or the resulting state may be
1300 * The serialization is lossy and will not survive round trips; it must only
1301 * be used to feed slave state objects, and must not be used to update the
1304 * If you do not fit the description above, you should use
1305 * xkb_state_update_key() instead. The two functions should not generally be
1308 * @returns A mask of state components that have changed as a result of
1309 * the update. If nothing in the state has changed, returns 0.
1311 * @memberof xkb_state
1313 * @sa xkb_state_component
1314 * @sa xkb_state_update_key
1316 enum xkb_state_component
1317 xkb_state_update_mask(struct xkb_state *state,
1318 xkb_mod_mask_t depressed_mods,
1319 xkb_mod_mask_t latched_mods,
1320 xkb_mod_mask_t locked_mods,
1321 xkb_layout_index_t depressed_layout,
1322 xkb_layout_index_t latched_layout,
1323 xkb_layout_index_t locked_layout);
1326 * Get the keysyms obtained from pressing a particular key in a given
1329 * Get the keysyms for a key according to the current active layout,
1330 * modifiers and shift level for the key, as determined by a keyboard
1333 * @param[in] state The keyboard state object.
1334 * @param[in] key The keycode of the key.
1335 * @param[out] syms_out An immutable array of keysyms corresponding the
1336 * key in the given keyboard state.
1338 * As an extension to XKB, this function can return more than one keysym.
1339 * If you do not want to handle this case, you can use
1340 * xkb_state_key_get_one_sym() for a simpler interface.
1342 * This function does not perform any @ref keysym-transformations.
1343 * (This might change).
1345 * @returns The number of keysyms in the syms_out array. If no keysyms
1346 * are produced by the key in the given keyboard state, returns 0 and sets
1349 * @memberof xkb_state
1352 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
1353 const xkb_keysym_t **syms_out);
1356 * Get the Unicode/UTF-8 string obtained from pressing a particular key
1357 * in a given keyboard state.
1359 * @param[in] state The keyboard state object.
1360 * @param[in] key The keycode of the key.
1361 * @param[out] buffer A buffer to write the string into.
1362 * @param[in] size Size of the buffer.
1364 * @warning If the buffer passed is too small, the string is truncated
1365 * (though still NUL-terminated).
1367 * @returns The number of bytes required for the string, excluding the
1368 * NUL byte. If there is nothing to write, returns 0.
1370 * You may check if truncation has occurred by comparing the return value
1371 * with the size of @p buffer, similarly to the snprintf(3) function.
1372 * You may safely pass NULL and 0 to @p buffer and @p size to find the
1373 * required size (without the NUL-byte).
1375 * This function performs Capitalization and Control @ref
1376 * keysym-transformations.
1378 * @memberof xkb_state
1382 xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,
1383 char *buffer, size_t size);
1386 * Get the Unicode/UTF-32 codepoint obtained from pressing a particular
1387 * key in a a given keyboard state.
1389 * @returns The UTF-32 representation for the key, if it consists of only
1390 * a single codepoint. Otherwise, returns 0.
1392 * This function performs Capitalization and Control @ref
1393 * keysym-transformations.
1395 * @memberof xkb_state
1399 xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);
1402 * Get the single keysym obtained from pressing a particular key in a
1403 * given keyboard state.
1405 * This function is similar to xkb_state_key_get_syms(), but intended
1406 * for users which cannot or do not want to handle the case where
1407 * multiple keysyms are returned (in which case this function is
1410 * @returns The keysym. If the key does not have exactly one keysym,
1411 * returns XKB_KEY_NoSymbol
1413 * This function performs Capitalization @ref keysym-transformations.
1415 * @sa xkb_state_key_get_syms()
1416 * @memberof xkb_state
1419 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
1422 * Get the effective layout index for a key in a given keyboard state.
1424 * @returns The layout index for the key in the given keyboard state. If
1425 * the given keycode is invalid, or if the key is not included in any
1426 * layout at all, returns XKB_LAYOUT_INVALID.
1428 * @invariant If the returned layout is valid, the following always holds:
1430 * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
1433 * @memberof xkb_state
1436 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
1439 * Get the effective shift level for a key in a given keyboard state and
1442 * @param state The keyboard state.
1443 * @param key The keycode of the key.
1444 * @param layout The layout for which to get the shift level. This must be
1446 * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
1447 * usually it would be:
1448 * @code xkb_state_key_get_layout(state, key) @endcode
1450 * @return The shift level index. If the key or layout are invalid,
1451 * returns XKB_LEVEL_INVALID.
1453 * @invariant If the returned level is valid, the following always holds:
1455 * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
1458 * @memberof xkb_state
1461 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
1462 xkb_layout_index_t layout);
1465 * Match flags for xkb_state_mod_indices_are_active() and
1466 * xkb_state_mod_names_are_active(), specifying the conditions for a
1467 * successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
1470 enum xkb_state_match {
1471 /** Returns true if any of the modifiers are active. */
1472 XKB_STATE_MATCH_ANY = (1 << 0),
1473 /** Returns true if all of the modifiers are active. */
1474 XKB_STATE_MATCH_ALL = (1 << 1),
1475 /** Makes matching non-exclusive, i.e. will not return false if a
1476 * modifier not specified in the arguments is active. */
1477 XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
1481 * The counterpart to xkb_state_update_mask for modifiers, to be used on
1482 * the server side of serialization.
1484 * @param state The keyboard state.
1485 * @param components A mask of the modifier state components to serialize.
1486 * State components other than XKB_STATE_MODS_* are ignored.
1487 * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
1490 * @returns A xkb_mod_mask_t representing the given components of the
1493 * This function should not be used in regular clients; please use the
1494 * xkb_state_mod_*_is_active API instead.
1496 * @memberof xkb_state
1499 xkb_state_serialize_mods(struct xkb_state *state,
1500 enum xkb_state_component components);
1503 * The counterpart to xkb_state_update_mask for layouts, to be used on
1504 * the server side of serialization.
1506 * @param state The keyboard state.
1507 * @param components A mask of the layout state components to serialize.
1508 * State components other than XKB_STATE_LAYOUT_* are ignored.
1509 * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
1512 * @returns A layout index representing the given components of the
1515 * This function should not be used in regular clients; please use the
1516 * xkb_state_layout_*_is_active API instead.
1518 * @memberof xkb_state
1521 xkb_state_serialize_layout(struct xkb_state *state,
1522 enum xkb_state_component components);
1525 * Test whether a modifier is active in a given keyboard state by name.
1527 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
1528 * name does not exist in the keymap, returns -1.
1530 * @memberof xkb_state
1533 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
1534 enum xkb_state_component type);
1537 * Test whether a set of modifiers are active in a given keyboard state by
1540 * @param state The keyboard state.
1541 * @param type The component of the state against which to match the
1543 * @param match The manner by which to match the state against the
1545 * @param ... The set of of modifier names to test, terminated by a NULL
1546 * argument (sentinel).
1548 * @returns 1 if the modifiers are active, 0 if they are not. If any of
1549 * the modifier names do not exist in the keymap, returns -1.
1551 * @memberof xkb_state
1554 xkb_state_mod_names_are_active(struct xkb_state *state,
1555 enum xkb_state_component type,
1556 enum xkb_state_match match,
1560 * Test whether a modifier is active in a given keyboard state by index.
1562 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
1563 * index is invalid in the keymap, returns -1.
1565 * @memberof xkb_state
1568 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
1569 enum xkb_state_component type);
1572 * Test whether a set of modifiers are active in a given keyboard state by
1575 * @param state The keyboard state.
1576 * @param type The component of the state against which to match the
1578 * @param match The manner by which to match the state against the
1580 * @param ... The set of of modifier indices to test, terminated by a
1581 * XKB_MOD_INVALID argument (sentinel).
1583 * @returns 1 if the modifiers are active, 0 if they are not. If any of
1584 * the modifier indices are invalid in the keymap, returns -1.
1586 * @memberof xkb_state
1589 xkb_state_mod_indices_are_active(struct xkb_state *state,
1590 enum xkb_state_component type,
1591 enum xkb_state_match match,
1595 * @page consumed-modifiers Consumed Modifiers
1598 * Some functions, like xkb_state_key_get_syms(), look at the state of
1599 * the modifiers in the keymap and derive from it the correct shift level
1600 * to use for the key. For example, in a US layout, pressing the key
1601 * labeled \<A\> while the Shift modifier is active, generates the keysym
1602 * 'A'. In this case, the Shift modifier is said to be "consumed".
1603 * However, the Num Lock modifier does not affect this translation at all,
1604 * even if it is active, so it is not consumed by this translation.
1606 * It may be desirable for some application to not reuse consumed modifiers
1607 * for further processing, e.g. for hotkeys or keyboard shortcuts. To
1608 * understand why, consider some requirements from a standard shortcut
1609 * mechanism, and how they are implemented:
1611 * 1. The shortcut's modifiers must match exactly to the state. For
1612 * example, it is possible to bind separate actions to \<Alt\>\<Tab\>
1613 * and to \<Alt\>\<Shift\>\<Tab\>. Further, if only \<Alt\>\<Tab\> is
1614 * bound to an action, pressing \<Alt\>\<Shift\>\<Tab\> should not
1615 * trigger the shortcut.
1616 * Effectively, this means that the modifiers are compared using the
1617 * equality operator (==).
1619 * 2. Only relevant modifiers are considered for the matching. For example,
1620 * Caps Lock and Num Lock should not generally affect the matching, e.g.
1621 * when matching \<Alt\>\<Tab\> against the state, it does not matter
1622 * whether Num Lock is active or not. These relevant, or "significant",
1623 * modifiers usually include Alt, Control, Shift, Super and similar.
1624 * Effectively, this means that non-significant modifiers are masked out,
1625 * before doing the comparison as described above.
1627 * 3. The matching must be independent of the layout/keymap. For example,
1628 * the \<Plus\> (+) symbol is found on the first level on some layouts,
1629 * but requires holding Shift on others. If you simply bind the action
1630 * to the \<Plus\> keysym, it would work for the unshifted kind, but
1631 * not for the others, because the match against Shift would fail. If
1632 * you bind the action to \<Shift\>\<Plus\>, only the shifted kind would
1633 * work. So what is needed is to recognize that Shift is used up in the
1634 * translation of the keysym itself, and therefore should not be included
1636 * Effectively, this means that consumed modifiers (Shift in this example)
1637 * are masked out as well, before doing the comparison.
1639 * In summary, this is how the matching would be performed:
1641 * (keysym == shortcut_keysym) &&
1642 * ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)
1645 * @c state_mods are the modifiers reported by
1646 * xkb_state_mod_index_is_active() and similar functions.
1647 * @c consumed_mods are the modifiers reported by
1648 * xkb_state_mod_index_is_consumed() and similar functions.
1649 * @c significant_mods are decided upon by the application/toolkit/user;
1650 * it is up to them to decide whether these are configurable or hard-coded.
1656 * Test whether a modifier is consumed by keyboard state translation for
1659 * @returns 1 if the modifier is consumed, 0 if it is not. If the modifier
1660 * index is not valid in the keymap, returns -1.
1662 * @sa xkb_state_mod_mask_remove_consumed()
1663 * @sa xkb_state_key_get_consumed_mods()
1664 * @memberof xkb_state
1667 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
1668 xkb_mod_index_t idx);
1671 * Remove consumed modifiers from a modifier mask for a key.
1673 * Takes the given modifier mask, and removes all modifiers which are
1674 * consumed for that particular key (as in xkb_state_mod_index_is_consumed()).
1676 * @sa xkb_state_mod_index_is_consumed()
1677 * @memberof xkb_state
1680 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
1681 xkb_mod_mask_t mask);
1684 * Get the mask of modifiers consumed by translating a given key.
1686 * @returns a mask of the consumed modifiers.
1688 * @sa xkb_state_mod_index_is_consumed()
1689 * @memberof xkb_state
1693 xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
1696 * Test whether a layout is active in a given keyboard state by name.
1698 * @returns 1 if the layout is active, 0 if it is not. If no layout with
1699 * this name exists in the keymap, return -1.
1701 * If multiple layouts in the keymap have this name, the one with the lowest
1704 * @sa xkb_layout_index_t
1705 * @memberof xkb_state
1708 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
1709 enum xkb_state_component type);
1712 * Test whether a layout is active in a given keyboard state by index.
1714 * @returns 1 if the layout is active, 0 if it is not. If the layout index
1715 * is not valid in the keymap, returns -1.
1717 * @sa xkb_layout_index_t
1718 * @memberof xkb_state
1721 xkb_state_layout_index_is_active(struct xkb_state *state,
1722 xkb_layout_index_t idx,
1723 enum xkb_state_component type);
1726 * Test whether a LED is active in a given keyboard state by name.
1728 * @returns 1 if the LED is active, 0 if it not. If no LED with this name
1729 * exists in the keymap, returns -1.
1731 * @sa xkb_led_index_t
1732 * @memberof xkb_state
1735 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
1738 * Test whether a LED is active in a given keyboard state by index.
1740 * @returns 1 if the LED is active, 0 if it not. If the LED index is not
1741 * valid in the keymap, returns -1.
1743 * @sa xkb_led_index_t
1744 * @memberof xkb_state
1747 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
1751 /* Leave this include last, so it can pick up our types, etc. */
1752 #include <xkbcommon/xkbcommon-compat.h>
1758 #endif /* _XKBCOMMON_H_ */